var t = readline();
while (t-- > 0) {
    var n, c1, c2;
    n = readline();
    c1 = readline();
    c2 = readline();
    for (var i = 0; i < n; i++)
        if (c1[i] == '1' && c2[i] == '1')
            n = -1;
    write(n == -1 ? "NO\n" : "YES\n");
}

'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++];
}

const log = console.log

/********** MAIN *****************/
function main() {
    let t = parseInt(readline());
    let cols,line1,line2,g =[],a
    while(t-->0){
      cols = parseInt(readline());
      line1 = readline().split("")
      line2 = readline().split("")
      g.push(line1)
      g.push(line2)
      a=dfs(g,0,0,cols)
      a?log('YES'):log('NO')
      g =[]
    }
}

const dfs = (g,r,c,cols)=>{
  if(c===cols){
    return true
  }
  if(g[r][c]==='0' || g[r+1][c]==='0'){
    return dfs(g,r,c+1,cols)
  }
  else{
    return false
  }
}

'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 Queue() {
    this.length = 0;
}

Queue.prototype.push = function (item) {
  var node = {item: item};
  if (this.last) {
    this.last = this.last.next = node;
  } else {
    this.last = this.first = node;
  }
  this.length++;
};

Queue.prototype.shift = function () {
  var node = this.first;
  if (node) {
    this.first = node.next;
    if (!(--this.length)) {
      this.last = undefined;
    }
    return node.item;
  }
};

Queue.prototype.slice = function (start, end) {
  start = typeof start === 'undefined' ? 0 : start;
  end = typeof end === 'undefined' ? Infinity : end;

  var output = [];

  var i = 0;
  for (var node = this.first; node; node = node.next) {
    if (--end < 0) {
      break;
    } else if (++i > start) {
      output.push(node.item);
    }
  }
  return output;
}

class Logger {

  constructor() {
    this.enabled = false;
  }

  enable() {
    this.enabled = true;
  }

  disable() {
    this.enabled = false;
  }

  log(...str) {
    if (this.enabled) {
      console.error(...str);
    }
  }
}

let logger = new Logger();
// logger.enable();

function main() {

  let t = +readline();

  for (let i = 0; i < t; ++i) {
    let n = +readline();
    let a = readline();
    let b = readline();

    let canReachEnd = true;

    for (let j = 0; j < n; ++j) {
      if (a[j] == '1' && b[j] == '1') {
        canReachEnd = false;
        break;
      }
    }

    console.log(canReachEnd?'YES':'NO')

  }

}

'use strict';

function solve(n, s) {
  const dp = Array.from({
    length: n
  }, () => [0, 0]);
  for (let j = 0; j < 2; j++) if (s[j][0] === '0') dp[0][j] = 1;
  for (let i = 1; i < n; i++) {
    for (let j = 0; j < 2; j++) if (s[j][i] === '0' && (dp[i - 1][0] || dp[i - 1][1])) dp[i][j] = 1;
  }
  return dp[n - 1][0] || dp[n - 1][1] ? 'YES' : 'NO';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = [];
      let tmp = 2;
      while (tmp--) {
        a.push(await read());
      }
      res[i] = solve(n, 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);
});

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

let ls = [];

function solve(){
    let l = 0;
    const t = parseInt(ls[l++]);
    for (let q = 0; q < t; q++){
        const n = parseInt(ls[l++]);
        const s1 = ls[l++];
        const s2 = ls[l++];
        let res = 'YES';
        for (let i = 0; i < n; i++){
            if (s1[i] == '1' && s2[i] == '1'){
                res = 'NO';
                break;
            }
        }
        console.log(res);
    }
}

rl.on('line', (l) => ls.push(l));
rl.on('close', () => solve());

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let n = nl.num();
		let a = nl.line().split('');
		let b = nl.line().split('');
		let flag = true;
		for(let j = 0; j < n && flag; j++){
			if (a[j] === '1' && a[j] === b[j]) {
				flag = false;
			}
		}
		ans.push(flag);
	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

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

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

process.stdin.on('end', () => {

    const {EOL} = require('os')
    const lines = inputText.split(EOL) /*your input text, split by lines*/

    // console.log(lines);

    let pointer = 0;
    let k = parseInt(lines[pointer++]);
    outer : while (k -- > 0) {

        let len = parseInt(lines[pointer++]);
        let line1 = lines[pointer++];
        let line2 = lines[pointer++];

        // console.log("NO");
        for(let i = 0 ; i < len ; i++) {
            if(line1[i] === '1' && line2[i] === '1') {
                console.log("NO");
                continue outer;
            }
        }

        console.log("YES");
    }

    // [n, m, a] = inputText.split(' ');
    // let k1 = n / a;
    // let k2 = m / a;
    // console.log(Math.ceil(k1) * Math.ceil(k2))
})

//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] = BigInt(next());
		}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 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 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();
	var dy = [-1,-1,-1,0,1,1,1,0];
	var dx = [-1,0,1,1,1,0,-1,-1];
	while(hasNext()){
		var N = nextInt();
		var s = [next(), next()];
		var list = new Array(2);
		for(var i = 0; i < 2; i++){
			list[i] = new Array(N).fill(false);
		}

		var queue = [];
		if(s[0][0] == "0"){
			queue.push([0,0]);
			list[0][0] = true;
		}
		while(queue.length > 0){
			var now = queue.shift();
			var y = now[0];
			var x = now[1];
			for(var i = 0; i < dy.length; i++){
				var nextY = y + dy[i];
				var nextX = x + dx[i];
				if(nextY < 2 && nextY >= 0 && nextX < N && nextX >= 0){
					if(s[nextY][nextX] == "0" && !list[nextY][nextX]){
						list[nextY][nextX] = true;
						queue.push([nextY, nextX]);
					}
				}
			}
		}
		myout((list[1][N - 1]) ? "YES" : "NO");
	}
}

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

function solve(n, grid) {
    const q = [[0, 0]]
    const visited = {}
    while (q.length) {
        // console.log(q)
        const [x, y] = q.shift()
        if (x === 1 && y === n - 1) return 'YES'
        const k = x + ',' + y
        if (visited[k]) continue
        visited[k] = 1

        add(n, grid, q, x, y + 1)
        add(n, grid, q, x + 1, y)
        add(n, grid, q, x + 1, y + 1)
        add(n, grid, q, x - 1, y)
        add(n, grid, q, x - 1, y + 1)
    }
    return 'NO'
}
function add(n, grid, q, x, y) {
    if (x >= 0 && x < 2 && y >= 0 && y < n && grid[x][y] === '0') {
        q.push([x, y])
    }
}

var t = parseInt(readline());
for (var i=0; i<t; i++) {
	var n = parseInt(readline());
	var l1 = readline().split('').map(function(x) { return parseInt(x); });
	var l2 = readline().split('').map(function(x) { return parseInt(x); });
	var b = true;
	for (var j=0; j<n; j++) {
		if (l1[j] === 1 && l2[j] === 1) {
			b = false;
			break;
		}
	}
	print(b ? 'YES' : 'NO');
}

var testcase=parseInt(readline())
while(testcase--)
{
    var n=parseInt(readline())
    var s1=readline()
    var s2=readline()

    var ans=true
    var ind=0;
    while(ind<n)
    {
        var curr1=s1[ind]-'0';
        var curr2=s2[ind]-'0';
        if(curr1 && curr2)
        {
            ans=false;
        }
        ind++;

    }
    if(ans)
    {
        print("YES");
    }
    else
    {
        print("NO");
    }

}

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

  // multi line input
  readline.on('line', line => {
    input+=line
  });

  readline.on('end',()=>{
      console.log(input)
  })

/****************************************************************\
                   BISMILLAHIR RAHMANIR RAHIM
****************************************************************
               AUTHOR NAME: MD. TAHURUZZOHA TUHIN
\****************************************************************/

'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 input() {
    return inputString[currentLine++];
}

function main() {

    let n, m, p, mx = [], mn = [], mp = [], mk = [], mh = [], t;
    t = input();
    let a = 0;
    while (a < t) {
        a++;
        n = input();
        n = parseInt(n);
        m = input();
        p = input();

        for (const x of m) {
            mx.push(x.toString());
        }

        for (const x of p) {
            mn.push(x.toString());
        }
        mp = [mx, mn];
        for (let i = 0; i < 2; i++) {
            for (let j = 0; j < n; j++) {
                if (mp[i][j] === '0' && i == 0) {
                    mk.push(i + 1, j + 1);
                }
                if (mp[i][j] === '0' && i == 1) {
                    mh.push(i + 1, j + 1);
                }
            }
        }
        let mg = [...mk, ...mh];
        let cnt = 0, pnt = 1;
        for (let i = 0; i < mg.length / 2; i += 1) {
            let v1 = Math.abs(mg[i] - mg[i + 2]);
            if (v1 >= 2) pnt = 0;
        }

        if (pnt === 0) {
            for (let i = 0; i < mk.length; i += 2) {
                let v3 = Math.abs(mk[i] - mh[i]);
                let v4 = Math.abs(mk[i + 1] - mh[i + 1]);
                if (((v3 >= 2 || v4 >= 2))) {
                    cnt = 0;
                } else {
                    cnt = 1;
                }
            }
        }
        console.log((pnt || cnt ? "YES" : "NO"));
        mk.length = 0;
        mh.length = 0;
        mg.length = 0;
        mp.length = 0;
        mx.length = 0;
        mn.length = 0;
    }

}

/****************************************************************\
                   BISMILLAHIR RAHMANIR RAHIM
****************************************************************
               AUTHOR NAME: MD. TAHURUZZOHA TUHIN
\****************************************************************/

'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 input() {
    return inputString[currentLine++];
}

function main() {

    let n, m, p, mx = [], mn = [], mp = [], mk = [], mh = [], t;
    t = input();
    let a = 0;
    while (a < t) {
        a++;
        n = input();
        n = parseInt(n);
        m = input();
        p = input();

        for (const x of m) {
            mx.push(x.toString());
        }

        for (const x of p) {
            mn.push(x.toString());
        }
        mp = [mx, mn];
        for (let i = 0; i < 2; i++) {
            for (let j = 0; j < n; j++) {
                if (mp[i][j] === '0' && i == 0) {
                    mk.push(i + 1, j + 1);
                }
                if (mp[i][j] === '0' && i == 1) {
                    mh.push(i + 1, j + 1);
                }
            }
        }
        let mg = [...mk, ...mh];
        let cnt = 0, pnt = 1;
        for (let i = 0; i < mg.length / 2; i += 1) {
            let v1 = Math.abs(mg[i] - mg[i + 2]);
            if (v1 >= 2) pnt = 0;
        }

        if (pnt === 0) {
            for (let i = 0; i < mk.length; i += 2) {
                let v3 = Math.abs(mk[i] - mh[i]);
                let v4 = Math.abs(mk[i + 1] - mh[i + 1]);
                if (((v3 >= 2 || v4 >= 2))) {
                    cnt = 0;
                } else {
                    cnt = 1;
                }
            }
        }
        console.log((pnt || cnt ? "YES" : "NO"));
        mk = mk.splice(0, mk.lenth);
        mh = mh.splice(0, mh.lenth);
        mg = mg.splice(0, mg.lenth);
        mp = mp.splice(0, mp.lenth);
        mx = mx.splice(0, mx.lenth);
        mn = mn.splice(0, mn.lenth);
    }

}


"use strict";
if (typeof print == 'undefined') var print = console.log;
if (typeof readline == 'undefined') {
    let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var readline = () => lines[id ++];
}

let nums = () => readline().split(' ').map(x => +x);
let t = nums(), n = t[0], k = t[1];

let a = nums().map(x => Math.floor((x + k -1) / k)).reduce((m, n) => m + n, 0);
print(Math.floor((a + 1) / 2));

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

var numbers = ints(),
	n = numbers[0],
	k = numbers[1],
	s = ints().reduce(function(s, x) {
		return s + Math.floor(x / k) + (x % k == 0 ? 0 : 1)
	}, 0)

print(Math.floor(s / 2) + (s % 2))

var params = readline().split(" ").map(function convert(value) {return +value; });

var n = params[0];
var k = params[1];

var counter = readline().split(" ").map(function convert(value) {return +value; })
									.reduce(function (total, current) {
										return total + (current - current % k) / k + (current % k !== 0);}, 0);

print((counter - counter % 2) / 2 + (counter % 2 !== 0));

var g = readline().split(" ");
var n = +g[0];
var k = +g[1];
var y = readline().split(" ");
var sum = 0;
for(i=0;i<n;i++){
    sum += Math.ceil(+y[i]/k);
}
print(Math.ceil(sum/2))

var ints = function() {
	return readline().split(' ').map(function(n){
		return parseInt(n)
	})
}

var numbers = ints(),
	n = numbers[0],
	k = numbers[1],
	s = ints().reduce(function(s, n) {
		return s + Math.round(n / k)
	}, 0)

print(Math.round(s / 2))

"use strict";
if (typeof print == 'undefined') var print = console.log;
if (typeof readline == 'undefined') {
    let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var readline = () => lines[id ++];
}

let nums = () => readline().split(' ').map(x => +x);
let t = nums(), n = t[0], k = t[1];

let ans = 0, c = 0;
let a = nums().map(x => (ans += Math.floor(x / (2 * k)), x % (2 * k)));
for (let i of a) {
    if (i > k) ans ++;
    else ++c;
}
ans += c >>> 1; if (c & 1) ans++;
print(ans);


var r = readline().split(' ').map(Number);
var n = r[0], k = r[1], d = {};
for (var i = 0; i < n; i++) {
    var j = readline();
    d[j] = d[j] ? 0 : 1;
}
var x = Object.keys(d).reduce((r, i) => r + d[i], 0);
print(n - x + Math.ceil(x/2));

var n = Number(readline().split(' ')[0]), d = {};
for (var i = 0; i < n; i++) {var j = readline(); d[j] = d[j] ? 0 : 1;}
var x = Object.keys(d).reduce((r, i) => r + d[i], 0);
write(n - x + Math.ceil(x/2));

var arr = readline().split(' ').map(item => +item);
var n = arr[0], k = arr[1];

arr = new Array(k).fill(0);

for(var i = 0; i < n; i++) {
  var j = +readline() - 1;
  arr[j]++;
}

count = 0;
mod = 0;

for(var i = 0; i < arr.length; i++) {
  var j = arr[i] % 2;
  count += arr[i] - j;
  mod += j;
}

count += parseInt(mod / 2) + mod % 2;

print(count);

"use strict";

var main = function() {
    var input = rdAr();
    var n = input[0];
    var k = input[1];
    var C = crAr(2000, 0);
    for (var i = 0; i < n; ++i) {
        var a = +rd();
        C[a] = (++C[a]) % 2;
    }
    var r = C.reduce((v, a) => v + a);
    var bad = r >> 1;
    wr(n - bad);
};

const rd = readline;
const wr = write;
const pr = print;
const rdAr = () => rd().split(' ').map(v => +v);
const prAr = (a) => pr(a.join(' '));
const cmpLt = (a, b) => a - b;
const cmpGt = (a, b) => b - a;
Array.prototype.sortLt = function() { return this.sort(cmpLt); };
Array.prototype.sortGt = function() { return this.sort(cmpGt); };
const crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };

main();

function main() {
    // write code here:
    const nk = stdin[0].split(' ').map(Number)
    var arr = new Array(nk[1]).fill(0),
        result = 0,
        t = 0;
    for (let i = 1; i <= nk[0]; i++) {
        var a = Number(stdin[i]) - 1;
        arr[a]++;
    }
    for (let j = 0; j < nk[1]; j++) {
        result += Math.floor(arr[j] / 2) * 2;
        //如果arr[j]为奇数，则先记录下来为奇数的个数
        if (arr[j] % 2 === 1) t++;
    }
    //在最后的 result 加上 （奇数个数+1）/ 2 的结果
    result += Math.floor((t + 1) / 2);
    console.log(result);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

var v = readline().split(' ');
v.map(x => Number(x));
var cnt = new Array;
cnt.length = v[1];
cnt.fill(0,0, v[1]);
for(var i = 0;i < v[0];i++){
    var x = Number(readline());
    cnt[x - 1]++;
}

var ans = 0;
var have = Math.floor((v[0] + 1)/2);
var t = 0;
for(i = 0;i < v[1];i++){
    ans += Math.floor( (cnt[i] / 2)) * 2;
    if(cnt[i] % 2 == 1) t++;
}
ans +=  Math.floor((t + 1)/2);
print(ans);


var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        used: false,
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        var charMapForStr = {};
        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (charMapForStr[curChar] ||
                to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
            ) {
                hasResult = false;
                break cycle;
            }

            charMapForStr[curChar] = true;
            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
            map[curChar].used = true;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var usedCount = 0;
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (map[char].used) usedCount++;
        if (map[char].used && !map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (!isOk ||usedCount > result.length) {
        print('NO');
    } else {
        print(result);
    }
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        used: false,
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
            ) {
                hasResult = false;
                break cycle;
            }

            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
            map[curChar].used = true;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var usedCount = 0;
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (map[char].used) usedCount++;
        if (map[char].used && !map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (!isOk ||usedCount > result.length) {
        print('NO');
    } else {
        print(result);
    }
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
	map[char] = {
		isFirstChar: false,
		used: false,
		direction: undefined
	};
});

var n = Number(readline());
var hasResult = true;

cycle:
for(var i = 0; i<n; i++) {
	var str = readline();

	var charMapForStr = {};
	for (var j = 0; j < str.length - 1; j++) {
		var curChar = str[j];
		var nextChar = str[j+1];
		var direction = map[curChar].direction;

		if (charMapForStr[curChar] || direction && direction != nextChar) {
			hasResult = false;
			break cycle;
		}

		charMapForStr[curChar] = true;
		if (map[curChar].isFirstChar) {
			map[curChar].isFirstChar = j===0;
		} else {
			map[curChar].isFirstChar = j===0 && !map[curChar].used;
		}
		map[curChar].used = true;
		map[curChar].direction = nextChar;
	}
	var lastChar = str[str.length - 1];
	map[lastChar].used = true;
	if (charMapForStr[lastChar]) {
		hasResult = false;
		break cycle;
	}
}

if (!hasResult) {
	print ("NO");
} else {
	var result = '';
	alphabet.forEach(function(char) {
		if (map[char].isFirstChar) {
			var curChar = char;
			result = result + curChar;
			while(map[curChar].direction) {
				curChar = map[curChar].direction;
				result = result + curChar;
			}
		}
	});
	print(result);
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
	map[char] = {
		isFirstChar: false,
		used: false,
		direction: undefined
	};
});

var n = Number(readline());
var hasResult = true;

cycle:
for(var i = 0; i<n; i++) {
	var str = readline();

	var charMapForStr = {};
	for (var j = 0; j < str.length; j++) {
		var curChar = str[j];
		var nextChar = str[j+1];
		var direction = map[curChar].direction;

		if (charMapForStr[curChar] || direction && nextChar && direction != nextChar) {
			hasResult = false;
			break cycle;
		}

		charMapForStr[curChar] = true;
		if (map[curChar].isFirstChar) {
			map[curChar].isFirstChar = j===0;
		} else {
			map[curChar].isFirstChar = j===0 && !map[curChar].used;
		}
		map[curChar].used = true;
		if (j != str.length -1 ) map[curChar].direction = nextChar;
	}
}

if (!hasResult) {
	print ("NO");
} else {
	var result = '';
	alphabet.forEach(function(char) {
		if (map[char].isFirstChar) {
			var curChar = char;
			result = result + curChar;
			while(map[curChar].direction) {
				curChar = map[curChar].direction;
				result = result + curChar;
			}
		}
	});
	print(result);
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        used: false,
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        var charMapForStr = {};
        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (charMapForStr[curChar] ||
                to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
            ) {
                hasResult = false;
                break cycle;
            }

            charMapForStr[curChar] = true;
            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
            map[curChar].used = true;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (map[char].used && !map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (result === 'crehpuqmbao') {
        Object.keys(map).forEach(function(key) {
            print(key + ": used = " + map[key].used + ", from = " + map[key].from + ", to = " + map[key].to);
        })
    }
    if (!result || !isOk) {
        print('NO');
    } else {
        print(result);
    }
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
	map[char] = {
		isFirstChar: false,
		used: false,
		direction: undefined
	};
});

var n = Number(readline());
var hasResult = true;

cycle:
for(var i = 0; i<n; i++) {
	var str = readline();

	var charMapForStr = {};
	for (var j = 0; j < str.length; j++) {
		var curChar = str[j];
		var nextChar = str[j+1];
		var direction = map[curChar].direction;

		if (charMapForStr[curChar] || direction && nextChar && direction != nextChar) {
			hasResult = false;
			break cycle;
		}

		charMapForStr[curChar] = true;
		if (map[curChar].isFirstChar) {
			map[curChar].isFirstChar = j===0;
		} else {
			map[curChar].isFirstChar = j===0 && !map[curChar].used;
		}
		map[curChar].used = true;
		if (j != str.length -1 ) map[curChar].direction = nextChar;
	}
}

if (!hasResult) {
	print ("NO");
} else {
	var result = '';
	alphabet.forEach(function(char) {
		if (map[char].isFirstChar) {
			var curChar = char;
			result = result + curChar;
			while(map[curChar].direction) {
				curChar = map[curChar].direction;
				result = result + curChar;
			}
		}
	});
	var isOk = true;
	var charMapForStr = {};
	for (var j = 0; j < result.length; j++) {
	    if (charMapForStr[result[j]]) {
	        isOk = false;
	        break;
	    }
	    charMapForStr[result[j]] = true;
	}
	if (!result || !isOk) {
	    print('NO');
	}
	print(result);
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        var charMapForStr = {};
        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (charMapForStr[curChar] ||
                to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
                ) {
                hasResult = false;
                break cycle;
            }

            charMapForStr[curChar] = true;
            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (!map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (!isOk) {
        print('NO');
    } else {
        print(result);
    }
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        used: false,
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        var charMapForStr = {};
        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (charMapForStr[curChar] ||
                to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
            ) {
                hasResult = false;
                break cycle;
            }

            charMapForStr[curChar] = true;
            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
            map[curChar].used = true;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (map[char].used && !map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (result === 'crehpuqmbao') {
        Object.keys(map).forEach(function(key) {
            print(key + ":u=" + map[key].used + ",f=" + map[key].from + ",t=" + map[key].to);
        })
    }
    if (!result || !isOk) {
        print('NO');
    } else {
        print(result);
    }
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
	map[char] = {
		isFirstChar: false,
		used: false,
		direction: undefined
	};
});

var n = Number(readline());
var hasResult = true;

cycle:
for(var i = 0; i<n; i++) {
	var str = readline();

	var charMapForStr = {};
	for (var j = 0; j < str.length; j++) {
		var curChar = str[j];
		var nextChar = str[j+1];
		var direction = map[curChar].direction;

		if (charMapForStr[curChar] || direction && nextChar && direction != nextChar) {
			hasResult = false;
			break cycle;
		}

		charMapForStr[curChar] = true;
		if (map[curChar].isFirstChar) {
			map[curChar].isFirstChar = j===0;
		} else {
			map[curChar].isFirstChar = j===0 && !map[curChar].used;
		}
		map[curChar].used = true;
		if (j != str.length -1 ) map[curChar].direction = nextChar;
	}
}

if (!hasResult) {
	print ("NO");
} else {
	var result = '';
	alphabet.forEach(function(char) {
		if (map[char].isFirstChar) {
			var curChar = char;
			result = result + curChar;
			while(map[curChar].direction) {
				curChar = map[curChar].direction;
				result = result + curChar;
			}
		}
	});
	var isOk = true;
	var charMapForStr = {};
	for (var j = 0; j < result.length; j++) {
	    if (charMapForStr[result[j]]) {
	        isOk = false;
	        break;
	    }
	    charMapForStr[result[j]] = true;
	}
	if (!result || !isOk) {
	    print('NO');
	} else {
	    print(result);
	}
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        used: false,
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        var charMapForStr = {};
        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (charMapForStr[curChar] ||
                to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
            ) {
                hasResult = false;
                break cycle;
            }

            charMapForStr[curChar] = true;
            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
            map[curChar].used = true;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (map[char].used && !map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (!result || !isOk) {
        print('NO');
    } else {
        print(result);
    }
}

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
var map = {};

alphabet.forEach(function(char) {
    map[char] = {
        used: false,
        to: undefined,
        from: undefined
    };
});

var n = Number(readline());
var hasResult = true;

cycle:
    for(var i = 0; i<n; i++) {
        var str = readline();

        var charMapForStr = {};
        for (var j = 0; j < str.length; j++) {
            var curChar = str[j];
            var nextChar = str[j+1];
            var prevChar = str[j-1];
            var to = map[curChar].to;
            var from = map[curChar].from;

            if (charMapForStr[curChar] ||
                to && nextChar && to != nextChar ||
                from && prevChar && from != prevChar
            ) {
                hasResult = false;
                break cycle;
            }

            charMapForStr[curChar] = true;
            if (j != str.length -1 ) map[curChar].to = nextChar;
            if (j != 0 ) map[curChar].from = prevChar;
            map[curChar].used = true;
        }
    }

if (!hasResult) {
    print ("NO");
} else {
    var isOk = true;
    var result = '';
    var charMapForStr = {};
    for(var i=0; i<alphabet.length; i++) {
        var char = alphabet[i];
        if (map[char].used && !map[char].from) {
            var curChar = char;
            result = result + curChar;
            if (charMapForStr[curChar]) {
                isOk = false;
                break;
            }
            charMapForStr[curChar] = true;
            while(map[curChar].to) {
                curChar = map[curChar].to;
                result = result + curChar;
                if (charMapForStr[curChar]) {
                    isOk = false;
                    break;
                }
                charMapForStr[curChar] = true;
            }
        }
    }
    if (!isOk) {
        print('NO');
    } else {
        print(result);
    }
}


const process = require("process");

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

let line = "";

process.stdin.on("data", (data) => {
  line += data + "\n";
});

process.stdin.on("end", () => {
  line = line.trim().split("\n");
  main();
});

function main() {
  const t = Number(line[0]);
  //   console.log(t);
  let j = 1;

  while (j < t + 1) {
    const [n, m] = line[j++].split(" ");
    solve(Number(n), Number(m));
  }
}

function solve(m, n) {
  let val = n,
    sum = (n * (n + 1)) / 2;
  val = 2 * val;

  let i = 1;

  while (i < m) {
    sum += val;
    val = val + n;
    i++;
  }

  console.log(sum);
}

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

let lineCounter = 0
// multi line input
readline.on('line', (line) => {
  if (lineCounter > 0) {
    let [n, m] = line.split(' ').map(Number)
    console.log(optimalPath(n, m))
  }
  lineCounter++
})

let optimalPath = (n, m) => {
  let minimalCost = (m * (m - 1)) / 2

  minimalCost += (m * (n * (n + 1))) / 2

  return minimalCost
}

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, m = 0;
    for(i = 1; i <= t; i++){
        var a = lines[i].split(' ').map(Number);
        n = a[0], m = a[1];
        var ans = m * (m - 1) / 2 + m * n * (n + 1) / 2;
        console.log(ans);
    }
});

//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 M = nextInt();
		var output = M * (M + 1) / 2;
		output += ((N * (N + 1) / 2)) * M;
		output -= M;
		myout(output);
	}
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var x = readline().split(' ');
        var n = parseInt(x[0]);
        var m = parseInt(x[1]);

        var sum = 0;
        sum += (m*(m+1))/2;
        sum += m*(n*(n+1))/2;
        sum -= m;

        console.log(sum);

    }
}

"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,m] = readline().trim().split(" ").map(cur=>parseInt(cur));
    let cnt = Math.floor((m * (m + 1))/2);
    for(let i=1;i<n;i++) cnt+=((i+1)*m);
    console.log(cnt);
  }
};
solve();

function run(m,n) {
	let c = n;
	let sum = 0;
	for (let i = 1; i < n; i++) {
		sum+=i;
	}
	while(m--){

		sum+=n;
		n+=c;
	}
	console.log(sum)
}
function runProgram(input){
	input = input.split('\n');
	let tt = +input[0];
	let i = 1;
	while(tt--){
		let data = input[i].split(' ');
		let m = +data[0];
		let n = +data[1];
		run(m,n);
		i++;
	}
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
let read="";
process.stdin.on("data",function(input){
	read+=input;
});
process.stdin.on("end",function(){
	read=read.replace(/\n$/,"");
	read=read.replace(/\n$/,'');
	runProgram(read);
});

//#region IO
'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 print(val) {
    console.log(val);
}

function readInt() {
    return parseInt(readline());
}
// Make a Snippet for the code above this and then write your logic in main();
//#endregion
function readInts() {
    return readline().split(' ').map(x=>parseInt(x));
}

function autoSum(a1,an,n) {
    return (a1+an) * n / 2;
}

function main() {
    let t = readInt();
    while(t-- > 0) {
        let [n,m] = readInts();
        print(autoSum(1,m,m) + autoSum(m,n*m,n) - m);
    }
}

/**
 * Format:
 * {type: 'number', namedVariable?: string }
 * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }
 * {type: 'array', namedVariable?: string }
 * {type: 'string', namedVariable?: string }
 */
 const readline = require('readline');

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

   let resolvePromise = null;
   const donePromise = new Promise((res, rej) => {
     resolvePromise = res;
   });

   function waitUntilDone() {
     return donePromise;
   }

   /**
    * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }
    */
   const stack = [];
   let pc = -1;

   function finished() {
     if (pc >= instructions.length) {
       return true;
     }
     return false;
   }

   function checkFinished() {
     // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);
     if (pc >= instructions.length) {
       return true;
     }
     if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {
       return true;
     }
     return false;
   }

   function getNextInstructionContext() {
     if (!stack.length) {
       return {
         index: ++pc,
       }
     }
     const lastStack = stack[stack.length - 1];
     if (lastStack.pointer === lastStack.instructionCount) {
       lastStack.pointer = 0;
       lastStack.iteration = lastStack.iteration + 1;
     }
     if (lastStack.count === lastStack.iteration) {
       stack.pop();
       pc = lastStack.basePointer + lastStack.instructionCount + 1;
       return {
         index: pc,
       }
     }

     lastStack.pointer = lastStack.pointer + 1;
     return {
       index: lastStack.basePointer + lastStack.pointer,
       context: {
         namedPath: [...lastStack.context.namedPath, lastStack.iteration]
       }
     }
   }

   function pushRepeatToStack(instruction, index, context) {
     stack.push({
       type: 'repeat',
       count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],
       iteration: 0,
       basePointer: index,
       pointer: 0,
       instructionCount: instruction.instructionCount,
       context: {
         namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],
       }
     })
     setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);
   }

   function nextInstruction() {
     if (finished()) {
       // console.warn('Calling nextInstruction after finished, something is wrong');
       return;
     }
     while (true) {
       const { index, context } = getNextInstructionContext();
       const instruction = instructions[index];

       // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);
       switch (instruction.type) {
         case 'number':
         case 'array':
         case 'string':
           return {
             ...instruction,
             namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,
           }
         case 'repeat':
           pushRepeatToStack(instruction, index, context);
           break;
         default:
           // console.warn('Unclear instruction, abort');
           return;
       }
     }
   }

   function getIn(object, path) {
     for (let i = 0; i < path.length; ++i) {
       object = object[path[i]];
     }
     return object;
   }

   function setIn(object, path, value) {
     for (let i = 0; i < path.length - 1; ++i) {
       if (object[path[i]] == null) {
         object[path[i]] = {};
       }
       object = object[path[i]];
     }
     object[path[path.length - 1]] = value;
   }

   rl.on('line', line => {
     if (finished()) {
       return;
     }
     const { type, namedPath } = nextInstruction();
     switch (type) {
       case 'number':
         if (namedPath) {
           setIn(mappedVariables, namedPath, parseInt(line));
         }
         break;
       case 'string':
         if (namedPath) {
           setIn(mappedVariables, namedPath, line.trim());
         }
         break;
       case 'array':
         if (namedPath) {
           setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));
         }
         break;
       default:
       // console.warn(`Value unread, received type ${type}.`);
     }

     if (checkFinished()) {
       resolvePromise(mappedVariables);
       rl.close();
     }
   });
   return {
     waitUntilDone,
   };
 }

 function solve(testCase) {
  const n = testCase.nAndM[0];
  const m = testCase.nAndM[1];
  return (m * (m - 1) / 2) + (n * (n + 1) / 2 * m);
 }

 (async function main() {
   const reader = createCLIReader([
     { type: 'number', namedVariable: 'numberOfTestCase' },
    { type: 'repeat', instructionCount: 1, count: 'numberOfTestCase', namedVariable: 'testCase' },
    { type: 'array', namedVariable: 'nAndM' },
   ]);
   const schema = await reader.waitUntilDone();

   for (let i = 0; i < schema.numberOfTestCase; ++i) {
     console.log(solve(schema.testCase[i]));
   }
 })();

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var x = readline().split(' ');
        var n = parseInt(x[0]);
        var m = parseInt(x[1]);

        var sum = 0;
        for (let j = 0; j < m; j++) {
            sum += (j+1);
        }
        for (let j = 0; j < n; j++) {
            sum += m*(j+1);
        }
        sum -= m;

        console.log(sum);

    }
}

'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 findKthLargest(nums, k) {
    k = nums.length - k;
    const quickSelect = (l, r) => {
        let pivot = nums[r];
        let p = l;
        for (let i = l; i < r; i++) {
            if (nums[i] <= pivot) {
                swapper(nums, p, i);
                p++;
            }
        }
        swapper(nums, p, r);

        if (p > k) return quickSelect(l, p - 1);
        else if (p < k) return quickSelect(p + 1, r);
        else return nums[p];
    };

    return quickSelect(0, nums.length - 1);
};

function swapper(array, a, b) {
    const temp = array[b];
    array[b] = array[a];
    array[a] = temp;
};

function main() {
    const t = readline() - 1;
    for (var l = 0; l <= t; l++) {
        const [n, m] = readline().split(' ').map(r => (r) - 0);
        if (m == 1) {
            const x = n * (n + 1) / 2;
            foo(String(x));
        }
        else {
            const x = m * (m + 1) / 2;
            const y = (2*m + (n-1)*m) * n/ 2;
            foo(String(x+y-m));
        }
    }
}
function foo(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    console.log();  // with auto '\n' (newline)
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let nm = readline().split(" ").map(Number);
    print(Easy(nm[0], nm[1]));
  }
}
function Easy(n, m) {
  let nth = n;
  let a = m;
  let d = m;
  let sum = (nth / 2) * (2 * a + (nth - 1) * d);
  let sum2 = (m * (m + 1)) / 2;
  return sum + sum2 - m;
}

'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++) {
        const [rows, cols] = readline().split(' ').map(Number);
        let sum = 0;
        for (let m = 0; m < cols; m++) {
            sum += m + 1;
        }
        for (let n = 1; n < rows; n++) {
            sum += (n + 1) * cols;
        }

        output(sum);
    }
}

'use strict';

function solve(n, m) {
  return m * (m - 1) / 2 + m * n * (n + 1) / 2;
}

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);
      res[i] = solve(n, m);
    }
    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);
});

var q = Number(readline());
while(q--) {
   var s=readline().split(" ");
   var n=Number(s[0]);
   var m=Number(s[1]);
   var tot=0;
   for(i=1;i<=m;++i)
      tot+=i;
   for(i=2;i<=n;++i)
      tot+=(i-1)*m+m;
   print(tot);
}

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

// multi line input
readline.on('line', (line) => {
  if (line.length > 1) {
    let [n, m] = line.split(' ').map(Number)
    console.log(optimalPath(n, m))
  }
})

let optimalPath = (n, m) => {
  let minimalCost = (m * (m - 1)) / 2

  minimalCost += (m * (n * (n + 1))) / 2

  return minimalCost
}


const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
function main(input){

	if(i == 0){
		n = 3
		i++
		return
	}
	let inputarr = input.split(' ')

	let r = parseInt(inputarr[0])
	let g = parseInt(inputarr[1])
	let b = parseInt(inputarr[2])

	let arr = [r, g, b]

	arr.sort(function(a,b) {
		return a-b

	})
	if(arr[1]+arr[0] < arr[2] - 1){

		console.log("No")
	}
	else
	{
		console.log("Yes")
	}

}

//Don't have to see. start------------------------------------------
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);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
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){
  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';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var tmp = nextIntArray();
    tmp.sort(function(a,b){
    	return b - a;
    });
    var max = tmp[0];
    var mins = tmp[1] + tmp[2];

    if(max - mins < 2){
      output[i] = "Yes";
    }else{
      output[i] = "No";
    }
  }
  myout(myconv(output, 9));
}

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;
  }

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);
  const r = arr[2] - arr[1] - arr[0];

  if (r > 1) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

let input = "";
const { EOL } = require("os");
process.stdin.on("data", i => (input += i));

process.stdin.on("end", func);

async function func() {
  const [t, ...queries] = input.split(EOL);
  for (let i = 0; i < t; i++) {
    const [r, g, b] = queries.shift().split(" ").map(a => parseInt(a));
    if (r + g + 1 < b || r + b + 1 < g || g + b + 1 < r) {
      console.log('No')
    } else {
      console.log('Yes')
    }
  }
}

module.exports = func;

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    lines.forEach(line => {
        let values = line.split(' ').map(Number).sort((a, b) => a - b);
        let result = values[2] - values[0] - values[1]  <= 1;
        console.log(result ? 'Yes' : 'No');
    });
});

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0;
});
txt.shift();
for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split(" ").filter(data=>data.length>0).map(data=>data*1));
}

function doit(tab) {
    let max=tab.indexOf(Math.max(...tab));
    let score=0;
    tab.forEach((data,index)=>{
        if(index!=max)score+=data;
    });
    if(score>=tab[max]-1){
        console.log("YES");
    }else{
        console.log("NO");

    }
}

function main() {
  var testCasesNum = +readline();
  var testCases = [];
  for (var i = 0; i < testCasesNum; i++) {
    (function (i) {
      testCases[i] = readline();
      canPay(testCases[i]);
    })(i)
  }
}

function canPay(testCase) {
  var caseArr = testCase.split(' ').map(Number);
  var r = +caseArr[0];
  var g = +caseArr[1];
  var b = +caseArr[2];
  if ((r >= g && r >= b && r <= g + b + 1) ||
    (g >= r && g >= b && g <= r + b + 1) ||
    (b >= g && b >= r && b <= g + r + 1)) {
    print("Yes")
  } else {
    print("No")
  }
}

main()

'use strict';

let col = +readline();

let strings = [];
for (let i = 0; i < col; i++){
	strings[i] = readline();
	strings[i] = strings[i].split(" ").map(function(item) {
		return +item;
	});
}

function yesNo(arr) {
	let max = 0;
	for (let i = 0; i < 3; i++) {
		if (max <= arr[i]) {
			max = arr[i];
		}
	}
	let sum = arr[0] + arr[1] + arr[2];
	if (max - 1 > (sum - max)) {
		return 'No\n';
	} else {
		return 'Yes\n';
	}
}

for (let i = 0; i < col; i++) {
	let res = yesNo(strings[i]);
	print(res);
}

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, ''))

  const t = parseInt(arr.shift())

  for(let i = 0; i < t; i++) {
    const r = arr[i].split(' ').map(a => parseInt(a))
    sort(r)
    if(r[2] - r[1] - r[0] > 1) wr('No')
    else wr('Yes')
  }
})

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

function max(...x) {
  return Math.max(...x)
}

function min(...x) {
  return Math.min(...x)
}

function mod(a, m) {
  let x = a % m
  if(x >= 0 )  return x
  else return m + x
}

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

var t = parseInt(readline(), 10),
    inp = [];

for(var i=1; i<=t; i++) {
    inp = readline().split(' ').map(el => parseInt(el, 10));
    r = inp[0];
    g = inp[1];
    b = inp[2];

    if(r>=g && r>=b) {
        if(g+b >= r-1) print('YES');
        else print('NO');
    } else if(g>=r && g>=b) {
        if(r+b >= g-1) print('YES');
        else print('NO');
    } else if(b>=r && b>=g) {
        if(r+g >= b-1) print('YES');
        else print('NO');
    }
}

"use strict";

let col = +readline();

let strings = [];
for (let i = 0; i < col; i++){
	strings[i] = readline();
	strings[i] = strings[i].split(" ").map(function(item) {
		return +item;
	});
}

function yesNo(arr) {
	let max = 0;
	for (let i = 0; i < 3; i++) {
		if (max <= arr[i]) {
			max = arr[i];
		}
	}
	let sum = arr[0] + arr[1] + arr[2];
	if ((sum - max) < max) {
		return 'No\n';
	} else {
		return 'Yes\n';
	}
}

for (let i = 0; i < col; i++) {
	let res = yesNo(strings[i]);
	print(res);
}

'use strict';

let col = +readline();

let strings = [];
for (let i = 0; i < col; i++){
	strings[i] = readline();
	strings[i] = strings[i].split(" ").map(function(item) {
		return +item;
	});
}

function yesNo(arr) {
	let max = 0;
	for (let i = 0; i < 3; i++) {
		if (max <= arr[i]) {
			max = arr[i];
		}
	}
	let sum = arr[0] + arr[1] + arr[2];
	if ((sum - max) <= max - 1) {
		return 'No\n';
	} else {
		return 'Yes\n';
	}
}

for (let i = 0; i < col; i++) {
	let res = yesNo(strings[i]);
	print(res);
}

"use strict";

var col = +readline();

var strings = [];
for (var i = 0; i < col; i++){
	strings[i] = readline();
	strings[i] = strings[i].split(" ").map(function(item) {
		return +item;
	});
}

function yesNo(arr) {
	let max = 0;
	for (var i = 0; i < 3; i++) {
		if (max < arr[i]) {
			max = arr[i];
		}
	}
	var sum = arr[0] + arr[1] + arr[2];
	if ((sum - max) < max) {
		return 'No';
	} else if ((sum - max) >= max) {
		return 'Yes';
	}
}

for (var i = 0; i < col; i++) {
	print(yesNo(strings[i]));
}

"use strict";

var col = +readline();

var strings = [];
for (var i = 0; i < col; i++){
	strings[i] = readline();
	strings[i] = strings[i].split(" ").map(function(item) {
		return +item;
	});
}

function yesNo(arr) {
	let max = 0;
	for (var i = 0; i < 3; i++) {
		if (max < arr[i]) {
			max = arr[i];
		}
	}
	var sum = arr[0] + arr[1] + arr[2];
	if ((sum - max) < max) {
		return 'No\n';
	} else {
		return 'Yes\n';
	}
}

for (var i = 0; i < col; i++) {
	print(yesNo(strings[i]));
}

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, ''))

  const t = parseInt(arr.shift())

  for(let i = 0; i < t; i++) {
    const [r, g, b] = arr[i].split(' ').map(a => parseInt(a))
    if(r >= g && r >= b && b + g >= r) {
      wr('Yes')
    }
    else if(g >= r && g >= b && b + r >= g) {
      wr('Yes')
    }
    else if(b >= r && b >= g && g + r >= b) {
      wr('Yes')
    }
    else wr('No')
  }
})

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

function max(...x) {
  return Math.max(...x)
}

function min(...x) {
  return Math.min(...x)
}

function mod(a, m) {
  let x = a % m
  if(x >= 0 )  return x
  else return m + x
}

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

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;
  }

  const arr = d.split(' ').map(Number);
  const min = Math.min(...arr);
  const max = Math.max(...arr);

  if (max - min > 1) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let arr = []
function main(input){

	if(i == 0){
		n = 3
		i++
		return
	}
	arr = []
	let inputarr = input.split(' ')

	let r = inputarr[0]
	let g = inputarr[1]
	let b = inputarr[2]

	const res = Math.abs((r-g-b))

	console.log(res > 3 ? "NO" : "YES")
}

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let arr = []
function main(input){

	if(i == 0){
		n = 3
		i++
		return
	}
	arr = []
	let inputarr = input.split(' ')

	let r = parseInt(inputarr[0])
	let g = parseInt(inputarr[1])
	let b = parseInt(inputarr[2])

	if(r === g){
		if(r > b){
			console.log("No")
			return
		}
	}

	if(g === b){
		if(g > r){
			console.log("No")
			return
		}
	}

	if(r === b){
		if(r > b){
			console.log("No")
			return
		}
	}

	const res = Math.abs((r-g-b))

	console.log(res > 3 ? "No" : "Yes")

}

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let arr = []
function main(input){

	if(i == 0){
		n = 3
		i++
		return
	}
	arr = []
	let inputarr = input.split(' ')

	let r = inputarr[0]
	let g = inputarr[1]
	let b = inputarr[2]

	if(r === g){
		if(r > b){
			console.log("NO")
			return
		}
	}

	if(g === b){
		if(g > r){
			console.log("NO")
			return
		}
	}

	if(r === b){
		if(r > b){
			console.log("NO")
			return
		}
	}

	const res = Math.abs((r-g-b))

	console.log(res > 3 ? "NO" : "YES")

}

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let arr = []
function main(input){

	if(i == 0){
		n = 3
		i++
		return
	}
	arr = []
	let inputarr = input.split(' ')

	let r = inputarr[0]
	let g = inputarr[1]
	let b = inputarr[2]

	if(r === b || r === g || g === b){
		console.log("NO")
	}

	console.log(r-b-g)
	const res = Math.abs((r-g-b))

	console.log(res > 3 ? "NO" : "YES")

}

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let arr = []
function main(input){

	if(i == 0){
		n = 3
		i++
		return
	}
	arr = []
	let inputarr = input.split(' ')

	let r = inputarr[0]
	let g = inputarr[1]
	let b = inputarr[2]

	const res = Math.abs((r-g-b))

	console.log(res >= 3 ? "NO" : "YES")

}


var data = '';
process.stdin.setEncoding('utf8');

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

process.stdin.on('end', () =>
{
    var x = data.split(/\s+/);
    var i = 1;

    for (var cas = 0; cas < x[0]; cas++, i += 2)
    {
        var n = x[i];
        var res = '';
        var str = x[i + 1];
        var len = str.length;
        var left = 0, right = len - 1;
        for (; left < len && str[left] == '0'; left++);
        for (; right >= 0 && str[right] == '1'; right--);
        for (var j = 0; j < left; j++) res += '0';
        if (left < right) res += '0';
        for (var j = right + 1; j < len; j++) res += '1';
        console.log(res);
    }
});

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; t++) {
      read();
      var s = read();
      var firstOne = s.indexOf('1');
      var lastZero = s.lastIndexOf('0');
      if (firstOne < lastZero && firstOne !== -1) {
         s = s.substr(0, firstOne) + s.substr(lastZero);
      }
      write(s);
   }
}

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');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

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

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

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
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--) {
    let _ = +readLine();
    let str = readLine();
    let countZero = 0;
    let countOne = 0;
    for (let i = 0; i < str.length; i++) {
      if (str[i] === "0") {
        countZero++;
      } else {
        break;
      }
    }
    for (let i = str.length - 1; i >= 0; i--) {
      if (str[i] === "1") {
        countOne++;
      } else {
        break;
      }
    }
    if (countOne + countZero === str.length) {
      console.log(str);
    } else {
      console.log(`${"0".repeat(countZero)}0${"1".repeat(countOne)}`);
    }
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input = '';
process.stdin.on('data', (line) => {
    input += line;
});
process.stdin.on('end', () => {
    const lines = input.split('\n');
    let tests = parseInt(lines.shift(), 10);
    while (tests--) {
        lines.shift();
        const s = lines.shift();
        let zeroCount = 0;
        let ans = [...s]
            .reverse()
            .reduce((acc, char) => {
            if (char === '0') {
                zeroCount++;
            }
            else if (zeroCount) {
                zeroCount = 1;
            }
            else {
                acc += char;
            }
            return acc;
        }, '');
        ans += '0'.repeat(zeroCount);
        console.log([...ans].reverse().join(''));
    }
});
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(element => parseInt(element, 10));
}

const processData = (lines) => {
  let acc = 0
  const n = +lines[acc]
  acc++
  for (let i=0; i<n; i++) {
    const a = +lines[acc]
    acc++
    const l = lines[acc]
    acc++

    let left = 0
    let right = l.length
    while(l[left] === '0') {
      left++
    }
    while(l[right-1] === '1') {
      right--
    }

    // console.log(l)
    // console.log(left, right)

    if (left >= right) {
      console.log(l)
    } else {
      // console.log('left', l.slice(0, left))
      // console.log('right', l.slice(right))
      console.log(l.slice(0, left) + '0' + l.slice(right))
    }

    //
    // const zeroPoint = l.indexOf('0')
    // const onePoint = l.indexOf('1')
    // const secondZeroPoint = l.indexOf('0', onePoint)
    //
    // if (zeroPoint === 0) {
    //   if (secondZeroPoint > 0) {
    //     console.log(l.slice(0, onePoint) + '0')
    //   } else {
    //     console.log(l)
    //   }
    // } else {
    //   if (zeroPoint > 0 ) {
    //     console.log('0')
    //   } else {
    //     console.log(l)
    //   }
    // }
  }
}

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)
})

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; t++) {
      var n = Number(read());
      var s = read();
      var firstOne = s.indexOf('1');
      var lastZero = s.lastIndexOf('0');
      if (firstOne < lastZero && firstOne !== -1) {
         s = s.substr(0, firstOne) + s.substr(lastZero);
      }
      write(s);
   }
}

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');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

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

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

var t = parseInt(readline());

while(t--){
  var n = parseInt(readline());
  var str = readline();

  var cur = 0;
  var isDesc = false;
  while(cur + 1 < n){
    if(str[cur] == '1' && str[cur + 1] == '0'){
      isDesc = true;
      break;
    }
    cur++;
  }

  if(isDesc) {
    var newstr = "";
    leadZ = 0;
    while(leadZ < n && str[leadZ] == '0')
      leadZ++;
    leadZ++;
    sufO = 0;
    while(sufO < n && str[n - 1 - sufO] == '1')
      sufO++;

    while(leadZ--)
      newstr += "0";

    while(sufO--)
      newstr += "1";

    print(newstr);
  } else {
    print(str);
  }

}


;(function () {

	print((function (k, d) {
		k = +k;
		if (d === '0' && k > 1) return 'No solution';
		for (var i = 1; i < k; i++) d += '0';
		return d;
	}).apply(this, readline().split(' ')));

}).call(this);

print(function(k, d) {
	if (k > 1 && d === 0) return 'No solution';
	var ans = [d];
	k--;
	while (k--)
		ans.push('0');
	return ans.join('');
} .apply(0, readline().split(' ').map(Number)));

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

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

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {

	function solve(numDigits, digitalRoot) {
		if (digitalRoot == 0) {
			print(numDigits == 1 ? 0 : "No solution");
			return;
		}
		var digits = [digitalRoot];
		for (var digitIndex = 1; digitIndex < numDigits; ++digitIndex) {
			digits.push(0);
		}
		print(digits.join(""));
	}

	var data = tokenizeIntegers(readline());
	solve(data[0], data[1]);
}

main();

print(function(k, d) {
	if (k === 0 && d > 1) return 'No solution';
	var ans = [d];
	k--;
	while (k--)
		ans.push('0');
	return ans.join('');
} .apply(0, readline().split(' ').map(Number)));

;(function () {

	print((function (k, d) {
		for (var i = 1, k = +k; i < k; i++) d += '0';
		return d;
	}).apply(this, readline().split(' ')));

}).call(this);

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

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

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {

	function solve(numDigits, digitalRoot) {
		if (digitalRoot == 0) {
			print(numDigits == 1 ? 0 : "Impossible");
			return;
		}
		var digits = [digitalRoot];
		for (var digitIndex = 1; digitIndex < numDigits; ++digitIndex) {
			digits.push(0);
		}
		print(digits.join(""));
	}

	var data = tokenizeIntegers(readline());
	solve(data[0], data[1]);
}

main();


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 [rowLen, colLen, x, y] = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  const visited = {};

  for (let i = y; i <= colLen; i++) {
    console.log(`${x} ${i}`);
  }
  for (let i = y - 1; i > 0; i--) {
    console.log(`${x} ${i}`);
  }

  let reverse = false;

  for (let row = 1; row <= rowLen; row++) {
    for (let col = 1; col <= colLen; col++) {
      if (x === row) {
        reverse = true;
        continue;
      }
      if (!reverse) {
        if (row % 2 !== 0) {
          console.log(`${row} ${col}`);
        } else {
          console.log(`${row} ${colLen + 1 - col}`);
        }
      } else {
        if (row % 2 === 0) {
          console.log(`${row} ${col}`);
        } else {
          console.log(`${row} ${colLen + 1 - col}`);
        }
      }
    }
  }
}

'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() {
    const line = readline();
    var cases = line.split(" ");
    var n = parseInt(cases[0]);
    var m = parseInt(cases[1]);
    var x = parseInt(cases[2]);
    var y = parseInt(cases[3]);
    pathPrint(n,m,x,y);
}

function pathPrint(n,m,x,y){
  var currX = x;
  var currY = y;

  var reachedX = -1;
  var reachedY = -1;

    for(var i = currY; i >=1; i--){
        console.log(currX + " "+i);
    }
    for(var j = currY+1;j <=m;j++){
        console.log(currX+ " "+j);
    }

    reachedX = currX;
    reachedY = m;

    var rowAbove = currX-1;
    var rowBelow = currX+1;

    while(rowAbove>=1 && rowBelow<=n){
        reachedX = rowAbove;
        reachedY = m;
        for(var col1 = reachedY ; col1>=1;col1--){
            console.log(reachedX+ " "+col1);
        }
        reachedX = rowBelow;
        reachedY = 1;
        for(var col = 1 ; col<=m;col++){
            console.log(reachedX+ " "+col);
        }
        rowAbove--;
        rowBelow++;
    }

    if(rowBelow <=n){
        reachedX = rowBelow;
        reachedY = m;
        while(rowBelow <=n){
            reachedX = rowBelow;
            if(reachedY == m){
                for(var col2 = m ; col2>=1;col2--){
                    console.log(reachedX+ " "+col2);
                }
                reachedY = 1;
            }else{
                for(var col3 = 1 ; col3<=m;col3++){
                    console.log(reachedX+ " "+col3);
                }
                reachedY = m;
            }
            rowBelow++;
        }
    }

    if(rowAbove >=1){
        reachedX = rowAbove;
        reachedY = m;
        while(rowAbove >=1){
            reachedX = rowAbove;
            if(reachedY == m){
                for(var col4 = m ; col4>=1;col4--){
                    console.log(reachedX+ " "+col4);
                }
                reachedY = 1;
            }else{
                for(var col5 = 1 ; col5<=m;col5++){
                    console.log(reachedX+ " "+col5);
                }
                reachedY = m;
            }
            rowAbove--;
        }
    }
}

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 [rowLen, colLen, x, y] = readLine()
    .split(" ")
    .map((n) => parseInt(n));

  for (let row = 0; row < rowLen; row++) {
    for (let col = 0; col < colLen; col++) {
      console.log(`${x} ${y}`);
      y++;
      if (y > colLen) y = 1;
    }
    y--;
    x++;
    if (y === 0) y = colLen;
    if (x > rowLen) x = 1;
  }
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
// 	data = data.split('\n');
// 	const testCases = data[0] * 1;
// 	let i = 1;
// 	while (i <= testCases) {
    let num = data.trim().split(' ').map(Number);
    let n = num[0];
    let m = num[1];
    let x = num[2];
    let y = num[3];
    console.log(x+' '+y);
    for (let c = m; c >= 1; c -= 1) {
      if (c !== y) console.log(x+' '+c);
    }
    let check = false;
    for (let i = 0; i < n; i++) {
        if (i+1 === x) {check=true; continue;}
      if (check) {
          if (i % 2 !== 0) {
          for (let j = 0; j < m; j++) console.log((i+1)+' '+(j+1));

        // If current row is odd, print from
        // right to left
        } else {
            for (let j = m - 1; j >= 0; j--)
                console.log((i+1)+' '+(j+1));
        }
      }
        // If current row is even, print from
        // left to right
      else {
        if (i % 2 == 0) {
          for (let j = 0; j < m; j++) console.log((i+1)+' '+(j+1));

        // If current row is odd, print from
        // right to left
        } else {
            for (let j = m - 1; j >= 0; j--)
                console.log((i+1)+' '+(j+1));
        }
      }

    // i += 1;
	}
}

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 [n, m, sx, sy] = readLine().split(/\s/).map(Number)
  const visited = Array(n).fill().map(() => [])
  console.log(sx, sy)
  visited[sx - 1][sy - 1] = true
  console.log(1, sy)
  visited[0][sy - 1] = true
  console.log(1, 1)
  visited[0][0] = true
  for (let r = 0; r < n; r++) {
    for (let _c = 0; _c < m; _c++) {
      const c = r % 2 === 0 ? _c : m - 1 - _c
      if (!visited[r][c]) {
        console.log(r + 1, c + 1)
        visited[r][c] = true
      }
    }
  }
}

const main = () => {
  const input = readline()
    .split(" ")
    .map((i) => Number(i));

  const N = input[0];
  const M = input[1];

  const pos = {
    x: input[2],
    y: input[3],
  };

  for (var i = pos.x; i <= N; i++) {
    print(i, pos.y);
  }

  for (var i = pos.x - 1; i >= 1; i--) {
    print(i, pos.y);
  }

  pos.x = 1;

  for (var i = 1; i < pos.y; i++) {
    if (pos.x === 1) {
      for (var j = 1; j <= N; j++) {
        print(j, i);
      }

      pos.x = N;
    } else {
      for (var j = N; j >= 1; j--) {
        print(j, i);
      }

      pos.x = 1;
    }
  }

  for (var i = pos.y + 1; i <= M; i++) {
    if (pos.x === 1) {
      for (var j = 1; j <= N; j++) {
        print(j, i);
      }

      pos.x = N;
    } else {
      for (var j = N; j >= 1; j--) {
        print(j, i);
      }

      pos.x = 1;
    }
  }
};

main();

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 [rowLen, colLen, x, y] = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  const visited = {};

  for (let i = y; i <= colLen; i++) {
    console.log(`${x} ${i}`);
    visited[`${x}_${i}`] = true;
  }
  for (let i = y - 1; i > 0; i--) {
    console.log(`${x} ${i}`);
    visited[`${x}_${i}`] = true;
  }

  for (let row = 1; row <= rowLen; row++) {
    for (let col = 1; col <= colLen; col++) {
      if (row % 2 !== 0) {
        !visited[`${row}_${col}`] && console.log(`${row} ${col}`);
      } else {
        !visited[`${row}_${colLen + 1 - col}`] && console.log(`${row} ${colLen + 1 - col}`);
      }
    }
  }
}

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() {
  const [x, y, a, b] = readLine()
    .split(" ")
    .map((n) => parseInt(n));

  const visited = {};
  const arr = [...Array(x).fill(0)].map((_) => Array(y).fill(0));
  arr[a - 1][b - 1] = 1;
  traverse(a - 1, b - 1);

  function traverse(a, b) {
    if (a < 0 || a >= x || b < 0 || b >= y || visited[`${a}${b}`]) return;

    console.log(`${a + 1} ${b + 1}`);

    visited[`${a}${b}`] = 1;

    traverse(a, b + 1);
    traverse(a - 1, b);
    traverse(a, b - 1);
    traverse(a + 1, b);
  }
}

const main = () => {
  const input = readline()
    .split(" ")
    .map((i) => Number(i));

  const N = input[0];
  const M = input[1];

  const pos = {
    x: input[2],
    y: input[3],
  };

  for (var i = pos.x; i <= N; i++) {
    print(i, pos.y);
  }

  for (var i = pos.x - 1; i >= 1; i--) {
    print(i, pos.y);
  }

  pos.x = 1;

  for (var i = 1; i < pos.y; i++) {
    if (pos.x === 1) {
      for (var j = 1; j <= N; j++) {
        print(j, i);
      }
      pos.x = N;
    } else {
      for (var j = N; j >= 1; j--) {
        print(i, j);
      }

      pos.x = 1;
    }
  }

  for (var i = pos.y + 1; i <= M; i++) {
    if (pos.x === 1) {
      for (var j = 1; j <= N; j++) {
        print(j, i);
      }
      pos.x = N;
    } else {
      for (var j = N; j >= 1; j--) {
        print(i, j);
      }

      pos.x = 1;
    }
  }
};

main();


process.stdin.resume();
process.stdin.setEncoding("utf-8");
var arr = "";
process.stdin.on("data", function (chunk) {
  arr += chunk;
});

process.stdin.on("end", function () {
  arr = arr.split("\n");
  const testcases = parseInt(arr.shift());
  for (let t = 0; t < testcases; t++) {
    const n = parseInt(arr[t]);
    if (n % 2 === 0) {
      console.log(0, 0, n / 2);
    } else {
      console.log(-1);
    }
  }
});

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var value = parseInt(readline());
    var result = ""
    if (value % 2 === 0)
    {
        result = `${value/2} 0 0`;
    }
    else result = "-1"
    print(result)
}

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;
	for(i = 1; i <= t; i++){
        var k = lines[i];
        if(k % 2 === 0){
            console.log(0, k / 2, k / 2);
        }else{
            console.log(-1);
        }
    }
});

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
        var x = parseInt(readline());
        if (x%2 === 0) {
            console.log(x/2,x/2,0);
        } else {
            console.log(-1);
        }

    }
}

'use strict';

function solve(n) {
  if (n & 1) return -1;
  return `0 ${n / 2} ${n / 2}`;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      res[i] = solve(n);
    }
    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';

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++) {
        const n = Number(readline());

        let carry = (a, b, c) => {
            return [
                '1' + a,
                '1' + b,
                '0' + c
            ];
        };

        let dontCarry = (a, b, c) => {
            return [
                '0' + a,
                '0' + b,
                '0' + c
            ];
        }

        const bits = n.toString(2).split('').reverse().join('');
        let a = '';
        let b = '';
        let c = '';

        if (bits[0] === '1') {
            output(-1);
            continue;
        }

        for (let bit = 1; bit < bits.length; bit++) {
            if (bits[bit] === '1') {
                [a, b, c] = carry(a, b, c);
            } else {
                [a, b, c] = dontCarry(a, b, c);
            }
        }

        a = parseInt(a, 2);
        b = parseInt(b, 2);
        c = parseInt(c, 2);

        output(`${a} ${b} ${c}`);
    }
}

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++];
}

/***
Codeforces Round #804 (Div. 2)
2022-07-04

A. The Third Three Number Problem
***/

function main() {
  const t = parseInt(readline());

  for (let i = 0; i < t; i++) {
    const n = parseInt(readline());

    if (n % 2 == 0) {
      console.log(`${0} ${n / 2} ${(n, n / 2)}`);
    } else {
      console.log("-1");
    }
  }
}

function formula(a, b, c) {
  return (a ^ b) + (b ^ c) + (a ^ c);
}

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;
	for(i = 1; i <= t * 2; i++){
        var k = lines[i];
        if(k % 2 === 0){
            console.log(0, k / 2, k / 2);
        }else{
            console.log(-1);
        }
    }
});

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;
	for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1], c = k[2];
        console.log(a + b + c, b + c, c);
    }
});