Kristina has two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ non-negative integers. She can perform the following operation on array $$$a$$$ any number of times:   apply a decrement to each non-zero element of the array, that is, replace the value of each element $$$a_i$$$ such that $$$a_i > 0$$$ with the value $$$a_i - 1$$$ ($$$1 \le i \le n$$$). If $$$a_i$$$ was $$$0$$$, its value does not change. Determine whether Kristina can get an array $$$b$$$ from an array $$$a$$$ in some number of operations (probably zero). In other words, can she make $$$a_i = b_i$$$ after some number of operations for each $$$1 \le i \le n$$$?For example, let $$$n = 4$$$, $$$a = [3, 5, 4, 1]$$$ and $$$b = [1, 3, 2, 0]$$$. In this case, she can apply the operation twice:   after the first application of the operation she gets $$$a = [2, 4, 3, 0]$$$;  after the second use of the operation she gets $$$a = [1, 3, 2, 0]$$$. Thus, in two operations, she can get an array $$$b$$$ from an array $$$a$$$.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$). The second line of each test case contains exactly $$$n$$$ non-negative integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). The third line of each test case contains exactly $$$n$$$ non-negative integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ values over all test cases in the test does not exceed $$$2 \cdot 10^5$$$.

For each test case, output on a separate line:   YES, if by doing some number of operations it is possible to get an array $$$b$$$ from an array $$$a$$$;  NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

NoteThe first test case is analyzed in the statement.In the second test case, it is enough to apply the operation to array $$$a$$$ once.In the third test case, it is impossible to get array $$$b$$$ from array $$$a$$$.

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let A = readline().split(' ').map(Number);
        let B = readline().split(' ').map(Number);

        let maxDiff = 0;

        for (let i = 0; i < n; i++) {
            let diff = Math.abs(A[i] - B[i]);
            if (diff > maxDiff) {
                maxDiff = diff;
            }
        }

        let ok = true;

        for (let i = 0; i < n; i++) {
            if (B[i] !== 0 && A[i] - B[i] !== maxDiff) {
                ok = false;
                break;
            }
        }

        output(ok ? 'YES' : 'NO');
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var alist = nextIntArray(N);
		var blist = nextIntArray(N);
		var ok = true;
		var just = -1;
		var must = -1;
		for(var i = 0; i < N; i++){
			if(alist[i] < blist[i]){
				ok = false;
				break;
			}else if(alist[i] >= 0){
				if(blist[i] == 0){
					must = Math.max(must, alist[i]);
				}else{
					if(just == -1){
						just = alist[i] - blist[i];
					}else if(just != alist[i] - blist[i]){
						ok = false;
						break;
					}
				}
			}
		}
		//myerr({just, must});
		if(just != -1){
			if(just < must){
				ok = false;
			}
		}
		if(ok){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    var a = 0;
    for(i = 1; i <= t * 3; i++){
        if(i % 3 == 1){
            n = lines[i];
        }else if(i % 3 == 2){
            a = lines[i].split(' ').map(Number);
        }else{
            var b = lines[i].split(' ').map(Number);
            var T = 0, k = 0;
            for(j = 0; j < n; j++){
                if(a[j] - b[j] < 0){
                    k++;
                    break;
                }
                T = Math.max(T, a[j] - b[j]);
            }
            for(j = 0; j < n; j++){
                if(a[j] - b[j] < T && b[j] !== 0){
                    k++;
                    break;
                }
            }
            console.log(k !== 0 ? 'NO' : 'YES');

        }
    }
});

const rdline = require('readline');
const rl = rdline.createInterface({
    input: process.stdin
});

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    // input in lines
    solve();
});

let line = 0;
const readline = () => lines[line++];
/**
 * План подзадачи:
 *  преобразую строки в массивы
 * создам пустой массив C
 * идем по элементам массивов
 *   если элемент массива A меньше  элемента массива B, то сразу выводим невозможность получения массива NO
 *   пока массив A не будет равен массиву B, из каждого элемента массива A вычитай 1
 *
 */
solve = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var a = readline().split(" ").map(Number);
        var b = readline().split(" ").map(Number);
        var dif = 0;
        var ans = "YES";
        if (a === b) {
            ans;
        } else {
            for (let j = 0; j < n; j++) {
                if (a[j] - b[j] > dif) {
                    dif = a[j] - b[j];
                }
            }

            for (let j = 0; j < n; j++) {
                if (a[j] < b[j]) {
                    ans = "NO";
                } else if (a[j] - b[j] !== dif && b[j] !== 0) {
                    ans = "NO";
                }
            }
        }
        console.log(ans)
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
       let n = parseInt(readline());
       let arr1 = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr2 = readline().trim().split(" ").map(cur=>parseInt(cur));
       let dif  = Infinity;
       let flag = true;
       for(let i=0;i<n;i++){
            if(arr2[i]===0) continue;
            else{
                 if(arr1[i]<arr2[i]){
                      flag = false;
                      break;
                 }
                 if(dif===Infinity) dif = arr1[i] - arr2[i];
                 else {
                     if(dif!==arr1[i] - arr2[i]){
                          flag = false;
                          break;
                     }
                 }

            }
       }
       if(flag){
            for(let i=0;i<n;i++){
                 if(arr2[i]===0){
                      if(arr1[i]-arr2[i]>dif) {
                           flag = false;
                           break;
                      }
                 }
            }
       }
       if(flag===false) console.log("NO");
       else console.log("YES");
  }
};
solve();

'use strict';

function solve(n, a, b) {
  let max = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] < b[i]) return 'NO';
    max = Math.max(max, a[i] - b[i]);
  }
  const nums = [];
  for (let i = 0; i < n; i++) {
    nums[i] = Math.max(a[i] - max, 0);
  }
  for (let i = 0; i < n; i++) {
    if (b[i] !== nums[i]) return 'NO';
  }
  return 'YES';
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      const b = (await read()).split(' ').map(Number);
      res.push(solve(n, a, b));
    }
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', () => {
  inputs = str.split('\n').values();
  main(read);
});

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const sa = lines[l++].trim().split(' ').map(Number)
        const sb = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, sa, sb) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, sa, sb) {
    const ds = []
    let max = -Infinity
    for (let i = 0; i < n; i++) {
        ds[i] = sa[i] - sb[i]
        max = Math.max(max, ds[i])
    }
    for (let i = 0; i < n; i++) {
        if (ds[i] === max || !sb[i]) {
            //
        } else {
            return false
        }
    }
    return max >= 0
}

T = readline()
while (T--) {
   n = readline()
   a = readline().split(' ').map(a => +a)
   b = readline().split(' ').map(b => +b)
   ans = 'YES'
   xx = 0

   if(JSON.stringify(a)==JSON.stringify(b)){
      print(ans)
   }

   else {
      for(i=0; i<n; i++){
         if((a[i] - b[i]) > xx)
            xx = a[i] - b[i]
      }
      for(i = 0; i<n; i++){
         if(a[i] < b[i])
            ans = 'NO'
         else if((a[i]-b[i] != xx) && (b[i] !=0))
            ans = 'NO'

      }
      print(ans)
   }
}

var tests = parseInt(readline());
    var n;
    var a, b;
    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        b = readline().split(' ').map(x=>parseInt(x));

        var minDiff = 0;
        var ans = 'YES';
        var diffMatch = -1;
        for (var i = 0; i < n; i++) {
            var diff = a[i] - b[i];
            if (b[i] == 0) {
                if (diff > minDiff) {
                    minDiff = diff;
                }
            } else {
                if (diff < 0) {
                    ans = 'NO';
                    break;
                } else if (diffMatch == -1){
                    diffMatch = diff;
                } else if (diff != diffMatch) {
                    ans = 'NO';
                    break;
                }
            }
        }
        if (diffMatch != -1 && diffMatch < minDiff) {
            ans = 'NO';
        }

        print(ans);
    }

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let A = readline().split(' ').map(Number);
        let B = readline().split(' ').map(Number);

        let ok = true;

        for (let i = 0; i < n; i++) {
            if (A[i] < B[i]) {
                ok = false;
                break;
            }
        }

        output(ok ? 'YES' : 'NO');
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var alist = nextIntArray(N);
		var blist = nextIntArray(N);
		var ok = true;
		var just = -1;
		var must = -1;
		for(var i = 0; i < N; i++){
			if(alist[i] < blist[i]){
				ok = false;
				break;
			}else if(alist[i] > 0){
				if(blist[i] == 0){
					must = Math.max(must, alist[i]);
				}else{
					if(just == -1){
						just = alist[i] - blist[i];
					}else if(just != alist[i] - blist[i]){
						ok = false;
						break;
					}
				}
			}
		}
		if(just != -1){
			if(just < must){
				ok - false;
			}
		}
		if(ok){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

T = readline()
while (T--) {
   n = readline()
   a = readline().split(' ').map(a => +a)
   b = readline().split(' ').map(b => +b)
   ans = 'NO'
   maxNum = Math.max.apply(null, a)
   while(maxNum--){
      for(i=0; i<n; i++){
         a[i]--
         if(a[i]< 0)
            a[i] =0
      }
      if(JSON.stringify(a)==JSON.stringify(b)){
         ans = 'YES'
         break
      }
   }
   print(ans)
}


You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that:   $$$1 \le i < j < k \le n$$$;  $$$p_i < p_j$$$ and $$$p_j > p_k$$$.  Or say that there are no such indices.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$.

For each test case:    if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves;  if there are no such indices, print NO (case insensitive).  If there are multiple valid triples of indices, print any of them.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let found = false;
    for (let i = 0; i <= len - 3; i++) {
      let [a, b, c] = [arr[i], arr[i + 1], arr[i + 2]];
      if (a < b && b > c) {
        console.log("YES");
        console.log(`${i + 1} ${i + 2} ${i + 3}`);
        found = true;
        break;
      }
    }
    !found && console.log("NO");
  }
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c % 2) {
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  let ans = 'NO';
  const arrIdx = [];

  for (let i = 1; i < arr.length - 1; i++) {
    if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
      ans = 'YES';
      arrIdx.push(i, i + 1, i + 2);
      break;
    }
  }

  console.log(ans);

  if (arrIdx.length) {
    console.log(arrIdx.join(' '));
  }

  c++;
});

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt();
        let a = [];
        for(let i = 0; i < N; i++) {
            a.push(nextInt());
        }

        let result = "NO";

        for(let i = 0; i+2 < a.length; i++) {
            if (a[i] < a[i+1] && a[i+1] > a[i+2]) {
                result = "YES\n" + (i+1) + " " + (i+2) + " " + (i+3);
                break;
            }
        }

        print(result);
    }
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    inputBuffer += chunk;
});

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});

var n = parseInt(readline());
var res = [];

while (n--){
    readline();//ODIO LE DONNE
    var inn = readline().split(" ").map(function (a) {
        return parseInt(a);
    });
    var f = false;
    for (var i = 1 ; i<inn.length -1;i++){
        if (inn[i] > inn[i - 1] && inn[i] > inn[i + 1]) {
            f=true;
            res.push([i,i+1,i+2]);
            break;
        }
    }
    if (!f){
        res.push([])
    }

}
for (var i = 0;i<res.length;i++){
    write((res[i].length === 0)?"NO\n":("YES\n"+res[i].join(" ")+"\n"));

}

function solve() {
   var n = Number(read());
   var a = readArray(Number);
   for (var i = 1; i < n; i++) {
      if (a[i - 1] < a[i] && a[i + 1] < a[i]) {
         write('YES');
         write(i + ' ' + (i + 1) + ' ' + (i + 2));
         return;
      }
   }
   write('NO');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

var n = parseInt(readline());
var res = [];

while (n--){
    readline();//ODIO LE DONNE
    var inn = readline().split(" ").map(function (a) {
        return parseInt(a);
    });
    var f = false;
    for (var i = 1 ; i<inn.length -1;i++){
        if (inn[i-1] < inn[i] && inn[i]>inn[i+1]){
            f=true;
            res.push([i-1,i,i+1]);
            break;
        }
    }
    if (!f){
        res.push([])
    }

}
for (var i = 0;i<res.length;i++){
    write((res[i].length === 0)?"NO\n":("YES\n"+res[i].join(" ")+"\n"));

}

var n = parseInt(readline());
var res = [];

while (n--){
    readline();//ODIO LE DONNE
    var inn = readline().split(" ").map(function (a) {
        return parseInt(a);
    });
    var f = false;
    loop1:for (var i = 0 ; i<inn.length -2;i++){
        for (var j = i+1 ; j<inn.length -1;j++){
            if (inn[i]>inn[j]){
                continue;
            }
            for (var k = j+1 ; k<inn.length;k++){
                if (inn[j]>inn[k]){
                    res.push([i+1,j+1,k+1]);
                    f = true;
                    break loop1;
                }
            }
        }
    }
    if (!f){
        res.push([])
    }

}
for (var i = 0;i<res.length;i++){
    write((res[i].length === 0)?"NO\n":("YES\n"+res.join(" ")+"\n"));

}


You are given a connected weighted undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges.You are asked $$$k$$$ queries about it. Each query consists of a single integer $$$x$$$. For each query, you select a spanning tree in the graph. Let the weights of its edges be $$$w_1, w_2, \dots, w_{n-1}$$$. The cost of a spanning tree is $$$\sum \limits_{i=1}^{n-1} |w_i - x|$$$ (the sum of absolute differences between the weights and $$$x$$$). The answer to a query is the lowest cost of a spanning tree.The queries are given in a compressed format. The first $$$p$$$ $$$(1 \le p \le k)$$$ queries $$$q_1, q_2, \dots, q_p$$$ are provided explicitly. For queries from $$$p+1$$$ to $$$k$$$, $$$q_j = (q_{j-1} \cdot a + b) \mod c$$$.Print the xor of answers to all queries.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 50$$$; $$$n - 1 \le m \le 300$$$) — the number of vertices and the number of edges in the graph. Each of the next $$$m$$$ lines contains a description of an undirected edge: three integers $$$v$$$, $$$u$$$ and $$$w$$$ ($$$1 \le v, u \le n$$$; $$$v \neq u$$$; $$$0 \le w \le 10^8$$$) — the vertices the edge connects and its weight. Note that there might be multiple edges between a pair of vertices. The edges form a connected graph. The next line contains five integers $$$p, k, a, b$$$ and $$$c$$$ ($$$1 \le p \le 10^5$$$; $$$p \le k \le 10^7$$$; $$$0 \le a, b \le 10^8$$$; $$$1 \le c \le 10^8$$$) — the number of queries provided explicitly, the total number of queries and parameters to generate the queries. The next line contains $$$p$$$ integers $$$q_1, q_2, \dots, q_p$$$ ($$$0 \le q_j < c$$$) — the first $$$p$$$ queries.

Print a single integer — the xor of answers to all queries.

function PriorityQueue(compare) {
  this.heap = [];
  this.elements = 0;
  this.compare = compare || ((a, b) => a < b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(upVal, myVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements / 2;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = current * 2 + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(this.heap[rightChild], best)
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(myVal, best)) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
var iniEdges = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
  iniEdges[i] = [node1, node2, parseInt(edge[2])];
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) / 2);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var edges = new PriorityQueue((a, b) => {
  return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];
});

var edgeCuts = new Array(cuts.length);
edgeCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];
edgeCuts[cuts.length - 1] = [
  mst(edges, nodes, cuts[cuts.length - 1]),
  cuts[cuts.length - 1]
];
if (!sortedArrayEquals(edgeCuts[0][0][0], edgeCuts[cuts.length - 1][0][0]))
  calcCuts(cuts, edgeCuts, edges, 0, cuts.length - 1);
edgeCuts = edgeCuts.filter((i) => i != undefined);
edgeCuts = edgeCuts.filter(
  (i, id) => id == 0 || !sortedArrayEquals(i[0][0], edgeCuts[id - 1][0][0])
);
for (var i = 0; i < weights.length; i++) {
  edgeCuts.push([mst(edges, nodes, weights[i]), weights[i]]);
}
edgeCuts.sort((a, b) => a[1] - b[1]);
edgeCuts = edgeCuts.filter((i, id) => id == 0 || i[1] != edgeCuts[id - 1][1]);

var result = 0;
var q = 0;
var dict={}
for (var i = 0; i < k; i++) {
  var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;
  q = qbase * 2;
  var res= dict[q]
  if (dict[q] == undefined){
  var j = upperBoundEdges(edgeCuts, q);

  var edgesList = edgeCuts[j][0][0];
  var weightsList = edgeCuts[j][0][1];
  var z = upperBound(weightsList, q);
  var res =
    (edgeCuts[j][0][2] - (n - 1 - 2 * z) * Math.abs(edgeCuts[j][1] - q)) / 2;}
  result ^= res;
}

print(result<0?result+8*(1<<30):result);

function upperBoundEdges(edgeCuts, q) {
  var min = 0;
  var max = edgeCuts.length;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (edgeCuts[mid][1] <= q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid;
}

function upperBound(arr, q) {
  var min = -1;
  var max = arr.length;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (arr[mid] <= q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid + 1;
}

function calcCuts(cuts, edgeCuts, edges, ini, end) {
  var mid = Math.floor((ini + end) / 2);
  if (mid == ini) return;
  edgeCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];
  var equalDown = sortedArrayEquals(edgeCuts[ini][0][0], edgeCuts[mid][0][0]);
  var equalUp = sortedArrayEquals(edgeCuts[end][0][0], edgeCuts[mid][0][0]);
  if (!equalDown) calcCuts(cuts, edgeCuts, edges, ini, mid);
  if (!equalUp) calcCuts(cuts, edgeCuts, edges, mid, end);
}

function sortedArrayEquals(a, b) {
  for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;
  return true;
}

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(edges, nodes, q) {
  edges.clear();
  var visited = { 0: true };
  var nVisited = 1;
  var edgesOrder = [];
  var weightsOrder = [];
  var sum = 0;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (true) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      edgesOrder.push(min[2]);
      weightsOrder.push(min[3]);
      sum += min[1];
      if (++nVisited == nodes.length) break;
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [
    edgesOrder.sort((a, b) => a - b),
    weightsOrder.sort((a, b) => a - b),
    sum
  ];
}

function PriorityQueue(compare) {
  this.heap = [];
  this.elements = 0;
  this.compare = compare || ((a, b) => a < b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(upVal, myVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements / 2;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = current * 2 + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(this.heap[rightChild], best)
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(myVal, best)) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
var iniEdges = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
  iniEdges[i] = [node1, node2, parseInt(edge[2])];
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) / 2);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var edges = new PriorityQueue((a, b) => {
  return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];
});

var edgeCuts = new Array(cuts.length);
edgeCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];
edgeCuts[cuts.length - 1] = [
  mst(edges, nodes, cuts[cuts.length - 1]),
  cuts[cuts.length - 1]
];
if (!sortedArrayEquals(edgeCuts[0][0][0], edgeCuts[cuts.length - 1][0][0]))
  calcCuts(cuts, edgeCuts, edges, 0, cuts.length - 1);
edgeCuts = edgeCuts.filter((i) => i != undefined);
edgeCuts = edgeCuts.filter(
  (i, id) => id == 0 || !sortedArrayEquals(i[0][0], edgeCuts[id - 1][0][0])
);
for (var i = 0; i < weights.length; i++) {
  edgeCuts.push([mst(edges, nodes, weights[i]), weights[i]]);
}
edgeCuts.sort((a, b) => a[1] - b[1]);
edgeCuts = edgeCuts.filter((i, id) => id == 0 || i[1] != edgeCuts[id - 1][1]);

var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;
  q = qbase * 2;
  var j = upperBoundEdges(edgeCuts, q);

  var edgesList = edgeCuts[j][0][0];
  var weightsList = edgeCuts[j][0][1];
  var z = upperBound(weightsList, q);
  var sum2 =
    (edgeCuts[j][0][2] - (n - 1 - 2 * z) * Math.abs(edgeCuts[j][1] - q)) / 2;
  result ^= sum2;
}

print(result<0?result+8*(1<<30):result);

function upperBoundEdges(edgeCuts, q) {
  var min = 0;
  var max = edgeCuts.length;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (edgeCuts[mid][1] <= q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid;
}

function upperBound(arr, q) {
  var min = -1;
  var max = arr.length;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (arr[mid] <= q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid + 1;
}

function calcCuts(cuts, edgeCuts, edges, ini, end) {
  var mid = Math.floor((ini + end) / 2);
  if (mid == ini) return;
  edgeCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];
  var equalDown = sortedArrayEquals(edgeCuts[ini][0][0], edgeCuts[mid][0][0]);
  var equalUp = sortedArrayEquals(edgeCuts[end][0][0], edgeCuts[mid][0][0]);
  if (!equalDown) calcCuts(cuts, edgeCuts, edges, ini, mid);
  if (!equalUp) calcCuts(cuts, edgeCuts, edges, mid, end);
}

function sortedArrayEquals(a, b) {
  for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;
  return true;
}

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(edges, nodes, q) {
  edges.clear();
  var visited = { 0: true };
  var nVisited = 1;
  var edgesOrder = [];
  var weightsOrder = [];
  var sum = 0;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (true) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      edgesOrder.push(min[2]);
      weightsOrder.push(min[3]);
      sum += min[1];
      if (++nVisited == nodes.length) break;
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [
    edgesOrder.sort((a, b) => a - b),
    weightsOrder.sort((a, b) => a - b),
    sum
  ];
}

function PriorityQueue(compare) {
  this.heap = [];
  this.elements = 0;
  this.compare = compare || ((a, b) => a < b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(upVal, myVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements / 2;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = current * 2 + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(this.heap[rightChild], best)
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(myVal, best)) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
var iniEdges = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
  iniEdges[i] = [node1, node2, parseInt(edge[2])];
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) / 2);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var edges = new PriorityQueue((a, b) => {
  return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];
});

var edgeCuts = new Array(cuts.length);
edgeCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];
edgeCuts[cuts.length - 1] = [
  mst(edges, nodes, cuts[cuts.length - 1]),
  cuts[cuts.length - 1]
];
if (!sortedArrayEquals(edgeCuts[0][0][0], edgeCuts[cuts.length - 1][0][0]))
  calcCuts(cuts, edgeCuts, edges, 0, cuts.length - 1);
edgeCuts = edgeCuts.filter((i) => i != undefined);
edgeCuts = edgeCuts.filter(
  (i, id) => id == 0 || !sortedArrayEquals(i[0][0], edgeCuts[id - 1][0][0])
);
for (var i = 0; i < weights.length; i++) {
  edgeCuts.push([mst(edges, nodes, weights[i]), weights[i]]);
}
edgeCuts.sort((a, b) => a[1] - b[1]);
edgeCuts = edgeCuts.filter((i, id) => id == 0 || i[1] != edgeCuts[id - 1][1]);

var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;
  q = qbase * 2;
  var j = upperBoundEdges(edgeCuts, q);

  var edgesList = edgeCuts[j][0][0];
  var weightsList = edgeCuts[j][0][1];
  var z = upperBound(weightsList, q);
  var sum2 =
    (edgeCuts[j][0][2] - (n - 1 - 2 * z) * Math.abs(edgeCuts[j][1] - q)) / 2;
  result ^= sum2;
}

print(result);

function upperBoundEdges(edgeCuts, q) {
  var min = 0;
  var max = edgeCuts.length;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (edgeCuts[mid][1] <= q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid;
}

function upperBound(arr, q) {
  var min = -1;
  var max = arr.length;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (arr[mid] <= q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid + 1;
}

function calcCuts(cuts, edgeCuts, edges, ini, end) {
  var mid = Math.floor((ini + end) / 2);
  if (mid == ini) return;
  edgeCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];
  var equalDown = sortedArrayEquals(edgeCuts[ini][0][0], edgeCuts[mid][0][0]);
  var equalUp = sortedArrayEquals(edgeCuts[end][0][0], edgeCuts[mid][0][0]);
  if (!equalDown) calcCuts(cuts, edgeCuts, edges, ini, mid);
  if (!equalUp) calcCuts(cuts, edgeCuts, edges, mid, end);
}

function sortedArrayEquals(a, b) {
  for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;
  return true;
}

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(edges, nodes, q) {
  edges.clear();
  var visited = { 0: true };
  var nVisited = 1;
  var edgesOrder = [];
  var weightsOrder = [];
  var sum = 0;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (true) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      edgesOrder.push(min[2]);
      weightsOrder.push(min[3]);
      sum += min[1];
      if (++nVisited == nodes.length) break;
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [
    edgesOrder.sort((a, b) => a - b),
    weightsOrder.sort((a, b) => a - b),
    sum
  ];
}

function PriorityQueue(compare) {
  this.heap = [];
  this.elements = 0;
  this.compare = compare || ((a, b) => a < b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(upVal, myVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements / 2;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = current * 2 + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(this.heap[rightChild], best)
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(myVal, best)) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
var iniEdges = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
  iniEdges[i] = [node1, node2, parseInt(edge[2])];
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) / 2);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var edges = new PriorityQueue((a, b) => {
  return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];
});

var edgesCuts = new Array(cuts.length);
edgesCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];
edgesCuts[cuts.length - 1] = [
  mst(edges, nodes, cuts[cuts.length - 1]),
  cuts[cuts.length - 1]
];
if (!sortedArrayEquals(edgesCuts[0][0], edgesCuts[cuts.length - 1][0]))
  calcCuts(cuts, edgesCuts, edges, 0, cuts.length - 1);
edgesCuts = edgesCuts.filter((i) => i != undefined);
edgesCuts = edgesCuts.filter(
  (i, id) => id == 0 || !sortedArrayEquals(i[0], edgesCuts[id - 1][0])
);

var dict = {};
var dictCuts = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;
  q = qbase * 2;
  if (dict[q] == undefined) {
    var j = upperBound(edgesCuts, q);

    var edgesList = edgesCuts[j][0];
    var sum = 0;
    for (var edge of edgesList) {
      sum += Math.abs(iniEdges[edge][2] - qbase);
    }
    dict[q] = sum;
  }
  result ^= dict[q];
}

print(result);

function upperBound(edgesCuts, q) {
  var min = 0;
  var max = edgesCuts.length - 1;
  var mid = Math.floor((min + max) / 2);
  while (min != mid) {
    if (edgesCuts[mid][1] < q) min = mid;
    else max = mid;
    mid = Math.floor((min + max) / 2);
  }
  return mid;
}

function calcCuts(cuts, edgesCuts, edges, ini, end) {
  var mid = Math.floor((ini + end) / 2);
  if (mid == ini) return;
  edgesCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];
  var equalDown = sortedArrayEquals(edgesCuts[ini][0], edgesCuts[mid][0]);
  var equalUp = sortedArrayEquals(edgesCuts[end][0], edgesCuts[mid][0]);
  if (!equalDown) calcCuts(cuts, edgesCuts, edges, ini, mid);
  if (!equalUp) calcCuts(cuts, edgesCuts, edges, mid, end);
}

function sortedArrayEquals(a, b) {
  for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;
  return true;
}

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(edges, nodes, q) {
  edges.clear();
  var visited = { 0: true };
  var nVisited = 1;
  var edgesOrder = [];
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (true) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      edgesOrder.push(min[2]);
      if (++nVisited == nodes.length) break;
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return edgesOrder.sort();
}

function PriorityQueue(compare) {
  this.heap = [];
  this.elements = 0;
  this.compare = compare || ((a, b) => a < b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(upVal, myVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements / 2;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = current * 2 + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(this.heap[rightChild], best)
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(myVal, best)) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
var iniEdges = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
  iniEdges[i] = [node1, node2, parseInt(edge[2])];
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) / 2);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var edges = new PriorityQueue((a, b) => {
  return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];
});

var edgesCuts = new Array(cuts.length);
edgesCuts[0] = [mst(edges, nodes, cuts[0]), cuts[0]];
edgesCuts[cuts.length - 1] = [
  mst(edges, nodes, cuts[cuts.length - 1]),
  cuts[cuts.length - 1]
];
if (!sortedArrayEquals(edgesCuts[0][0], edgesCuts[cuts.length - 1][0]))
  calcCuts(cuts, edgesCuts, edges, 0, cuts.length - 1);
edgesCuts = edgesCuts.filter((i) => i != undefined);
edgesCuts = edgesCuts.filter(
  (i, id) => id == 0 || !sortedArrayEquals(i[0], edgesCuts[id - 1][0])
);

var dict = {};
var dictCuts = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  var qbase = i < queries.length ? queries[i] : ((q * a) / 2 + b) % c;
  q = qbase * 2;
  if (dict[q] == undefined) {
    var jmin = 0;
    var jmax = edgesCuts.length - 1;

    var j = Math.floor((jmin + jmax) / 2);
    while (jmin != j) {
      if (edgesCuts[j][1] <= q) jmin = j;
      else jmax = j;
      j = Math.floor((jmin + jmax) / 2);
    }

    var edgesList = edgesCuts[j][0];
    var sum = 0;
    for (var edge of edgesList) {
      sum += Math.abs(iniEdges[edge][2] - qbase);
    }
    dict[q] = sum;
  }
  result ^= dict[q];
}

print(result);

function calcCuts(cuts, edgesCuts, edges, ini, end) {
  var mid = Math.floor((ini + end) / 2);
  if (mid == ini) return;
  edgesCuts[mid] = [mst(edges, nodes, cuts[mid]), cuts[mid]];
  var equalDown = sortedArrayEquals(edgesCuts[ini][0], edgesCuts[mid][0]);
  var equalUp = sortedArrayEquals(edgesCuts[end][0], edgesCuts[mid][0]);
  if (!equalDown) calcCuts(cuts, edgesCuts, edges, ini, mid);
  if (!equalUp) calcCuts(cuts, edgesCuts, edges, mid, end);
}

function sortedArrayEquals(a, b) {
  return a.join() == b.join();
}

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(edges, nodes, q) {
  edges.clear();
  var visited = { 0: true };
  var nVisited = 1;
  var edgesOrder = [];
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (true) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      edgesOrder.push(min[2]);
      if (++nVisited == nodes.length) break;
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return edgesOrder.sort();
}

function PriorityQueue(compare) {
  this.heap = [];
  this.elements = 0;
  this.compare = compare || ((a, b) => a < b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(upVal, myVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements / 2;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = current * 2 + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(this.heap[rightChild], best)
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(myVal, best)) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
var iniEdges = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
  iniEdges[i] = [node1, node2, weight];
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) / 2);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var edges = new PriorityQueue((a, b) => {
  return a[1] == b[1] ? b[3] < a[3] : a[1] < b[1];
});

var edgesCuts = new Array(cuts.length);
edgesCuts[0] = [mst(edges, nodes, cuts[0])[2], cuts[0]];
edgesCuts[cuts.length - 1] = [
  mst(edges, nodes, cuts[cuts.length - 1])[2],
  cuts[cuts.length - 1]
];
if (!sortedArrayEquals(edgesCuts[0][0], edgesCuts[cuts.length - 1][0]))
  calcCuts(cuts, edgesCuts, edges, 0, cuts.length - 1);
edgesCuts = edgesCuts.filter((i) => i != undefined);

var dict = {};
var dictCuts = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  q = i < queries.length ? queries[i] * 2 : (((q * a) / 2 + b) % c) * 2;
  if (dict[q] == undefined) {
    var j = 0;

    while (j < edgesCuts.length && edgesCuts[j][1] <= q) {
      j++;
    }
    j--;
    var edgesList = edgesCuts[j][0];
    var sum = 0;
    for (var edge of edgesList) {
      sum += Math.abs(iniEdges[edge][2] - q);
    }
    dict[q] = sum / 2;
  }
  result ^= dict[q];
}
// for (var i = 0; i < k; i++) {
//   q = i < queries.length ? queries[i] * 2 : (((q * a) / 2 + b) % c) * 2;
//   if (dict[q] == undefined) {
//     var j = 0;

//     while (j < cuts.length && cuts[j] <= q) {
//       j++;
//     }
//     j--;
//     var prevSol = dictCuts[cuts[j]];
//     if (prevSol == undefined) {
//       dictCuts[cuts[j]] = mst(edges, nodes, cuts[j]);
//       prevSol = dictCuts[cuts[j]];
//     }
//     var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) / 2;
//     dict[q] = sol;
//   }
//   result ^= dict[q];
// }

print(result);

function calcCuts(cuts, edgesCuts, edges, ini, end) {
  var mid = Math.floor((ini + end) / 2);
  if (mid == ini) return;
  edgesCuts[mid] = [mst(edges, nodes, cuts[mid])[2], cuts[mid]];
  var equalDown = sortedArrayEquals(edgesCuts[ini][0], edgesCuts[mid][0]);
  var equalUp = sortedArrayEquals(edgesCuts[end][0], edgesCuts[mid][0]);
  if (!equalDown) calcCuts(cuts, edgesCuts, edges, ini, mid);
  if (!equalUp) calcCuts(cuts, edgesCuts, edges, mid, end);
  if (equalDown || equalUp) delete edgesCuts[mid];
}

function sortedArrayEquals(a, b) {
  return a.join() == b.join();
}

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(edges, nodes, q) {
  edges.clear();
  var sum = 0;
  var edgesUp = 0;
  var visited = { 0: true };
  var nVisited = 1;
  var edgesOrder = [];
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  //var eds = [];
  while (true) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      sum += min[1];
      edgesOrder.push(min[2]);
      if (q < min[3]) {
        edgesUp++;
      }
      //  eds.push(min[2]); // Don't know why this makes the code run faster
      if (++nVisited == nodes.length) break;
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [sum, edgesUp, edgesOrder.sort()];
}

function PriorityQueue(maxSize, compare) {
  this.maxSize = maxSize || 100000;
  this.heap = new Array(this.maxSize);
  this.elements = 0;
  this.compare = compare || ((a, b) => a - b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(myVal, upVal) >= 0) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements >> 1;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = (current << 1) + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(best, this.heap[rightChild]) > 0
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(best, myVal) >= 0) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) << 1; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) >> 1);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));
var max = queries.reduce((a, b) => Math.max(a, b), 0);
max = Math.max(max, c) << 1;

var dictCuts = {};

var dict = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  q = i < queries.length ? queries[i] << 1 : (((q * a) >> 1) + b) % c << 1;
  if (dict[q] == undefined) {
    var j = 0;
    while (j < cuts.length && cuts[j] <= q) {
      j++;
    }
    j--;
    var prevSol = dictCuts[cuts[j]];
    if (prevSol == undefined) {
      dictCuts[cuts[j]] = mst(nodes, cuts[j]);
      prevSol = dictCuts[cuts[j]];
    }
    var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) >> 1;
    dict[q] = sol;
  }
  result ^= dict[q];
  if (i % 100000 == 0) print(i / 100000);
}

print(result);

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(nodes, q) {
  var edges = new PriorityQueue(400, (a, b) => {
    var res = a[1] - b[1];
    return res == 0 ? b[3] - a[3] : res;
  });
  var sum = 0;
  var edgesUp = 0;
  var visited = { 0: true };
  var nVisited = 1;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  var eds = [];
  while (nVisited < nodes.length) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      nVisited++;
      sum += min[1];
      eds.push(min[2]); // Don't know why this makes the code run faster
      if (q < min[3]) {
        edgesUp++;
      }
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [sum, edgesUp];
}

function PriorityQueue(maxSize, compare) {
  this.maxSize = maxSize || 100000;
  this.heap = new Array(this.maxSize);
  this.elements = 0;
  this.compare = compare || ((a, b) => a - b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(myVal, upVal) >= 0) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements >> 1;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = (current << 1) + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(best, this.heap[rightChild]) > 0
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(best, myVal) >= 0) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) << 1; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  cuts.add(w1);
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) >> 1);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));
var max = queries.reduce((a, b) => Math.max(a, b), 0);
max = Math.max(max, c) << 1;

var dictCuts = {};

var dict = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  q = i < queries.length ? queries[i] << 1 : (((q * a) >> 1) + b) % c << 1;
  if (dict[q] == undefined) {
    var j = 0;
    while (j < cuts.length && cuts[j] <= q) {
      j++;
    }
    j--;
    var prevSol = dictCuts[cuts[j]];
    if (prevSol == undefined) {
      dictCuts[cuts[j]] = mst(nodes, cuts[j]);
      prevSol = dictCuts[cuts[j]];
    }
    var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) >> 1;
    dict[q] = sol;
  }
  result ^= dict[q];
  if (n > 17 && nodes[17][0][1] == 51480 * 2 && i % 10000 == 0) print(i / 1000);
}

print(result);

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(nodes, q) {
  var edges = new PriorityQueue(400, (a, b) => {
    var res = a[1] - b[1];
    return res == 0 ? b[3] - a[3] : res;
  });
  var sum = 0;
  var edgesUp = 0;
  var visited = { 0: true };
  var nVisited = 1;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  var eds = [];
  while (nVisited < nodes.length) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      nVisited++;
      sum += min[1];
      eds.push(min[2]); // Don't know why this makes the code run faster
      if (q < min[3]) {
        edgesUp++;
      }
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [sum, edgesUp];
}

function PriorityQueue(maxSize, compare) {
  this.maxSize = maxSize || 100000;
  this.heap = new Array(this.maxSize);
  this.elements = 0;
  this.compare = compare || ((a, b) => a - b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(myVal, upVal) >= 0) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements >> 1;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = (current << 1) + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(best, this.heap[rightChild]) > 0
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(best, myVal) >= 0) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) >> 1);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var dictCuts = {};
for (var cut of cuts) {
  dictCuts[cut] = mst(nodes, cut);
}

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

var dict = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  q = i < queries.length ? 2 * queries[i] : (((q * a) / 2 + b) % c) * 2;
  if (dict[q] == undefined) {
    var j = 0;
    while (j < cuts.length && cuts[j] <= q) {
      j++;
    }
    j--;
    var prevSol = dictCuts[cuts[j]];
    var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) / 2;
    dict[q] = sol;
  }
  result ^= dict[q];
}

print(result);

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(nodes, q) {
  var edges = new PriorityQueue(400, (a, b) => {
    var res = a[1] - b[1];
    return res == 0 ? b[3] - a[3] : res;
  });
  var sum = 0;
  var edgesUp = 0;
  var visited = new Set();
  visited.add(0);
  var nVisited = 1;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (nVisited < nodes.length) {
    var min = edges.pop();
    var node = min[0];
    if (!visited.has(node)) {
      visited.add(node);
      nVisited++;
      sum += min[1];
      if (q < min[3]) {
        edgesUp++;
      }
      for (var edge of nodes[node]) {
        if (!visited.has(edge[0]))
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [sum, edgesUp];
}

function PriorityQueue(maxSize, compare) {
  this.maxSize = maxSize || 100000;
  this.heap = new Array(this.maxSize);
  this.elements = 0;
  this.compare = compare || ((a, b) => a - b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.add = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (this.compare(myVal, upVal) >= 0) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  if (this.elements == 1) {
    return this.heap[--this.elements];
  }
  var el = this.heap[0];

  var myVal = this.heap[--this.elements];
  this.heap[0] = myVal;

  var current = 0;
  var maxSize = this.elements >> 1;
  var leftChild;
  var rightChild;
  var best;

  while (current < maxSize) {
    leftChild = (current << 1) + 1;
    rightChild = leftChild + 1;
    best = this.heap[leftChild];

    if (
      rightChild < this.elements &&
      this.compare(best, this.heap[rightChild]) > 0
    ) {
      best = this.heap[rightChild];
      leftChild = rightChild;
    }
    if (this.compare(best, myVal) >= 0) {
      break;
    }
    this.heap[current] = best;
    current = leftChild;
  }
  this.heap[current] = myVal;

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var weights = Array(m);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]) * 2; //*2 to avoid decimals
  addEdge(nodes, node1, node2, weight, i);
  weights[i] = weight;
}

var cuts = new Set();
cuts.add(0);
for (var i = 0; i < m; i++) {
  var w1 = weights[i];
  for (var j = 0; j < i; j++) {
    cuts.add((w1 + weights[j]) >> 1);
  }
}
cuts = Array.from(cuts);
cuts.sort((a, b) => a - b);

var dictCuts = {};
for (var cut of cuts) {
  dictCuts[cut] = mst(nodes, cut);
}

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

for (var i = p; i < k; i++) {
  queries.push((queries[i - 1] * a + b) % c);
}

var dict = {};
var result = 0;
var q = 0;
for (var i = 0; i < k; i++) {
  q = i < queries.length ? 2 * queries[i] : (((q * a) / a + b) % c) * 2;
  if (dict[q] == undefined) {
    var j = 0;
    while (j < cuts.length && cuts[j] <= q) {
      j++;
    }
    j--;
    var prevSol = dictCuts[cuts[j]];
    var sol = (prevSol[0] + (n - 1 - 2 * prevSol[1]) * (q - cuts[j])) / 2;
    dict[q] = sol;
  }
  result ^= dict[q];
}

print(result);

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(nodes, q) {
  var edges = new PriorityQueue(400, (a, b) => {
    var res = a[1] - b[1];
    return res == 0 ? b[3] - a[3] : res;
  });
  var sum = 0;
  var edgesUp = 0;
  var visited = new Set();
  visited.add(0);
  var nVisited = 1;
  for (var edge of nodes[0])
    edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
  while (nVisited < nodes.length) {
    var min = edges.pop();
    var node = min[0];
    if (!visited.has(node)) {
      visited.add(node);
      nVisited++;
      sum += min[1];
      if (q < min[3]) {
        edgesUp++;
      }
      for (var edge of nodes[node]) {
        if (!visited.has(edge[0]))
          edges.add([edge[0], Math.abs(edge[1] - q), edge[2], edge[1]]);
      }
    }
  }
  return [sum, edgesUp];
}

function PriorityQueue(maxSize, compare) {
  this.maxSize = maxSize || 100000;
  this.heap = new Array(this.maxSize);
  this.elements = 0;
  this.compare = compare || ((a, b) => a - b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.insert = function (myVal) {
  this.heap[this.elements++] = myVal;

  var current = this.elements - 1;
  while (current > 0) {
    var up = (current - 1) >> 1;
    var upVal = this.heap[up];
    if (!this.compare(myVal, upVal)) break;
    this.heap[current] = upVal;
    current = up;
  }
  this.heap[current] = myVal;
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  var el = this.heap[0];

  this.heap[0] = this.heap[this.elements - 1];
  this.elements--;

  var current = 0;
  var leftChild = current * 2 + 1;
  var rightChild = current * 2 + 2;
  var currentVal = this.heap[current];
  var leftChildVal = this.heap[leftChild];
  var rightChildVal = this.heap[rightChild];

  while (
    rightChild < this.elements &&
    (this.compare(currentVal, leftChildVal) > 0 ||
      this.compare(currentVal, rightChildVal) > 0)
  ) {
    if (this.compare(leftChildVal, rightChildVal) > 0) {
      this.heap[rightChild] = currentVal;
      this.heap[current] = rightChildVal;
      current = rightChild;
    } else {
      this.heap[leftChild] = currentVal;
      this.heap[current] = leftChildVal;
      current = leftChild;
    }
    leftChild = current * 2 + 1;
    rightChild = current * 2 + 2;
    currentVal = this.heap[current];
    leftChildVal = this.heap[leftChild];
    rightChildVal = this.heap[rightChild];
  }

  if (
    rightChild == this.elements &&
    this.compare(currentVal, leftChildVal) > 0
  ) {
    this.heap[leftChild] = currentVal;
    this.heap[current] = leftChildVal;
  }

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var rrr = false;
var aaa = {};
var bbb = 0;
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]);
  if (weight == 51480) rrr = true;
  if (rrr) {
    if (aaa[node1 + "," + node2] == undefined) aaa[node1 + "," + node2] = true;
    else bbb++;
  }
  addEdge(nodes, node1, node2, weight, i);
}

if (rrr) print(bbb);

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

for (var i = p; i < k; i++) {
  queries.push((queries[i - 1] * a + b) % c);
}

var dict = {};
var results = [];
for (var i = 0; i < queries.length; i++) {
  q = queries[i];
  if (dict[q] == undefined) dict[q] = mst(nodes, q);
  if (n > 17 && nodes[17][0][1] == 51480 && i % 1000 == 0)
    print(i / 1000 + "," + Object.keys(dict).length);
  results.push(dict[q]);
}

print(results.reduce((a, b) => a ^ b, 0));

function addEdge(nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];

  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
}

function mst(nodes, q) {
  var edges = new PriorityQueue(400, (a, b) => a[1] - b[1]);
  var sum = 0;
  var visited = { 0: true };
  var nVisited = 1;
  for (var edge of nodes[0])
    edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);
  var eds = [];
  while (nVisited < nodes.length) {
    var min = edges.pop();
    var node = min[0];
    if (!visited[node]) {
      visited[node] = true;
      nVisited++;
      sum += min[1];
      eds.push(min[2]);
      for (var edge of nodes[node]) {
        if (!visited[edge[0]])
          edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);
      }
    }
  }
  return sum;
}

function PriorityQueue(maxSize, compare) {
  this.maxSize = maxSize || 100000;
  this.heap = new Array(this.maxSize);
  this.elements = 0;
  this.compare = compare || ((a, b) => a - b);
}

PriorityQueue.prototype.size = function () {
  return this.elements;
};

PriorityQueue.prototype.isEmpty = function () {
  return this.elements == 0;
};

PriorityQueue.prototype.clear = function () {
  this.elements = 0;
};

PriorityQueue.prototype.peek = function () {
  return this.elements > 0 ? heap[0] : undefined;
};

PriorityQueue.prototype.insert = function (e) {
  if (this.elements == this.maxSize) throw "Error max size exceeded";
  this.heap[this.elements++] = e;

  var current = this.elements - 1;
  while (
    current > 0 &&
    this.compare(this.heap[Math.floor((current - 1) / 2)], this.heap[current]) >
      0
  ) {
    var tmp = this.heap[Math.floor((current - 1) / 2)];
    this.heap[Math.floor((current - 1) / 2)] = this.heap[current];
    this.heap[current] = tmp;
    current = Math.floor((current - 1) / 2);
  }
};

PriorityQueue.prototype.pop = function () {
  if (this.elements == 0) return null;
  var el = this.heap[0];

  this.heap[0] = this.heap[this.elements - 1];
  this.elements--;

  var current = 0;
  var leftChild = current * 2 + 1;
  var rightChild = current * 2 + 2;
  var currentVal = this.heap[current];
  var leftChildVal = this.heap[leftChild];
  var rightChildVal = this.heap[rightChild];

  while (
    rightChild < this.elements &&
    (this.compare(currentVal, leftChildVal) > 0 ||
      this.compare(currentVal, rightChildVal) > 0)
  ) {
    if (this.compare(leftChildVal, rightChildVal) > 0) {
      this.heap[rightChild] = currentVal;
      this.heap[current] = rightChildVal;
      current = rightChild;
    } else {
      this.heap[leftChild] = currentVal;
      this.heap[current] = leftChildVal;
      current = leftChild;
    }
    leftChild = current * 2 + 1;
    rightChild = current * 2 + 2;
    currentVal = this.heap[current];
    leftChildVal = this.heap[leftChild];
    rightChildVal = this.heap[rightChild];
  }

  if (
    rightChild == this.elements &&
    this.compare(currentVal, leftChildVal) > 0
  ) {
    this.heap[leftChild] = currentVal;
    this.heap[current] = leftChildVal;
  }

  return el;
};

PriorityQueue.prototype.toArray = function () {
  return this.heap.filter((_, id) => id < this.elements);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
var iniEdges = [];
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]);
  addEdge(iniEdges, nodes, node1, node2, weight, i);
}

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

print(JSON.stringify(iniEdges) + ","+p+ ","+k+ ","+a+ ","+b+","+c)

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

for (var i = p; i < k; i++) {
  queries.push((queries[i - 1] * a + b) % c);
}

var dict = {};
var results = [];
var dictOrder = {};
for (var i = 0; i < queries.length; i++) {
  q = queries[i];
  if (dict[q] == undefined) dict[q] = mst(dictOrder, iniEdges, nodes, q);
  results.push(dict[q]);
}

print(results.reduce((a, b) => a ^ b, 0));

function addEdge(iniEdges, nodes, n1, n2, w, i) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];
  nodes[n1 - 1].push([n2 - 1, w, i]);
  nodes[n2 - 1].push([n1 - 1, w, i]);
  iniEdges.push([i, n1, n2, w]);
}

function mst(dictOrder, iniEdges, nodes, q) {
  var edges = new PriorityQueue(400, (a, b) => a[1] - b[1]);
  var iniEdges2 = iniEdges.map((i) => [i[0], i[1], i[2], Math.abs(i[3] - q)]);
  iniEdges2.sort((a, b) => a[3] - b[3]);
  var key = iniEdges2.map((i) => i[0]).join(",");

  var sum = 0;
  if (dictOrder[key] == undefined) {
    var visited = { 0: true };
    var nVisited = 1;
    for (var edge of nodes[0])
      edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);
    var eds = [];
    while (nVisited < nodes.length) {
      var min = edges.pop();
      var node = min[0];
      if (!visited[node]) {
        visited[node] = true;
        nVisited++;
        sum += min[1];
        eds.push(min[2]);
        for (var edge of nodes[node]) {
          if (!visited[edge[0]])
            edges.insert([edge[0], Math.abs(edge[1] - q), edge[2]]);
        }
      }
    }
    dictOrder[key] = eds;
  } else {
    for (el of dictOrder[key]) sum += Math.abs(iniEdges[el][3] - q);
  }
  return sum;
}

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var nodes = Array(n);
for (var i = 0; i < m; i++) {
  var edge = readline().split(" ");
  var node1 = parseInt(edge[0]);
  var node2 = parseInt(edge[1]);
  var weight = parseInt(edge[2]);
  addEdge(nodes, node1, node2, weight);
}

var line = readline().split(" ");
var p = parseInt(line[0]);
var k = parseInt(line[1]);
var a = parseInt(line[2]);
var b = parseInt(line[3]);
var c = parseInt(line[4]);

var queries = readline()
  .split(" ")
  .map((i) => parseInt(i));

for (var i = p; i < k; i++) {
  queries.push((queries[i - 1] * a + b) % c);
}

var dict = {};
var results = [];
for (var i = 0; i < queries.length; i++) {
  q = queries[i];
  if (dict[q] == undefined) dict[q] = mst(nodes, q);
  results.push(dict[q]);
}

print(
  results.reduce((a, b) => a ^ b),
  0
);

function addEdge(nodes, n1, n2, w) {
  if (nodes[n1 - 1] == undefined) nodes[n1 - 1] = [];
  if (nodes[n2 - 1] == undefined) nodes[n2 - 1] = [];
  nodes[n1 - 1].push([n2 - 1, w]);
  nodes[n2 - 1].push([n1 - 1, w]);
}

function mst(nodes, q) {
  var nodes2 = nodes.map((i) => i.map((j) => [j[0], Math.abs(j[1] - q)]));
  var edges = nodes2[0];
  var sum = 0;
  var vertexs = new Set();
  vertexs.add(0);
  while (edges.length > 0) {
    var min = edges.reduce((a, b) => (a[1] <= b[1] ? a : b), [0, Infinity]);
    sum += min[1];
    vertexs.add(min[0]);
    edges = edges.concat(nodes2[min[0]]);
    edges = edges.filter((i) => !vertexs.has(i[0]));
  }
  return sum;
}