There are $$$n$$$ candies in a row, they are numbered from left to right from $$$1$$$ to $$$n$$$. The size of the $$$i$$$-th candy is $$$a_i$$$.Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten.The process consists of moves. During a move, the player eats one or more sweets from her/his side (Alice eats from the left, Bob — from the right).Alice makes the first move. During the first move, she will eat $$$1$$$ candy (its size is $$$a_1$$$). Then, each successive move the players alternate — that is, Bob makes the second move, then Alice, then again Bob and so on.On each move, a player counts the total size of candies eaten during the current move. Once this number becomes strictly greater than the total size of candies eaten by the other player on their previous move, the current player stops eating and the move ends. In other words, on a move, a player eats the smallest possible number of candies such that the sum of the sizes of candies eaten on this move is strictly greater than the sum of the sizes of candies that the other player ate on the previous move. If there are not enough candies to make a move this way, then the player eats up all the remaining candies and the game ends.For example, if $$$n=11$$$ and $$$a=[3,1,4,1,5,9,2,6,5,3,5]$$$, then:  move 1: Alice eats one candy of size $$$3$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3,5]$$$.  move 2: Alice ate $$$3$$$ on the previous move, which means Bob must eat $$$4$$$ or more. Bob eats one candy of size $$$5$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3]$$$.  move 3: Bob ate $$$5$$$ on the previous move, which means Alice must eat $$$6$$$ or more. Alice eats three candies with the total size of $$$1+4+1=6$$$ and the sequence of candies becomes $$$[5,9,2,6,5,3]$$$.  move 4: Alice ate $$$6$$$ on the previous move, which means Bob must eat $$$7$$$ or more. Bob eats two candies with the total size of $$$3+5=8$$$ and the sequence of candies becomes $$$[5,9,2,6]$$$.  move 5: Bob ate $$$8$$$ on the previous move, which means Alice must eat $$$9$$$ or more. Alice eats two candies with the total size of $$$5+9=14$$$ and the sequence of candies becomes $$$[2,6]$$$.  move 6 (the last): Alice ate $$$14$$$ on the previous move, which means Bob must eat $$$15$$$ or more. It is impossible, so Bob eats the two remaining candies and the game ends. Print the number of moves in the game and two numbers:  $$$a$$$ — the total size of all sweets eaten by Alice during the game;  $$$b$$$ — the total size of all sweets eaten by Bob during the game.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases in the input. The following are descriptions of the $$$t$$$ test cases. Each test case consists of two lines. The first line contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of candies. The second line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$) — the sizes of candies in the order they are arranged from left to right. It is guaranteed that the sum of the values of $$$n$$$ for all sets of input data in a test does not exceed $$$2\cdot10^5$$$.

For each set of input data print three integers — the number of moves in the game and the required values $$$a$$$ and $$$b$$$.

let input = require('fs')
    .readFileSync(0, 'ascii')
    .split('\n')
    .filter(line => !/^\s*$/.test(line))
    .map(l => l.split(' ').map(w => parseInt(w)));

let [t, ...tests] = input;

for (let i = 0; i < t; i++) {
    const n = tests[2*i];
    const a = tests[2*i + 1];
    let l = 0;
    let r = n - 1;
    let ra = 0;
    let rb = 0;
    let moves = 0;
    let previous_size = 0;
    while (l <= r) {
	if (l <= r) {
	    let current_size = 0;
	    while (l <= r && current_size <= previous_size) {
		current_size += a[l];
		l++;
	    }
	    ra += current_size;
	    previous_size = current_size;
	    moves++;
	}
	if (l <= r) {
	    let current_size = 0;
	    while (l <= r && current_size <= previous_size) {
		current_size += a[r];
		r--;
	    }
	    rb += current_size;
	    previous_size = current_size;
	    moves++;
	}
    }
    console.log(moves, ra, rb)
}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i < t; i++) {
        const n = parseInt(readLine(), 10);
        const seq = readLine().split(' ').map(x => parseInt(x));
        let moves = 1, a = seq[0], b = 0;
        let li = 1, i = seq.length - 1, ri = i, eatenInPrevMove = a;
        let isAlicesTurn = false;
        while (i >= 1 && li - ri < 1) {
            let eatenTillNow = 0;
            if (isAlicesTurn) {
                while (li - ri < 1) {
                    eatenTillNow += seq[li];
                    li++;
                    if (eatenTillNow>eatenInPrevMove) break;
                }
                a += eatenTillNow;
            } else {
                while (li - ri < 1) {
                    eatenTillNow += seq[ri];
                    ri--;
                    if (eatenTillNow>eatenInPrevMove) break;
                }
                b += eatenTillNow;
            }
            moves++;
            isAlicesTurn = !isAlicesTurn;
            eatenInPrevMove = eatenTillNow;
        }
        console.log([moves, a, b].join(" "));

    }
    return;
}

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}
function Main(){
        var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray();
		var turn = true;
		var alice = 0;
		var bob = 0;
		var mae = 0;
		var now = 0;
		var move = 0;
		while(list.length > 0){
			if(turn){
				turn = false;
				while(now <= mae && list.length > 0){
					now += list.shift();
				}
				alice += now;
				mae = now;
			}else{
				turn = true;
				while(now <= mae && list.length > 0){
					now += list.pop();
				}
				bob += now;
				mae = now;
			}
			now = 0;
			move++;
		}
		output[i] = move + " " + alice + " " + bob;
	}
	myout(myconv(output,9));
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (arr) {
        let sic = 0;
        let aW = 0;
        let aL = 0;
        let bW = 0;
        let bL = 0;
        while (arr.length) {
            let sicW = 0;
            if (!(sic % 2)) {
                do {
                    sicW += arr.shift();
                } while (sicW <= bL && arr.length);
                aL = sicW;
                aW += sicW;
            } else {
                do {
                    sicW += arr.pop();
                } while (sicW <= aL && arr.length);
                bL = sicW;
                bW += sicW;
            }
            sic++;
        }
        return [sic, aW, bW].join(' ');
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount * 2].split(" ").map(Number);
        let result = foo(data);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

const processData = (lines) => {
  const num = +lines[0]
  for (let i=0; i<num; i++) {
    const n = +lines[i*2+1]
    const arr = lines[i*2 + 2].split(' ').map(x => +x)

    let aSum = 0
    let bSum = 0
    let a = 0
    let b = 0
    let start = 0
    let end = arr.length - 1
    let cur = 0
    let step = 0
    while (start <= end) {
      if (cur === 0 ) {
        a = 0
        while (start <= end && a <= b) {
          a += arr[start]
          start++
        }
        aSum += a
      } else {
        b = 0
        while (start <= end && b <= a) {
          // console.log('b', end)
          b += arr[end]
          end--
        }

        bSum += b
      }
      cur = (cur + 1) %2
      step++
    }
    console.log(step, aSum, bSum)
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

'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.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n, a) {
  let steps = 0;
  let sumA = 0;
  let sumB = 0;
  let isA = true;
  let lastStep = 0;
  let i = 0;
  let j = n - 1;
  while (i <= j) {
    let curSum = 0;
    if (isA) {
      while (curSum === 0 || (curSum <= lastStep && i <= j)) {
        curSum += a[i];
        i++;
      }
      sumA += curSum;
      isA = false;
    } else {
      while (curSum === 0 || (curSum <= lastStep && i <= j)) {
        curSum += a[j];
        j--;
      }
      sumB += curSum;
      isA = true;
    }
    lastStep = curSum;
    steps++;
  }
  return [steps, sumA, sumB];
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n, a);
    console.log(res.join(' '));
  }
  //process.stdout.write("hello: ");
}

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

var input  = []
rl.on('line', function(line){
    input.push(line);
})

rl.on("close", ContestResponse);

function ContestResponse(){
    let index = 0;
    let nCases = +input[index++];
    for (let i = 0; i < nCases; i++){
      index++;
      let arr = input[index++].split(" ").map((val) => +val);
      let prev = 0;
      let currPrev = 0;
      let alice = 0;
      let aliceIndex = 0;
      let bob = 0
      let bobIndex = arr.length - 1;
      let moves = 0;
      let turn = 0;
      let un = false;
      while (aliceIndex <= bobIndex){
        un = false;
        if (turn === 0){
          alice += arr[aliceIndex];
          if (currPrev + arr[aliceIndex] > prev){
            prev = currPrev + arr[aliceIndex];
            currPrev = 0;
            turn = 1;
            aliceIndex++;
            moves++;
          }
          else {
            currPrev += arr[aliceIndex];
            aliceIndex++;
            un = true;
          }
        }
        else{
          bob += arr[bobIndex];
          if (currPrev + arr[bobIndex] > prev){
            turn = 0;
            prev = currPrev + arr[bobIndex];
            currPrev = 0;
            bobIndex--;
            moves++;
          }
          else {
            currPrev += arr[bobIndex]
            bobIndex--;
            un = true;
          }
        }
      }
      if (un)
        moves++
      console.log(moves, alice, bob);
    }
}

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

var input  = []
rl.on('line', function(line){
    input.push(line);
})

rl.on("close", ContestResponse);

function ContestResponse(){
    let index = 0;
    let nCases = +input[index++];
    for (let i = 0; i < nCases; i++){
      index++;
      let arr = input[index++].split(" ").map((val) => +val);
      let prev = 0;
      let alicePrev = 0;
      let alice = 0;
      let aliceIndex = 0;
      let bobPrev = 0;
      let bob = 0
      let bobIndex = arr.length - 1;
      let moves = 0;
      let turn = 0;
      let un = false;
      while (aliceIndex <= bobIndex){
        if (turn === 0){
          //console.log("-----ALICE")
          if (alicePrev + arr[aliceIndex] > prev){
            //console.log(arr[aliceIndex])
            turn = 1;
            alice += arr[aliceIndex];
            alicePrev += arr[aliceIndex];
            aliceIndex++;
            moves++;
            prev = alicePrev;
            alicePrev = 0;
            un = false;
          }
          else {
            //console.log(arr[aliceIndex])
            alice += arr[aliceIndex];
            alicePrev += arr[aliceIndex];
            aliceIndex++;
            un = true;
          }
        }
        else{
          //console.log("-----BOB")
          if (bobPrev + arr[bobIndex] > prev){
            //console.log(arr[bobIndex])
            un = false;
            turn = 0;
            bob += arr[bobIndex];
            bobPrev += arr[bobIndex]
            prev = bobPrev;
            bobPrev = 0;
            bobIndex--;
            moves++;
          }
          else {
            //console.log(arr[bobIndex])
            bob += arr[bobIndex];
            bobPrev += arr[bobIndex]
            bobIndex--;
            un = true;
          }
        }
      }
      if (un)
        moves++
      console.log(moves, alice, bob);
    }
}

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

var input  = []
rl.on('line', function(line){
    input.push(line);
})

rl.on("close", ContestResponse);

function ContestResponse(){
    let index = 0;
    let nCases = +input[index++];
    for (let i = 0; i < nCases; i++){
      index++;
      let arr = input[index++].split(" ").map((val) => +val);
      let alice = 0;
      let aliceIndex = 0;
      let alicePrev = 0;
      let bob = 0;
      let bobPrev = 0;
      let bobIndex = arr.length - 1;
      let moves = 0;
      while (aliceIndex <= bobIndex){
        moves++;
        if (moves & 1){
          for (alicePrev = 0; aliceIndex <= bobIndex && alicePrev <= bobPrev; aliceIndex++)
            alicePrev += arr[aliceIndex];
            alice += alicePrev;
        }
        else {
          for (bobPrev = 0; aliceIndex <= bobIndex && bobPrev <= alicePrev; bobIndex--)
            bobPrev += arr[bobIndex];
            bob += bobPrev;
        }
      }
      console.log(moves, alice, bob);
    }
}

'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {

    let cases = parseInt(readline(), 10);
    for (var X = 0; X < cases; X++) {
      readline();
      let candies = readline().split(" ").map(e => parseInt(e));

      let eated = [0, 0];
      let previousEating = 0;
      let turn = 0
      let count = 0;

      while (candies.length > 0) {

        let currentEating = 0;
        //console.log('start turn', turn)
        //console.log(JSON.stringify(candies));

        while (candies.length > 0 && currentEating <= previousEating) {
          currentEating += (turn == 0) ? candies.shift() : candies.pop();
          //console.log('eating', currentEating);
        }

        if (currentEating > previousEating) {
          eated[turn] += currentEating;
        } else {
          //turn = turn === 0 ? 1 : 0;
          eated[turn] += currentEating;
        }

        turn = turn === 0 ? 1 : 0;
        previousEating = currentEating;
        count++;
      }

      console.log(`${count} ${eated[0]} ${eated[1]}`)
      // console.log(`----`)

    }

}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    caseN();
  }
}

function caseN() {
  var num = +readline();
  var cds = readNumArray();
  var aInd = 0;
  var bInd = num - 1;
  var numA = 0;
  var numB = 0;
  var currV = 0;
  var steps = 0;
  while (aInd <= bInd) {
    steps++;
    var currA = 0;
    var currB = 0;
    while (currA <= currV) {
      currA += cds[aInd];
      numA += cds[aInd];
      aInd++;
      if (aInd > bInd) {
        print(steps + " " + numA + " " + numB);
        return;
      }
    }
    currV = currA;
    steps++;
    while (currB <= currV) {
      currB += cds[bInd];
      numB += cds[bInd];
      bInd--;
      if (aInd > bInd) {
        print(steps + " " + numA + " " + numB);
        return;
      }
    }
    currV = currB;
  }
}
main()

function solve() {
    var n = readInt()
    var arr = readIntArray()

    var numSteps = 0
    var aTotal = 0
    var bTotal = 0
    var lastTotal = 0
    var turnTotal = 0
    var curPlayerIsA = true
    var aIndex = 0
    var bIndex = n
    while(aIndex < bIndex) {
        if (curPlayerIsA) {
            aTotal += arr[aIndex]
            turnTotal += arr[aIndex]
            if(turnTotal > lastTotal) {
                curPlayerIsA = false
                lastTotal = turnTotal
                turnTotal = 0
                numSteps += 1
                bIndex -= 1
            } else {
                aIndex += 1
            }
        } else {
            bTotal += arr[bIndex]
            turnTotal += arr[bIndex]
            if(turnTotal > lastTotal) {
                curPlayerIsA = true
                lastTotal = turnTotal
                turnTotal = 0
                numSteps += 1
                aIndex += 1
            } else {
                bIndex -= 1
            }
        }
    }

    if (turnTotal > 0) {
        numSteps += 1
    }

    print(`${numSteps} ${aTotal} ${bTotal}`)
}

var testCases = readInt();
var testCaseNum;
for(testCaseNum=0; testCaseNum<testCases; testCaseNum++) {
  solve()
}

function readIntArray() {
    return readline().split(" ").map(function(x) { return parseInt(x); });
}

function readInt() {
    return parseInt(readline())
}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i < t; i++) {
        const n = parseInt(readLine(), 10);
        const seq = readLine().split(' ').map(x => parseInt(x));
        let moves = 1, a = seq[0], b = 0;
        let li = 1, i = seq.length - 1, ri = i, eatenInPrevMove = a;
        let isAlicesTurn = false;
        while (i > 1 && li + (i - ri) <= i) {
            let eatenTillNow = 0;
            if (isAlicesTurn) {
                while ((li + i - ri) <= i) {
                    eatenTillNow += seq[li];
                    li++;
                    if (eatenTillNow>eatenInPrevMove) break;
                }
                a += eatenTillNow;
            } else {
                while ((li + i - ri) <= i) {
                    eatenTillNow += seq[ri];
                    ri--;
                    if (eatenTillNow>eatenInPrevMove) break;
                }
                b += eatenTillNow;
            }
            moves++;
            isAlicesTurn = !isAlicesTurn;
            eatenInPrevMove = eatenTillNow;
        }
        console.log([moves, a, b].join(" "));

    }
    return;
}


Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters. Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2·d, ..., n·d meters.

The first line contains two space-separated real numbers a and d (1 ≤ a, d ≤ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink. The second line contains integer n (1 ≤ n ≤ 105) showing that Valera needs an extra drink n times.

Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers i·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4. Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.

print(function(a, d) {
	var n = +readline();
	var ans = [];
	for (var i = 1; i <= n; i++) {
		var x = (i * d) % (a * 4);
		if (x <= a) {
			ans.push(x + ' 0');
		} else if (x <= 2 * a) {
			ans.push(a + ' ' + (x - a))
		} else if (x <= 3 * a) {
			ans.push((3 * a - x) + ' ' + a)
		} else {
			ans.push('0 ' + (4 * a - x))
		}
	}
	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeFloats(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseFloat(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var factor = 100*100,
		data = tokenizeFloats(readline()),
		side = factor*data[0], drink = factor*data[1],
		numDrinks = parseInt(readline());
	var parts = [], pos = 0, lap = 4*side;
	for (var i = 0; i < numDrinks; ++i) {
		pos = (pos + drink) % lap;
		if (pos < side) {
			var x = pos, y = 0;
		} else if (pos < 2*side) {
			var x = side, y = pos - side;
		} else if (pos < 3*side) {
			var x = 3*side - pos, y = side;
		} else {
			var x = 0, y = lap - pos;
		}
		parts.push(x/factor);
		parts.push(' ');
		parts.push(y/factor);
		parts.push('\n');
	}
	parts.pop();
	print(parts.join(''));
}

main();


Let's call two strings $$$s$$$ and $$$t$$$ anagrams of each other if it is possible to rearrange symbols in the string $$$s$$$ to get a string, equal to $$$t$$$.Let's consider two strings $$$s$$$ and $$$t$$$ which are anagrams of each other. We say that $$$t$$$ is a reducible anagram of $$$s$$$ if there exists an integer $$$k \ge 2$$$ and $$$2k$$$ non-empty strings $$$s_1, t_1, s_2, t_2, \dots, s_k, t_k$$$ that satisfy the following conditions:  If we write the strings $$$s_1, s_2, \dots, s_k$$$ in order, the resulting string will be equal to $$$s$$$;  If we write the strings $$$t_1, t_2, \dots, t_k$$$ in order, the resulting string will be equal to $$$t$$$;  For all integers $$$i$$$ between $$$1$$$ and $$$k$$$ inclusive, $$$s_i$$$ and $$$t_i$$$ are anagrams of each other. If such strings don't exist, then $$$t$$$ is said to be an irreducible anagram of $$$s$$$. Note that these notions are only defined when $$$s$$$ and $$$t$$$ are anagrams of each other.For example, consider the string $$$s = $$$ "gamegame". Then the string $$$t = $$$ "megamage" is a reducible anagram of $$$s$$$, we may choose for example $$$s_1 = $$$ "game", $$$s_2 = $$$ "gam", $$$s_3 = $$$ "e" and $$$t_1 = $$$ "mega", $$$t_2 = $$$ "mag", $$$t_3 = $$$ "e":  On the other hand, we can prove that $$$t = $$$ "memegaga" is an irreducible anagram of $$$s$$$.You will be given a string $$$s$$$ and $$$q$$$ queries, represented by two integers $$$1 \le l \le r \le |s|$$$ (where $$$|s|$$$ is equal to the length of the string $$$s$$$). For each query, you should find if the substring of $$$s$$$ formed by characters from the $$$l$$$-th to the $$$r$$$-th has at least one irreducible anagram.

The first line contains a string $$$s$$$, consisting of lowercase English characters ($$$1 \le |s| \le 2 \cdot 10^5$$$). The second line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$)  — the number of queries. Each of the following $$$q$$$ lines contain two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le |s|$$$), representing a query for the substring of $$$s$$$ formed by characters from the $$$l$$$-th to the $$$r$$$-th.

For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise.

NoteIn the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose $$$s_1 = $$$ "a", $$$s_2 = $$$ "aa", $$$t_1 = $$$ "a", $$$t_2 = $$$ "aa" to show that it is a reducible anagram.In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/

function main(input) {
    s=" "+input[0]
    n=s.length-1
    q=+input[1]
    dp=new Array(26)
    for (var i=0;i<26;i++){
        dp[i]=new Array(n+1)
        for (var j=0;j<=n;j++){
            dp[i][j]=0
        }
    }
    for (var i=1;i<=n;i++){
        for (var j=0;j<26;j++){
            dp[j][i]=dp[j][i-1]
        }
        var w=s.charCodeAt(i)-'a'.charCodeAt(0)
        ++dp[w][i]
    }

    for (var t=2;t<=q+1;t++){
        a=input[t].split(' ')
        l=+a[0]
        r=+a[1]
        if (l==r){
            wr("Yes")
        } else {
            if (s[l]!=s[r]){
                wr("Yes")
            } else {
                var cnt=0
                for (var j=0;j<26;j++){
                    if (dp[j][r]>dp[j][l-1]){
                        ++cnt
                    }
                }
                if (cnt>2){
                    wr("Yes")
                } else {
                    wr("No")
                }
            }
        }
    }

}


Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ digits and doesn't contain any leading zeroes.

Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.

NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var line = 0;
var n, k;
var S;

rl.on('line', (data) => {
	++line;

	var arr = data.split(' ');

	if(line===1) {
		n = parseInt(arr[0]);
		k = parseInt(arr[1]);
	} else {
		S = arr[0];
		var array = S;
		var result = '';
//		console.log(array)

		if(k===0) {
			console.log(S);
		} else if(n===1){
			console.log(0);
		} else {
			var idx=1;
			if(array[0]!=='1'){
				--k;
			}
			result+='1';
			for(; idx<n; idx++) {
				if(k===0) {
//					console.log('K is zero for',array[idx]);
					for(var jj=idx; jj<n; jj++) {
						result+=array[jj];
//							console.log('Added',array[jj])
					}
					idx=n;
					break;
				}

				if(array[idx]==='0') {
					result+=0;
				}else {
//					console.log('Decrement for',array[idx],'K is',k-1);
					--k;
					result+=0;
				}

//				console.log(k+1,'ADDED',array[idx])
			}
			console.log(result);
		}
		line=0;
	}
});

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const ax = arr.shift().split(' ')
  const s = arr.shift()
  const n = parseInt(ax[0])
  const k = parseInt(ax[1])
  let s2 = ''
  if(n == 1) {
    if(k == 1) console.log('0')
    else console.log(s)
  }
  else {
    for(let i = 0, no = 0; no < k && i < n; i++) {
      if(i == 0) s2 += 1
      else {
        s2 += 0
      }
      if(i == 0 && s[0] != 1) no ++
      else if(i !=0 && s[i] != 0) no ++
    }
    s2 += s.substr(s2.length)
    console.log(s2)

  }
})

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', sol);

function sol() {
  let [n, k, S] = input
    .replace('\n', ' ')
    .split(' ')
  n = Number(n)
  k = Number(k)
  S = Array.from(S)

  for (let i = 0; i < n && k > 0; ++i) {
    if (i === 0 && i !== n-1) {
      if (S[i] !== '1') {
        S[i] = '1'
        --k
      }
    } else {
      if (S[i] !== '0') {
        S[i] = '0'
        --k
      }
    }
  }

  process.stdout.write(
    S.join(''),
    'utf8',
    () => process.stdout.end()
  );
}

let lines = '';
process.stdin.on('data', c => lines += c);

const solution = () => {
	let line = lines.split('\n');
	let [n, k] = line[0].split(' ').map(v => parseInt(v,10));
	let s = line[1];
	let r = '';
	for(let i = 0; i < n; i++){
		let c = s[i];
		 if (i === 0 && n == 1 && k > 0) {
			r += 0;
			k--;
		}else if (i === 0 && c > 1 && k > 0) {
			r += 1;
			k--;
		} else if (i !== 0 && c > 0 && k > 0) {
			r += 0;
			k--;
		} else {
			r += c;
		}
	}

	console.log(r);
	process.exit(0);
}

process.stdin.on('end', solution);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(n == 1 && k) {
    ans += 0;
} else
if(str[0] != 1 && k) {
    -- k;
    ans += 1;
} else ans += str[0];

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
}

print(ans);

'use strict'

const fn = (k, x) => {
    if (x.length === 1 && k >= 1) return '0';
    if (k === 0) return x;
    let K = 0;
    if (x[0] !== '1') { k--; }

    while(k && K++ < x.length) {
        if (x[K] !== '0') k--;
    }
    const z = Math.min(K, x.length - 1);
    return '1' + '0'.repeat(z) + x.slice(z + 1)
}

write(fn(parseInt(readline().split(' ')[1]), readline()));

var str = readline().split(" ");
var steps = +str[1];
var nums = str[0];
var numbers = readline().split("");
var i = 0;
while (steps && i < numbers.length){
    if (numbers.length == 1){
        numbers[0] = 0;
        break;
    }
    if (i == 0 && numbers[i] != 1){
        numbers[0] = 1;
        steps--;

    } else if( i>0 && numbers[i] != 0) {
        numbers[i] = 0;
        steps--;

    }
    i++;
}
write(numbers.join(""));

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var line = 0;
var n, k;
var S;

rl.on('line', (data) => {
	++line;

	var arr = data.split(' ');

	if(line===1) {
		n = parseInt(arr[0]);
		k = parseInt(arr[1]);
	} else {
		S = parseInt(arr[0]);
		var result = '';
		var array = Array.from(String(S), Number);

		if(k===0) {
			console.log(S);
		} else if(n===1){
			console.log(0);
		} else {
			var idx=1;
			if(array[0]!==1){
				--k;
			}
			result+='1';
			for(; idx<n; idx++) {
				if(array[idx]===0) {
					result+=0;
				}else {
					--k;
					result+=0;
					if(k===0) {
						for(var jj=idx+1; jj<n; jj++) {
							result+=array[jj];
						}
						idx=n;
					}
				}
			}
			console.log(result);
		}
		line=0;
	}
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var line = 0;
var n, k;
var S;

rl.on('line', (data) => {
	++line;
	var arr = data.split(' ');
	if(line===1) {
		n = parseInt(arr[0]);
		k = parseInt(arr[1]);
	} else {
		S = arr[0];
		var array = S;
		var result = '';

		if(k===0) {
			console.log(S);
		} else if(n===1){
			console.log(0);
		} else {
			var idx=1;
			if(array[0]!=='1'){
				--k;
			}
			result+='1';
			for(; idx<n; idx++) {
				if(array[idx]==='0') {
					result+='0';
				}else {
					--k;
					result+=0;
				}
				if(k===0) {
					for(var jj=idx+1; jj<n; jj++) {
						result+=array[jj];
					}
					idx=n;
				}
			}
			console.log(result);
		}
		line=0;
	}
});

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const ax = arr.shift().split(' ')
  const s = arr.shift()
  const n = parseInt(ax[0])
  const k = parseInt(ax[1])
  let s2 = ''
  if(n == 1) {
    console.log('0')
  }
  else {
    for(let i = 0, no = 0; no < k && i < n; i++) {
      if(i == 0) s2 += 1
      else {
        s2 += 0
      }
      if(i == 0 && s[0] != 1) no ++
      else if(s[i] != 0) no ++
    }
    s2 += s.substr(s2.length)
    console.log(s2)

  }
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const ax = arr.shift().split(' ')
  const s = arr.shift()
  const n = parseInt(ax[0])
  const k = parseInt(ax[1])
  let s2 = ''
  for(let i = 0, no = 0; no < k; i++) {
    if(i == 0) s2 += 1
    else {
      s2 += 0
    }
    if(s[i] != 1 || s.length == 1) no ++
  }
  s2 += s.substr(s2.length)

  if(s2.length > 1) console.log(s2)
  else console.log('0')
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const ax = arr.shift().split(' ')
  const s = arr.shift()
  const n = parseInt(ax[0])
  const k = parseInt(ax[1])
  let s2 = ''
  if(n == 1) {
    console.log('0')
  }
  else {
    for(let i = 0, no = 0; no < k && i < n; i++) {
      if(i == 0) s2 += 1
      else {
        s2 += 0
      }
      if(s[0] != 1) no ++
      else if(s[i] != 0) no ++
    }
    s2 += s.substr(s2.length)
    console.log(s2)

  }
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const ax = arr.shift().split(' ')
  const s = arr.shift()
  const n = parseInt(ax[0])
  const k = parseInt(ax[1])
  let s2 = ''
  if(n == 1) {
    if(k == 1) console.log('0')
    else console.log(s)
  }
  else {
    for(let i = 0, no = 0; no < k && i < n; i++) {
      if(i == 0) s2 += 1
      else {
        s2 += 0
      }
      if(i == 0 && s[0] != 1) no ++
      else if(s[i] != 0) no ++
    }
    s2 += s.substr(s2.length)
    console.log(s2)

  }
})

let lines = '';
process.stdin.on('data', c => lines += c);

const solution = () => {
	let line = lines.split('\n');
	let [n, k] = line[0].split(' ').map(v => parseInt(v,10));
	let s = line[1];
	let r = '';
	for(let i = 0; i < n; i++){
		let c = s[i];
		if (i === 0 && c > 1 && k > 0) {
			r += 1;
			k--;
		} else if (i === 0 && n == 1 && k > 0) {
			r += 0;
			k--;
		} else if (i !== 0 && c > 0 && k > 0) {
			r += 0;
			k--;
		} else {
			r += c;
		}
	}

	console.log(r);
	process.exit(0);
}

process.stdin.on('end', solution);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(str[0] != 1 && k) {
    -- k;
    ans += 1;
} else ans += str[0];

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
}

print(ans);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(str[0] != 1 && k) {
    -- k;
    ans += 1;
}

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
    -- k;
}

print(ans);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(str[0] != 1 && k) {
    if(n == 1) {
        ans += 0;
    } else {
        -- k;
        ans += 1;
    }
} else ans += str[0];

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
}

print(ans);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(str[0] != 1 && k) {
    -- k;
    ans += 1;
}

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
}

print(ans);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(str[0] != '1' && k) {
    -- k;
    ans += 1;
}

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
    -- k;
}

print(ans);

'use strict'

let data = readline().split(' ');

let n = parseInt(data[0]), k = parseInt(data[1]);

let str = readline(), ans = "";

if(str[0] != 1 && k) {
    -- k;
    ans += 1;
} else ans += str[0];

for (let i = 1; i < n; ++ i) {
    if(!k || str[i] == '0') {
        ans += str[i];
    } else {
        -- k;
        ans += 0;
    }
    -- k;
}

print(ans);

var str = readline().split(" ");
var steps = +str[1];
var nums = str[0];
var numbers = readline().split("");
var i = 0;
while (steps){
    if (i){
        numbers[i] = 0;
        steps--;
    } else if (numbers[i] != 1){
        numbers[i] = 1;
        steps--;
    } else if (numbers.length == 1){
        numbers[0] = 0;
        steps--;
    }

    i++;
}
write(numbers.join(""));


Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:You are given an array $$$a$$$ of $$$n$$$ integers. You are also given an integer $$$k$$$. Lord Omkar wants you to do $$$k$$$ operations with this array.Define one operation as the following:   Set $$$d$$$ to be the maximum value of your array.  For every $$$i$$$ from $$$1$$$ to $$$n$$$, replace $$$a_{i}$$$ with $$$d-a_{i}$$$. The goal is to predict the contents in the array after $$$k$$$ operations. Please help Ray determine what the final sequence will look like!

Each test contains multiple test cases. The first line contains the number of cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5, 1 \leq k \leq 10^{18}$$$) – the length of your array and the number of operations to perform. The second line of each test case contains $$$n$$$ integers $$$a_{1},a_{2},...,a_{n}$$$ $$$(-10^9 \leq a_{i} \leq 10^9)$$$ – the initial contents of your array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each case, print the final version of array $$$a$$$ after $$$k$$$ operations described above.

NoteIn the first test case the array changes as follows:Initially, the array is $$$[-199, 192]$$$. $$$d = 192$$$.After the operation, the array becomes $$$[d-(-199), d-192] = [391, 0]$$$.

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, time] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    let max = Math.max(...arr);
    const store = [];
    for (let i = 0; i < arr.length; i++) {
      arr[i] = max - arr[i];
    }

    store.push(arr);
    max = Math.max(...arr);
    const _arr = [...arr];
    for (let i = 0; i < _arr.length; i++) {
      _arr[i] = max - _arr[i];
    }
    store.push(_arr);

    if ((time - 1) % 2 === 0) {
      console.log(store[0].join(" "));
    } else {
      console.log(store[1].join(" "));
    }
  }
}

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 main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
	const [nStr, kStr] = readLine().split(/\s/)
    const n = Number(nStr)
    const k = BigInt(kStr)
    const as = readLine().split(/\s/).map(Number)
    const max = Math.max.apply(null, as)
    const as1 = as.map(a => max - a)
    if (k % 2n === 1n) {
      console.log(as1.join(' '))
      continue
    }
    const max1 = Math.max.apply(null, as1)
    console.log(as1.map(a => max1 - a).join(' '))
  }
}

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

function readDOM(pos) {
    const inputList = document.querySelectorAll(".input");
    const input = inputList[pos];
    return input.querySelector("pre").textContent;
}

let CONFIG = {
    // getStringFunc: readDOM.bind(null, 0)
}

stdioCPPattern(CONFIG, ({ readNum, readStr, writeLine, readCharArray }) => {
    // your code goes here
    let tc_count = readNum();
    let n, kOper, dmax, arr;

    const convert = x => dmax - x;
    function maxForBigInt(...args) {
        return args.reduce((a, b) => a > b ? a : b);
    };

    while (tc_count--) {
        [n, kOper] = [Number(readNum()), readNum()];
        arr = new BigInt64Array(n).map(readNum);
        //writeLine(`[${arr}]`);

        dmax = maxForBigInt(...arr);
        arr = arr.map(convert);

        if ((kOper & 1n) === 0n) {
            dmax = maxForBigInt(...arr);
            arr = arr.map(convert);
        }
        writeLine( arr.join(" "));
    }
});

/**
 * @author flynn
 */
function stdinReadAll() {
    const fs = require("fs");
    return fs.readFileSync(0).toString();
}

function stdioCPPattern({
    getStringFunc = stdinReadAll
}, callbackfn) {
    const aStr = getStringFunc() + "\n";

    let cur = -1;
    const resultList = [];// Array(numberOfLine);
    const seperator = /\s/;
    const MINUS_CODE = -3n;

    callbackfn({
        readCharArray,
        log: console.log,
        readNum() {
            let x = 0n, sign = 1n, ch = nextDigit();
            while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();

            if (ch === MINUS_CODE) { sign = -1n; ch = nextDigit(); }

            while (0 <= ch && ch <= 9) {
                x = x * 10n + ch;
                ch = nextDigit();
            }
            return x * sign;
        },
        writeLine(data) {
            resultList.push(`${data}`);
        },
        readStr(bufferLen = 1e6) {
            return readCharArray(bufferLen).join("");
        }
    });
    let prompt = resultList.join("\n");
    if (prompt) console.log(prompt);

    function nextDigit() {
        return BigInt(aStr.charCodeAt(++cur) - 48);
    }

    function readCharArray(bufferLen = 1e6) {
        const chArr = Array(bufferLen);
        let ch = aStr[++cur], p = 0;
        while (seperator.test(ch))
            ch = aStr[++cur];
        while (!seperator.test(ch)) {
            chArr[p++] = ch;
            ch = aStr[++cur];
        }
        return chArr.slice(0, p);
    }
}

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() >> 0;
	while (t--) {
		let [n, k] = readLine().split(' ');

		n = n >> 0;
		k = BigInt(k);

		let arr = readLine()
			.split(' ')
			.map(x => x >> 0);

		k = k & 1n ? 1 : 2;
		for (let i = 0; i < k; i++) {
			let d = Math.max(...arr);
			for (let j = 0; j < n; j++) {
				arr[j] = d - arr[j];
			}
		}
		console.log(arr.join(' '));
	}
}

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 main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
	const [n, k] = readLine().split(/\s/).map(Number)
    const as = readLine().split(/\s/).map(Number)
    const max = Math.max.apply(null, as)
    const as1 = as.map(a => max - a)
    if (k % 2 === 1) {
      console.log(as1.join(' '))
      continue
    }
    const max1 = Math.max.apply(null, as1)
    console.log(as1.map(a => max1 - a).join(' '))
  }
}

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

function readDOM() {
    const inputList = document.querySelectorAll(".input");
    const input = inputList[2];
    return input.querySelector("pre").textContent;
}

stdioCPPattern({}, ({ readNum, readStr, writeLine, readCharArray }) => {
    // your code goes here
    let tc_count = readNum();
    let n, kOper, dmax, arr;

    const convert = x => dmax - x;

    while (tc_count--) {
        [n, kOper] = [readNum(), readNum()];
        arr = new Int32Array(n).map(readNum);

        dmax = Math.max(...arr);
        arr = arr.map(convert);

        if ((kOper & 1) === 0) {
            dmax = Math.max(...arr);
            arr = arr.map(convert);
        }
        writeLine( arr.join(" "));
    }
});

/**
 * @author flynn
 */
function stdinReadAll() {
    const fs = require("fs");
    return fs.readFileSync(0).toString();
}

function stdioCPPattern({
    getStringFunc = stdinReadAll
}, callbackfn) {
    const aStr = getStringFunc() + "\n";

    let cur = 0;
    const resultList = [];// Array(numberOfLine);
    const seperator = /\s/;
    const MINUS_CODE = -3;

    callbackfn({
        readCharArray,
        log: console.log,
        readNum() {
            let x = 0, sign = 1, ch = aStr.charCodeAt(cur) - 48;
            while (ch !== MINUS_CODE && (ch < 0 || 9 < ch)) ch = nextDigit();

            if (ch === MINUS_CODE) { sign = -1; ch = nextDigit(); }

            while (0 <= ch && ch <= 9) {
                x = x * 10 + ch;
                ch = nextDigit();
            }
            return x * sign;
        },
        writeLine(data) {
            resultList.push(`${data}`);
        },
        readStr(bufferLen = 1e6) {
            return readCharArray(bufferLen).join("");
        }
    });
    let prompt = resultList.join("\n");
    if (prompt) console.log(prompt);

    function nextDigit() {
        return aStr.charCodeAt(++cur) - 48;
    }

    function readCharArray(bufferLen = 1e6) {
        const chArr = Array(bufferLen);
        let ch = aStr[cur], p = 0;
        while (seperator.test(ch))
            ch = aStr[++cur];
        while (!seperator.test(ch)) {
            chArr[p++] = ch;
            ch = aStr[++cur];
        }
        return chArr.slice(0, p);
    }
}


In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.Lesha knows that today he can study for at most $$$a$$$ hours, and he will have $$$b$$$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $$$k$$$ in $$$k$$$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.Thus, the student has to fully read several lecture notes today, spending at most $$$a$$$ hours in total, and fully read several lecture notes tomorrow, spending at most $$$b$$$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and which — in the second?

The only line of input contains two integers $$$a$$$ and $$$b$$$ ($$$0 \leq a, b \leq 10^{9}$$$) — the number of hours Lesha has today and the number of hours Lesha has tomorrow.

In the first line print a single integer $$$n$$$ ($$$0 \leq n \leq a$$$) — the number of lecture notes Lesha has to read in the first day. In the second line print $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq a$$$), the sum of all $$$p_i$$$ should not exceed $$$a$$$. In the third line print a single integer $$$m$$$ ($$$0 \leq m \leq b$$$) — the number of lecture notes Lesha has to read in the second day. In the fourth line print $$$m$$$ distinct integers $$$q_1, q_2, \ldots, q_m$$$ ($$$1 \leq q_i \leq b$$$), the sum of all $$$q_i$$$ should not exceed $$$b$$$. All integers $$$p_i$$$ and $$$q_i$$$ should be distinct. The sum $$$n + m$$$ should be largest possible.

NoteIn the first example Lesha can read the third note in $$$3$$$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $$$3$$$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.In the second example Lesha should read the third and the sixth notes in the first day, spending $$$9$$$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $$$12$$$ hours in total.

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

  let standardInputString= '';
  let currentLine = 0;

  function readLine(){
    return standardInputString[currentLine++];
  }
  process.stdin.on('data', rawData =>{
    standardInputString += rawData;
  });
  process.stdin.on('end', _ =>{
    standardInputString= standardInputString.trim().split('\n').map(line =>{
      return line.trim();
    });

    main();
  })

  function main(){

    let [a,b] = readLine().split(' ').map(Number);
    // let line = readLine().split(' ').map(Number);

      let hardestDay = a>=b ? a : b;
      let easiestDay = a<=b ? a : b;
      let sum = 0;

      let easierSum = 0;

      let hardDayArr = [];
      let easiestDayArr = [];

      let imposterNumber = 0;
      let didOnce = 1;

      let smallestStart = 1;

        for(let j = 1; j<=hardestDay; ++j){

          if(sum >= hardestDay){
           imposterNumber = sum - hardestDay;
           if(imposterNumber !== 0){
            hardDayArr.splice(imposterNumber-1,1);
           }
           smallestStart = j;
           break;
          }
          else{
            sum += j;
            hardDayArr.push(j);
          }
        }
        if(imposterNumber !== 0){
          easierSum = imposterNumber
          easiestDayArr.push(easierSum);
        }
        for(smallestStart; smallestStart<=easiestDay; ++smallestStart){

          easierSum += smallestStart;
          if(easierSum <= easiestDay){
            easiestDayArr.push(smallestStart);
          }
          else{
            break;
          }
        }
        let pera = hardDayArr.length !== 0 ? hardDayArr.reduce((a,b) => a +b) : 0;
        if( pera!== hardestDay){
          hardDayArr.splice((pera - hardestDay) - 1, 1);
        };
        if(easiestDay === 0){
          easiestDayArr = [];
        }
        else if( hardestDay === 0){
          hardDayArr = [];
        }

        if(hardestDay === 1&& easiestDay ===1){
          easiestDayArr = [];
        }
        if(a===hardestDay){
          console.log(hardDayArr.length);
          console.log(hardDayArr.reverse().join(" "));
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
        }
        else{
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
          console.log(hardDayArr.length);
          console.log(hardDayArr.reverse().join(" "));

        }
  }

var line = readline().split(' ');
var a = +line[0];
var b = +line[1];
var n = a+b;
var j = 0;
var firstDay = [];
var secondDay = [];
while (n - j -1 >= 0) {
    n -= ++j;
}
while ((j > 0) && (a+b > 0)) {
    if (a >= b) {
        a -= j--;
        firstDay.push(j+1);
    } else {
         b -= j--;
         secondDay.push(j+1);
    }
}
write(firstDay.length+'\n'+firstDay.reverse().join(' ')+'\n'+secondDay.length+'\n'+secondDay.reverse().join(' '));

var hours = readline().split(' ').map(v=>+v);
var shorterIndex = +(hours[0] > hours[1]);

var arr = hours[shorterIndex] = {
    nextIndex: 1 - shorterIndex,
    left: - hours[shorterIndex],
    values: []
}, nextObj;

for(var i = 1; true; i++) {
    arr.values.push(i);
    arr.left += i;

    if (arr.left > 0) {
        if (arr.nextIndex === undefined) {
            arr.values.pop();
            break;
        } else {
            arr.values.splice(arr.left - 1, 1)
            arr = nextObj = hours[arr.nextIndex] = {
                left: -hours[arr.nextIndex] + arr.left,
                values: [arr.left]
            };

            if(arr.left > 0) {
                arr.values.pop();
                break;
            }
        }
    }
}

hours.forEach(v => {
    print(v.values.length);
print(v.values.join(' '));
})

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

  let standardInputString= '';
  let currentLine = 0;

  function readLine(){
    return standardInputString[currentLine++];
  }
  process.stdin.on('data', rawData =>{
    standardInputString += rawData;
  });
  process.stdin.on('end', _ =>{
    standardInputString= standardInputString.trim().split('\n').map(line =>{
      return line.trim();
    });

    main();
  })

  function main(){
    let [a,b] = readLine().split(' ').map(Number);
    // let line = readLine().split(' ').map(Number);

      let hardestDay = a>=b ? a : b;
      let easiestDay = a<=b ? a : b;
      let sum = 0;

      let easierSum = 0;

      let hardDayArr = [];
      let easiestDayArr = [];

      let imposterNumber = 0;
      let didOnce = 1;

      let smallestStart = 1;

        for(let j = 1; j<=hardestDay; j++){

          if(sum >= hardestDay){
           imposterNumber = sum - hardestDay;
           if(imposterNumber !== 0){
            hardDayArr.splice(imposterNumber-1,1);
           }
          //  easierSum += imposterNumber + j;
           smallestStart = j;
           break;
          }
          else{
            sum += j;
            hardDayArr.push(j);
          }
        }
        if(imposterNumber !== 0){
          easierSum = imposterNumber
          easiestDayArr.push(easierSum);
        }
        for(smallestStart; smallestStart<=easiestDay; smallestStart++){

          easierSum += smallestStart;
          if(easierSum <= easiestDay){
            easiestDayArr.push(smallestStart);
          }
        }

        if(a===hardestDay){
          console.log(hardDayArr.length);
          console.log(hardDayArr.reverse().join(" "));
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
        }
        else{
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
          console.log(hardDayArr.length);
          console.log(hardDayArr.reverse().join(" "));

        }

  }

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

  let standardInputString= '';
  let currentLine = 0;

  function readLine(){
    return standardInputString[currentLine++];
  }
  process.stdin.on('data', rawData =>{
    standardInputString += rawData;
  });
  process.stdin.on('end', _ =>{
    standardInputString= standardInputString.trim().split('\n').map(line =>{
      return line.trim();
    });

    main();
  })

  function main(){
    let [a,b] = readLine().split(' ').map(Number);
    // let line = readLine().split(' ').map(Number);

      let hardestDay = a>=b ? a : b;
      let easiestDay = a<=b ? a : b;
      let sum = 0;

      let easierSum = 0;

      let hardDayArr = [];
      let easiestDayArr = [];

      let imposterNumber = 0;
      let didOnce = 1;

      let smallestStart = 1;

        for(let j = 1; j<=hardestDay; ++j){

          if(sum >= hardestDay){
           imposterNumber = sum - hardestDay;
           if(imposterNumber !== 0){
            hardDayArr.splice(imposterNumber-1,1);
           }
           smallestStart = j;
           break;
          }
          else{
            sum += j;
            hardDayArr.push(j);
          }
        }
        if(imposterNumber !== 0){
          easierSum = imposterNumber
          easiestDayArr.push(easierSum);
        }
        for(smallestStart; smallestStart<=easiestDay; ++smallestStart){

          easierSum += smallestStart;
          if(easierSum <= easiestDay){
            easiestDayArr.push(smallestStart);
          }
          else{
            break;
          }
        }
        let pera = hardDayArr.length !== 0 ? hardDayArr.reduce((a,b) => a +b) : 0;
        if( pera!== hardestDay){
          hardDayArr.splice((pera - hardestDay) - 1, 1);
        };
        if(a===hardestDay){
          console.log(hardDayArr.length);
          console.log(hardDayArr.join(" "));
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
        }
        else{
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
          console.log(hardDayArr.length);
          console.log(hardDayArr.join(" "));

        }
  }

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

  let standardInputString= '';
  let currentLine = 0;

  function readLine(){
    return standardInputString[currentLine++];
  }
  process.stdin.on('data', rawData =>{
    standardInputString += rawData;
  });
  process.stdin.on('end', _ =>{
    standardInputString= standardInputString.trim().split('\n').map(line =>{
      return line.trim();
    });

    main();
  })

  function main(){
    let [a,b] = readLine().split(' ').map(Number);
    // let line = readLine().split(' ').map(Number);

      let hardestDay = a>=b ? a : b;
      let easiestDay = a<=b ? a : b;
      let sum = 0;

      let easierSum = 0;

      let hardDayArr = [];
      let easiestDayArr = [];

      let imposterNumber = 0;
      let didOnce = 1;

      let smallestStart = 1;

        for(let j = 1; j<=hardestDay; ++j){

          if(sum >= hardestDay){
           imposterNumber = sum - hardestDay;
           if(imposterNumber !== 0){
            hardDayArr.splice(imposterNumber-1,1);
           }
           smallestStart = j;
           break;
          }
          else{
            sum += j;
            hardDayArr.push(j);
          }
        }
        if(imposterNumber !== 0){
          easierSum = imposterNumber
          easiestDayArr.push(easierSum);
        }
        for(smallestStart; smallestStart<=easiestDay; ++smallestStart){

          easierSum += smallestStart;
          if(easierSum <= easiestDay){
            easiestDayArr.push(smallestStart);
          }
          else{
            break;
          }
        }
        let pera = hardDayArr.length !== 0 ? hardDayArr.reduce((a,b) => a +b) : 0;
        if( pera!== hardestDay){
          hardDayArr.splice((pera - hardestDay) - 1, 1);
        };
        if(easiestDay === 0){
          easiestDayArr = [];
        }
        else if( hardestDay === 0){
          hardDayArr = [];
        }
        if(a===hardestDay){
          console.log(hardDayArr.length);
          console.log(hardDayArr.reverse().join(" "));
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
        }
        else{
          console.log(easiestDayArr.length);
          console.log(easiestDayArr.join(" "));
          console.log(hardDayArr.length);
          console.log(hardDayArr.reverse().join(" "));

        }
  }

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

  let standardInputString= '';
  let currentLine = 0;

  function readLine(){
    return standardInputString[currentLine++];
  }
  process.stdin.on('data', rawData =>{
    standardInputString += rawData;
  });
  process.stdin.on('end', _ =>{
    standardInputString= standardInputString.trim().split('\n').map(line =>{
      return line.trim();
    });

    main();
  })

  function main(){
    let [a,b] = readLine().split(' ').map(Number);
    // let line = readLine().split(' ').map(Number);

      let hardestDay = a>=b ? a : b;
      let easiestDay = a<=b ? a : b;
      let sum = 0;

      let easierSum = 0;

      let hardDayArr = [];
      let easiestDayArr = [];

      let imposterNumber = 0;
      let didOnce = 1;

      let smallestStart = 1;

        for(let j = 1; j<=hardestDay; j++){

          if(sum >= hardestDay){
           imposterNumber = sum - hardestDay;
           if(imposterNumber !== 0){
            hardDayArr.splice(imposterNumber-1,1);
           }
          //  easierSum += imposterNumber + j;
           smallestStart = j;
           break;
          }
          else{
            sum += j;
            hardDayArr.push(j);
          }
        }
        if(imposterNumber !== 0){
          easierSum = imposterNumber
          easiestDayArr.push(easierSum);
        }
        for(smallestStart; smallestStart<=easiestDay; smallestStart++){

          easierSum += smallestStart;
          if(easierSum <= easiestDay){
            easiestDayArr.push(smallestStart);
          }
        }

      console.log(easiestDayArr.length);
      console.log(easiestDayArr.join(" "));

      console.log(hardDayArr.length);
      console.log(hardDayArr.join(" "));
  }


Once Divan analyzed a sequence $$$a_1, a_2, \ldots, a_n$$$ consisting of $$$n$$$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $$$a$$$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $$$a$$$.A sequence $$$c$$$ is a subsequence of a sequence $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements. For example, $$$[1, \, 2, \, 3, \, 4]$$$, $$$[2, \, 4]$$$, and $$$[2]$$$ are subsequences of $$$[1, \, 2, \, 3, \, 4]$$$, but $$$[4, \, 3]$$$ and $$$[0]$$$ are not.Divan was very proud of his analysis, but now he lost the sequence $$$a$$$, and also the coziness value! However, Divan remembers the value of bitwise OR on $$$m$$$ contiguous subsegments of the sequence $$$a$$$. It turns out that each element of the original sequence is contained in at least one of these $$$m$$$ segments.Divan asks you to help find the coziness of the sequence $$$a$$$ using the information he remembers. If several coziness values are possible, print any.As the result can be very large, print the value modulo $$$10^9 + 7$$$.

The first line contains one integer number $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. The first line of each test case contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively. The following $$$m$$$ lines describe the segments, one per line. Each segment is described with three integers $$$l$$$, $$$r$$$, and $$$x$$$ ($$$1 \le l \le r \le n$$$, $$$0 \le x \le 2^{30} - 1$$$) — the first and last elements of the segment and the bitwise OR of $$$a_l, a_{l + 1}, \ldots, a_r$$$, respectively. It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$.

For each test case print the coziness any suitable sequence $$$a$$$ modulo $$$10^9 + 7$$$.

NoteIn first example, one of the sequences that fits the constraints is $$$[0, 2]$$$. Consider all its non-empty subsequences:  $$$[0]$$$: the bitwise XOR of this subsequence is $$$0$$$;  $$$[2]$$$: the bitwise XOR of this subsequence is $$$2$$$;  $$$[0, 2]$$$: the bitwise XOR of this subsequence is $$$2$$$. The sum of all results is $$$4$$$, so it is the answer.In second example, one of the sequences that fits the constraints is $$$[0, \, 5, \, 5]$$$.In third example, one of the sequences that fits the constraints is $$$[5, \, 6, \, 7, \, 0, \, 2]$$$.

'use strict';

function solve(n, m, a) {
  let num = a.reduce((a, b) => a | b[2], 0);
  let res = 0;
  for (let i = 0; i < 31; i++) {
    if (num & 1 << i) {
      res = add(res, mul(1 << i, power(2, n - 1)));
    }
  }
  return res;
}
const MOD = 10 ** 9 + 7;
function mod(num) {
  return (num % MOD + MOD) % MOD;
}
function add(a, b) {
  return mod(mod(a) + mod(b));
}
function power(a, b) {
  let res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b = b >> 1;
  }
  return res;
}
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = m;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a);
    }
    return 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', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, m, a) {
  a.sort((a, b) => {
    if (a[0] !== b[0]) return a[0] - b[0];else return b[1] - a[1];
  });
  const nums = new Array(n);
  const segTree = new SegTree(n);
  for (let [l, r, val] of a) {
    segTree.update(l - 1, r - 1, val);
  }
  for (let i = 0; i < n; i++) nums[i] = segTree.query(i);
  let res = 0;
  for (let i = 0; i < 31; i++) {
    for (let j = 0; j < n; j++) {
      if (nums[j] & 1 << i) {
        res = add(res, mul(1 << i, power(2, n - 1)));
        break;
      }
    }
  }
  return res;
}
const MOD = 10 ** 9 + 7;
function mod(num) {
  return (num % MOD + MOD) % MOD;
}
function add(a, b) {
  return mod(mod(a) + mod(b));
}
function power(a, b) {
  let res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b = b >> 1;
  }
  return res;
}
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, y, z) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      this._update(this.root, 0, n, x, y, z);
    };
    this.query = x => {
      x = Math.max(x, 0);
      x = Math.min(x, n);
      return this._query(this.root, 0, n, x);
    };
  }
  _newNode(val = 0, left = null, right = null) {
    return {
      val,
      left,
      right,
      add: 0
    };
  }
  _down(node, l, r) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    if (node.add) {
      left.add = node.add;
      left.val = node.add;
      right.add = node.add;
      right.val = node.add;
      node.add = 0;
    }
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.add = z;
      node.val = z;
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
  }
  _query(node, l, r, x) {
    if (!node) return 0;
    if (l === r) return node.val;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (x <= mid) res = this._query(node.left, l, mid, x);else res = this._query(node.right, mid + 1, r, x);
    return res;
  }
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = m;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a);
    }
    return 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', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});
	const mod = 1e9 + 7;
	let t = inputReader.readNumber();

	function solve() {
	  let [n, m] = inputReader.readNumberArray();
	  let totalOr = 0;
	  while (m--) {
	    let [l, r, or] = inputReader.readNumberArray();
	    totalOr |= or;
	  }
	  totalOr %= mod;
	  for (let i = 1; i <= n - 1; i++) totalOr = (2 * totalOr) % mod;
	  console.log(totalOr);
	}

	while (t--) {
	  solve();
	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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, m] = lines[l++].trim().split(' ').map(Number)
        const or = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))
        l += m
        output[i] = solve(n, m, or)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, or) {
    const arr = Array(n).fill(0)
    or.forEach(([l, r, x]) => {
        arr[l - 1] |= x
        arr[r - 1] |= x
    })
// const arr = [0, 2]
// const arr = [5, 6, 7, 0, 2]
    let prev
    let limit = 1
    let ans = 0
    for (let i = 0; i < arr.length; i++) {
        const next = []
        for (let j = 0; j < 30; j++) {
            if (arr[i] & (1 << j)) {
                if (i) {
                    next[j] = minus(limit, prev[j])
                    next[j] = add(next[j], prev[j])
                } else {
                    next[j] = limit
                }
            } else {
                if (i) {
                    next[j] = prev[j]
                    next[j] = add(next[j], prev[j])
                } else {
                    next[j] = 0
                }
            }
            if (i === arr.length - 1) {
                ans = add(ans, mul(next[j], 1 << j))
            }
        }
        limit = mul(limit, 2)
        prev = next
// console.log(prev)
    }

    return ans
}
function add(a, b) {
    return (a + b) % (1e9 + 7)
}
function minus(a, b) {
    return (a - b + 1e9 + 7) % (1e9 + 7)
}
function mul(a, b) {
    let r = 0
    let base = a
    while (b) {
        if (b & 1) {
            r = add(r, base)
        }
        b >>= 1
        base = add(base, base)
    }
    return r
}

'use strict';

function solve(n, m, a) {
  a.sort((a, b) => {
    if (a[0] !== b[0]) return a[0] - b[0];else return b[1] - a[1];
  });
  const nums = new Array(n);
  const segTree = new SegTree(n);
  for (let [l, r, val] of a) {
    segTree.update(l - 1, r - 1, val);
  }
  for (let i = 0; i < n; i++) nums[i] = segTree.query(i);
  let res = 0;
  for (let i = 0; i < 31; i++) {
    for (let j = 0; j < n; j++) {
      if (nums[j] & 1 << i) {
        res = res + (1 << i) * 2 ** (n - 1);
        break;
      }
    }
  }
  return res;
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, y, z) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      this._update(this.root, 0, n, x, y, z);
    };
    this.query = x => {
      x = Math.max(x, 0);
      x = Math.min(x, n);
      return this._query(this.root, 0, n, x);
    };
  }
  _newNode(val = 0, left = null, right = null) {
    return {
      val,
      left,
      right,
      add: 0
    };
  }
  _down(node, l, r) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    if (node.add) {
      left.add = node.add;
      left.val = node.add;
      right.add = node.add;
      right.val = node.add;
      node.add = 0;
    }
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.add = z;
      node.val = z;
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
  }
  _query(node, l, r, x) {
    if (!node) return 0;
    if (l === r) return node.val;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (x <= mid) res = this._query(node.left, l, mid, x);else res = this._query(node.right, mid + 1, r, x);
    return res;
  }
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = m;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a);
    }
    return 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', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, m, a) {
  a.sort((a, b) => {
    if (a[0] !== b[0]) return a[0] - b[0];else return b[1] - a[1];
  });
  const nums = new Array(n);
  const segTree = new SegTree(n);
  for (let [l, r, val] of a) {
    segTree.update(l - 1, r - 1, val);
  }
  for (let i = 0; i < n; i++) nums[i] = segTree.query(i);
  let res = 0;
  for (let i = 0; i < 31; i++) {
    for (let j = 0; j < n; j++) {
      if (nums[i] & 1 << i) {
        res = add(res, mul(1 << i, power(2, n - 1)));
        break;
      }
    }
  }
  return res;
}
const MOD = 10 ** 9 + 7;
function mod(num) {
  return (num % MOD + MOD) % MOD;
}
function add(a, b) {
  return mod(mod(a) + mod(b));
}
function power(a, b) {
  let res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b = b >> 1;
  }
  return res;
}
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, y, z) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      this._update(this.root, 0, n, x, y, z);
    };
    this.query = x => {
      x = Math.max(x, 0);
      x = Math.min(x, n);
      return this._query(this.root, 0, n, x);
    };
  }
  _newNode(val = 0, left = null, right = null) {
    return {
      val,
      left,
      right,
      add: 0
    };
  }
  _down(node, l, r) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    if (node.add) {
      left.add = node.add;
      left.val = node.add;
      right.add = node.add;
      right.val = node.add;
      node.add = 0;
    }
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.add = z;
      node.val = z;
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
  }
  _query(node, l, r, x) {
    if (!node) return 0;
    if (l === r) return node.val;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (x <= mid) res = this._query(node.left, l, mid, x);else res = this._query(node.right, mid + 1, r, x);
    return res;
  }
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = m;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, a);
    }
    return 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', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader();

function _main() {
  _inputLines = _inputData
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });
  const mod = 1e9 + 7;
  let t = inputReader.readNumber();

  function modPower(x, y, mod) {
    let res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0) {
      if (y & 1) res = (res * x) % mod;
      y = y >> 1;
      x = (x * x) % mod;
    }
    return res;
  }

  function solve() {
    let [n, m] = inputReader.readNumberArray();
    let totalOr = 0;
    while (m--) {
      let [l, r, or] = inputReader.readNumberArray();
      totalOr |= or;
    }
    totalOr %= mod;
    let ans = totalOr * modPower(2, n - 1, mod);
    console.log(ans);
  }

  while (t--) {
    solve();
  }
}

var _inputData = "";
function cacheInput(data) {
  _inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", cacheInput).on("end", _main);

function _inputReader() {
  function readNumber() {
    return Number(_inputLines[_lineNumber++]);
  }

  function readNumberArray() {
    return _inputLines[_lineNumber++].split(" ").map((val) => Number(val));
  }

  return {
    readNumber,
    readNumberArray,
  };
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader();

function _main() {
  _inputLines = _inputData
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });
  const mod = 1e9 + 7;
  let t = inputReader.readNumber();

  function modPower(x, y, mod) {
    let res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0) {
      if (y & 1) res = (res * x) % mod;
      y = y >> 1;
      x = (x * x) % mod;
    }
    return res;
  }

  function solve() {
    let [n, m] = inputReader.readNumberArray();
    let totalOr = 0;
    while (m--) {
      let [l, r, or] = inputReader.readNumberArray();
      totalOr |= or;
    }
    let ans = totalOr * modPower(2, n - 1, mod);
    console.log(ans);
  }

  while (t--) {
    solve();
  }
}

var _inputData = "";
function cacheInput(data) {
  _inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", cacheInput).on("end", _main);

function _inputReader() {
  function readNumber() {
    return Number(_inputLines[_lineNumber++]);
  }

  function readNumberArray() {
    return _inputLines[_lineNumber++].split(" ").map((val) => Number(val));
  }

  return {
    readNumber,
    readNumberArray,
  };
}