function solve(a,b) {
    var p = a*b;
    var h = Math.floor(p/2);
    return (p % 2 == 0) ? h : ++h;
}
var t = Number(readline());
while (t--) {
    var arr = readline().split(' ').map(Number);
    var a = arr[0];
    var b = arr[1];
    print(solve(a,b));
}

'use strict';

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

let inputString = [];
let currentLine = 0;

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

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

    //withTiming(main);
    main();
});

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

const withTiming = callback => {
    const start = new Date();
    callback();
    console.log(`Took ${new Date() - start} ms`);
}

function main() {
    const n = Math.floor(readline());
    const inputs = [];

    for (let i = 0; i < n; i++) {
        const [a, b] = readline().split(' ').map(a => parseInt(a));

        let sum = Math.floor(a / 2) * Math.floor(b / 2) * 2;
        sum += (a % 2) * Math.ceil(b / 2) + (b % 2) * Math.ceil(a / 2) - ((a % 2) && (b % 2));
        console.log(sum);
    }
}

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 [a, b] = d.split(' ').map(Number);

  if (Number.isInteger(a) && Number.isInteger(b)) {
    console.log(Math.ceil(a*b/2));
  }

  c++;
});

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [m, n] = lines[i+1].split(' ').map(x => +x)
    const max = Math.max(m, n)
    const min = Math.min(m, n)

    if (max > 2) {
      if (max % 2 === 0) {
        console.log(max/2 *min)
      } else {
        console.log( (max-1)/2*min + Math.ceil(min/2))
      }
    } else {
      console.log(Math.ceil(m*n/2))
    }
  }
}

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

'use strict';
// node.js
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() {
    var testCases = parseInt(readLine());

    function minNumberOfLanterns(row, column) {
        return Math.ceil((row * column / 2));
    }

    for (var i = 0; i < testCases; i++) {
        var numbers = readLine()
            .split(" ")
            .map(num => parseInt(num));

        var row = numbers[0];
        var column = numbers[1];

        console.log(minNumberOfLanterns(row, column));
    }
}

let outFd = null;
let fs = null;
let promisify = null;

function stdinStdout() {
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let lingeringLine = "";
    process.stdin.on('data', function(chunk) {
        lines = chunk.split("\n");

        lines[0] = lingeringLine + lines[0];
        lingeringLine = lines.pop();

        lines.map(s => s.trim()).forEach(line => {
            processLine(line.trim());
        });
    });

    process.stdin.on('end', function() {
        processLine(lingeringLine.trim());
    });
}

function inOutFiles(fin, fout) {
    fs = require('fs');
    outFd = fs.openSync(fout, 'w');
    data = fs.readFileSync(fin);
    data.toString().split('\n').map(line => line.trim()).forEach(processLine);
    fs.closeSync(outFd);
}

function output(s) {
    if(outFd) {
        fs.writeSync(outFd, s.toString() + '\n');
    } else {
        console.log(s);
    }
}

let t = -1;
let n;
let m;

function processLine(line) {
    if(t == -1) {
        t = parseInt(line);
    } else if(t > 0) {
        t--;
        [n, m] = line.split(/\s+/).slice(0, 2).map(s => parseInt(s));
        if(n < m) {
            [n, m] = [m, n];
        }
        solve();
    }
}

function solve() {
    output((n - n % 2) / 2 * m + (n % 2) * ((m - m % 2) / 2 + m % 2));
}

stdinStdout();
// inOutFiles('amusing.in', 'amusing.out');

function lamps(n, m) {
    if (m % 2 != 0) {
        if (n % 2 == 0) {
            return ((Math.floor(n/2) * m));
        }
        else {
            return ((Math.floor(m/2) * n) + Math.floor(n / 2) + 1);
        }
    }
    else {
        return (Math.floor(m/2) * n);
    }
}

function processData(input) {
    const inputArr = input.split("\n");
    const n = inputArr[0];
    for (let i = 1; i <= parseInt(n); i ++) {
        const n_m = inputArr[i].split(' ');
        console.log(lamps(parseInt(n_m[0]), parseInt(n_m[1])));
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		output[i] = Math.ceil(N * M / 2);
	}
	myout(myconv(output,9));
}

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.shift();
  for (let i = 0; i < testCases; i += 1) {
    let park = data[i].split(' ');
    let lantern = 0;
    const row = +park[0];
    const column = +park[1];
    if (row % 2 === 0) lantern = row / 2 * column;
    else {
      lantern = (row - 1) / 2 * column;
      lantern += Math.ceil(column / 2);
    }
    console.log(lantern);
  }
}

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 [a, b] = d.split(' ').map(Number);

  console.log(Math.ceil(a*b/2));

  c++;
});

function lamps(n, m) {
    if (m % 2 != 0) {
        if (n % 2 == 0) {
            return ((Math.floor(m/2) * n));
        }
        else {
            return ((Math.floor(m/2) * n) + Math.floor(n / 2) + 1);
        }
    }
    else {
        return (Math.floor(m/2) * n);
    }
}

function processData(input) {
    const inputArr = input.split("\n");
    const n = inputArr[0];
    for (let i = 1; i <= parseInt(n); i ++) {
        const n_m = inputArr[i].split(' ');
        console.log(lamps(parseInt(n_m[0]), parseInt(n_m[1])));
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

function lamps(n, m) {
    if (m % 2 != 0) {
        if (n % 2 == 0) {
            return ((Math.floor(m/2) * n) + Math.floor(n / 2));
        }
        else {
            return ((Math.floor(m/2) * n) + Math.floor(n / 2) + 1);
        }
    }
    else {
        let temp = n;
        n = m;
        m = temp;

        if (n % 2 == 0) {
            return ((Math.floor(m/2) * n));
        }
        else {
            return ((Math.floor(m/2) * n));
        }
    }
}

function processData(input) {
    const inputArr = input.split("\n");
    const n = inputArr[0];
    for (let i = 1; i <= parseInt(n); i ++) {
        const n_m = inputArr[i].split(' ');
        console.log(lamps(parseInt(n_m[0]), parseInt(n_m[1])));
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});


function toi(x){return parseInt(x);}
var n=+readline();
var v=[];
var d=[];
var p=[];
var res=[];
for(var i=0;i<n;i++){
    t=readline().split(" ").map(toi);
    v.push(t[0]);
    d.push(t[1]);
    p.push(t[2]);
}
for(var i=0;i<n;i++){
    if(p[i]>=0){
	res.push(i+1);
	var tv=v[i];
	var td=0;
	for(var j=i+1;j<n;j++){
	    if(p[j]>=0){
		if(tv>0){
		    p[j]=Math.max(p[j]-tv,-1);
		    tv-=1
		    if(p[j]<0){
			td+=d[j];
		    }else{
			p[j]=Math.max(p[j]-td,-1);
			if(p[j] < 0){
			    td+=d[j];
			}
		    }
		}else{
		    p[j]=Math.max(p[j]-td,-1);
		    if(p[j] < 0){
			td+=d[j];
		    }
		}
	    }
	}
    }
}
print(res.length);
print(res.join(" "));

n = +readline();
v = [], d = [], p = [];
line = [];
for (var i = 0; i < n; i++) {
	input = readline().split(" ").map(Number);
	v[i] = input[0];
	d[i] = input[1];
	p[i] = input[2];
	line.push({v:v[i],d:d[i],p:p[i],i:i+1});
}

answer = [];
while (line.length > 0) {
	//write(line + "\n");

	var patient = line[0];
	//write(patient.v + "\n");
	answer.push(patient.i);
	line.splice(0,1);

	//
	var cry = -1;
	for (var i = 0; i < line.length && i < patient.v; i++) {
		line[i].p -= patient.v-i;
		if (cry == -1 && line[i].p < 0)
			cry = i;
	}

	//for (var i = 0; i < line.length; i++) write(line[i].p + " ");

	while (cry >= 0) {
		var j = cry;
		cry = -1;
		for (var i = j; i < line.length; i++) {
			line[i].p -= line[j].d;
			if (cry == -1 && i > j && line[i].p < 0) {
				cry = i;
			}
		}
	}

	for (var i = line.length-1; i >= 0; --i) {
		if (line[i].p < 0) {
			line.splice(i,1);
		}
	}

}
write(answer.length + "\n");
for (var i = 0; i < answer.length; i++) {
	write(answer[i] + " ");
}


var str = readline().split('').sort();
var sum = 0;
var num = 1;

for(var i = 0; i<str.length; i++) {
	if (str[i] == str[i+1]) {
		num++;
	} else {
		sum += num * num;
		num = 1;
	}
}

print(sum);

print(function(s) {
	var cnt = new Int32Array(256);
	for (var i = 0; i < 256; i++)
		cnt[i] = 1;
	var ans = 0;
	for (var i = 0; i < s.length; i++) {
		ans += cnt[s.charCodeAt(i)];
		cnt[s.charCodeAt(i)] += 2;
	}
	return ans;
}(readline()));

'use strict'

let S = readline()

let ls = {}

for (let i = 0; i < S.length; i++) {
  let l = S[i]
  ls[l] = ls[l] || 0
  ls[l]++
}

let c = 0
Object.keys(ls).forEach(l => {
  c += ls[l] * ls[l]
})

print(c)

function result(str) {
  var ret = 0;
  var values = {};
  for (var i=0;i<str.length;i++) {
    values[str.charCodeAt(i)] = (values[str.charCodeAt(i)] || 0) + 1;
  }
  for (var k in values) {
    ret += values[k] * values[k];
  }
  return ret;
}

print(result(readline()));


var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseArray = readline().split(" ");
    var firstElevator = parseInt(caseArray[0]);
    var firstElevatorTime = firstElevator - 1;
    var secondElevator = parseInt(caseArray[1]);
    var secondElevatorDestination = parseInt(caseArray[2])
    var secondElevatorTime = 0;
    if (secondElevator > secondElevatorDestination)
    {
        secondElevatorTime = secondElevator - 1;
    }
    else
    {
        secondElevatorTime = ((secondElevatorDestination - secondElevator) + (secondElevatorDestination - 1))
    }
    var result = 0;
    if (firstElevatorTime > secondElevatorTime)
    {
        result = 2;
    }
    else if (firstElevatorTime < secondElevatorTime)
    {
        result = 1;
    }
    else
    {
        result = 3;
    }
    print(result);
}

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() {
  var t = readline();
  for (var i = 0; i < t; i++) {
    var [a, b, c] = readline().trim().split(' ').map(Number);
    if ((a - 1) == ((Math.abs(b - c) + c) -1)) {
      process.stdout.write('3\n');
    }
    if ((a - 1) > ((Math.abs(b - c) + c) -1)) {
      process.stdout.write('2\n')
    }
    if ((a - 1) < ((Math.abs(b - c) + c) -1)) {
      process.stdout.write('1\n')
    }
  }
}
// https://codeforces.com/contest/1729/problem/B
  // function main() {
  //   let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  //   let n = readline();
  //   for (let k = 0; k < n; k++) {
  //     var o = readline();
  //     var splittedSTR = readline().trim().split('');
  //     var output = [];
  //     for (var i = 0; i < o; i++) {
  //       if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {
  //         splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;
  //         splittedSTR.splice(i + 1, 1)
  //         splittedSTR.splice(i - 1, 1)
  //       }
  //       if (o - i == 1) {
  //         for (var j = 0; j < splittedSTR.length; j++) {
  //           output.push(Alpha[splittedSTR[j] - 1])
  //           if (output.length == splittedSTR.length) {
  //             console.log(output.join(''));
  //           }
  //         }
  //       }
  //     }
  //   }
  // }

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 [e1, e2, f] = d.split(" ").map(Number);
  const e1d = Math.abs(e1 - 1);
  const e2d = Math.abs(f - e2) + Math.abs(f - 1);

  if (e1d < e2d) {
    console.log(1);
  } else if (e2d < e1d) {
    console.log(2);
  } else {
    console.log(3);
  }

  c++;
});

rl.on("close", () => {});

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 [a, b, c] = nl.nums();
		let x = 0;
		if (b > c) {
			x = b;
		} else {
			x = c + c - b;
		}
		if (a < x) {
			ans.push(1);
		} else if (a > x) {
			ans.push(2);
		} else {
			ans.push(3);
		}
	}
	console.log(ans.join('\n'));
};

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

/*
** Template
*/

// Common Template Starts //
//*
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++];
}
// Common Template Ends //

function getResult(inputs) {
    let a = inputs[0]
    let b = inputs[1]
    let c = inputs[2]

    if (a == 1 && b != 1) return 1
    if (a == b && c < b) return 3

    let opt1 = a - 1
    let opt2 = 0

    if (b >= c) {
        opt2 = b - 1
    } else if (b < c) {
        opt2 = c - b
        opt2 += c - 1
    }

    if (opt1 < opt2) return 1
    if (opt1 > opt2) return 2
    if (opt1 == opt2) return 3
}

function main() {
    let testCases = parseInt(readline())
    while (testCases--) {
        let inputs = readline()
        inputs = inputs.split(' ').map(Number)
        console.log(getResult(inputs))
    }
}
//*/
// console.clear()
// let inputs = ''
// inputs = '1 2 3'
// inputs = inputs.split(' ').map(Number)
// console.log( getResult(inputs) )
// inputs = '3 1 2'
// inputs = inputs.split(' ').map(Number)
// console.log( getResult(inputs) )
// inputs = '3 2 1'
// inputs = inputs.split(' ').map(Number)
// console.log( getResult(inputs) )
// process.exit(1)

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const [a, b, c] = rns();
  const d = Math.abs(b - c) + c;
  if (a > d) return 2;else if (a < d) return 1;
  return 3;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

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

function solve(a, b, c) {
    const t1 = a - 1
    const t2 = c < b ? b - 1 : c - b + c - 1
    if (t1 < t2) return 1
    if (t1 > t2) return 2
    return 3
}

function twoElevator (lift1, from , to) {
    if (lift1 == 1) return 1
    var result1 = lift1 - 1
    var result2 = 0

    if (from > to) {
        result2 = from - to + to - 1
    } else { //
        result2 = 2 * to - from - 1
    }

    if (result1 === result2) return 3
    if (result1 > result2) {
        return 2
    } else {
        return 1
    }
}

function main() {

    var count = readline();

    var inp = [];

    for(var i = 0 ; i < count ; i++) {

        inp = readline().split(' ').map(el => +el);
        var result = twoElevator(inp[0], inp[1], inp[2]);
        print(result);

    }

}
main()

var t = +readline();

for(var i = 0; i< t; i ++) {

      var nums = [];
    var arr = readline().split(' ').map((t) => +t)
    print(TwoElevators(arr[0],arr[1],arr[2]))

}

function TwoElevators(a,b,c){
    a -= 1;
    var test1 = Math.abs(b - c) + c - 1;
    if (test1 < a){
        return '2'
    }else if (test1 > a){
        return '1'
    }else {
        return '3'
    }
}

function foo(elev1, elev2from, elev2to) {
	var elev1time = elev1 - 1

    var elev2time = 0

    if(elev2to === 1) elev2time = elev2from - 1
  	else {
    	elev2time = Math.abs(elev2to - elev2from) + (elev2to - 1)
    }

  	if(elev1time < elev2time) return 1
  	else if(elev1time === elev2time) return 3
  	else return 2
}

var count = readline();

var inp;
var size;

for(var i = 0 ; i < count ; i++) {

    inp = readline().split(' ').map(el => +el);
    print(foo(inp[0], inp[1], inp[2]));

}

T = readline();

while (T--) {
  str = readline()
    .split(" ")
    .map((el) => +el);
  a = str[0];
  b = str[1];
  c = str[2];

  bc = 0;

  if (b > c) bc = b;
  else bc = b + (c-b) * 2;

  ans = 0;
  if (a < bc) ans = 1;
  else if (a > bc) ans = 2;
  else ans = 3;

  print(ans);
}

var t = parseInt(readline());

for (var test = 0; test < t; test++) {
    var inp = readline().split(' ');
    var a = parseInt(inp[0]);
    var b = parseInt(inp[1]);
    var c = parseInt(inp[2]);

    var abs1 = a - 1;
    var abs2 = Math.abs(c - b) + c - 1;

    if (abs1 < abs2) {
        print('1');
    } else if (abs2 < abs1) {
        print('2');
    } else {
        print('3');
    }
}

    var t = readline();
    for(var i = 0 ; i < t ; i++){
        var inputs = readline().split(' '),
            a = inputs[0],
            b = inputs[1];
            c = inputs[2];
            firstElevator = a - 1;
            secondElevator = Math.abs(b - c) + (c - 1);
            if(firstElevator < secondElevator){
                print('1');
            }
            else if(firstElevator > secondElevator){
                print('2');
            }
            else{
                print('3');
            }
    }

"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 testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    var q = readline().split(" ");
    var a = +q[0];
    var w = +q[1];
    var e = +q[2];
    if (Math.abs(e - w) + (e - 1) === a - 1) arr.push(3);
    else if (Math.abs(e - w) + (e - 1) > a - 1) arr.push(1);
    else arr.push(2);
  }
  arr = arr.join("\n");
  console.log(arr);
}

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

let inputString = "";

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

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

  main();
});

function main() {
  const testCases = inputString[0];

  const answers = [];

  for (let i = 1; i <= testCases; i++) {
    let [a, b, c] = inputString[i].split(" ").map((s) => Number(s));

    let bDist = c < b ? b : (c - b) * 2 + b;
    a--;
    bDist--;

    if (a === bDist) answers.push(3);
    else if (a < bDist) answers.push(1);
    else answers.push(2);
  }

  answers.forEach((v) => console.log(v));
}

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split(" ").map(Number)

        a = Math.abs(k[0] - 1);
        b = Math.abs(k[2] - k[1]) + Math.abs(k[2] - 1);
          if (a < b) {
            console.log(1);
          } else if (b < a) {
            console.log(2);
          } else {
            console.log(3);
          }

    }

});

"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 main() {
  const t = readline();
  for (let i = 0; i < t; i++) {
    let sol = 3;

    const [a, b, c] = readline()
      .split(" ")
      .map((x) => parseInt(x));

    if (a - 1 < Math.abs(b - c) + Math.abs(c - 1)) sol = 1;
    else if (a - 1 > Math.abs(b - c) + Math.abs(c - 1)) sol = 2;
    console.log(sol);
  }
}

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

"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() {
  let testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    let q = readline().split(" ");
    let a = +q[0];
    let w = +q[1];
    let e = +q[2];
    if (Math.abs(e * 2 - (w + 1)) === a - 1) {
      arr.push(3);
      continue;
    }
    if (Math.abs(e * 2 - (w + 1)) + (e - 1) > a - 1) {
      arr.push(1);
      continue;
    }
    arr.push(2);
  }
  arr = arr.join("\n");
  console.log(arr);
}

"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() {
  let testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    let q = readline().split(" ");
    let a = +q[0];
    let w = +q[1];
    let e = +q[2];
    if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);
    else if (Math.abs(e * 2 - (w + 1)) + (e - 1) > a - 1) arr.push(1);
    else arr.push(2);
  }
  arr=arr.join("\n");
  console.log(arr);
}

"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() {
  let testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    let q = readline().split(" ");
    let a = +q[0];
    let w = +q[1];
    let e = +q[2];
    if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);
    else if (Math.abs(e * 2 - (w + 1)) + (e - 1) > a - 1) arr.push(1);
    else arr.push(2);
  }
  console.log(arr.join("\n"));
}

"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 testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    var q = readline().split(" ");
    var a = +q[0];
    var w = +q[1];
    var e = +q[2];
    if (Math.abs(e - w )+ (e- 1) === a - 1) arr.push(3);
    if (Math.abs(e - w )+ (e- 1) > a - 1) arr.push(1);
    else arr.push(2);
  }
  arr = arr.join("\n");
  console.log(arr);
}

"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 testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    var q = readline().split(" ");
    var a = +q[0];
    var w = +q[1];
    var e = +q[2];
    if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);
    if (Math.abs(e * 2 - (w + 1)) > a - 1) arr.push(1);
    else arr.push(2);
  }
  arr = arr.join("\n");
  console.log(arr);
}

"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 testCases = +readline();
  let arr = [];
  for (let m = 0; m < testCases; m++) {
    var q = readline().split(" ");
    var a = +q[0];
    var w = +q[1];
    var e = +q[2];
    if (Math.abs(e * 2 - (w + 1)) === a - 1) arr.push(3);
    if (Math.abs(e * 2) - (w + 1) > a - 1) arr.push(1);
    else arr.push(2);
  }
  arr =arr.join("\n")
  console.log(arr);
}

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

let inputString = "";

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

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

  main();
});

function main() {
  const testCases = inputString[0];

  const answers = [];

  for (let i = 1; i <= testCases; i++) {
    const [a, b, c] = inputString[i].split(" ").map((s) => Number(s));

    if (a === 1) answers.push(1);
    else if (
      (a === 2 && b === 2 && c === 1) ||
      (a === 3 &&
        ((b === 1 && c === 2) || (b === 2 && c === 3) || (b === 3 && c === 1)))
    )
      answers.push(3);
    else answers.push(2);
  }

  answers.forEach((v) => console.log(v));
}

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

let inputString = "";

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

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

  main();
});

function main() {
  const testCases = inputString[0];

  const answers = [];

  for (let i = 1; i <= testCases; i++) {
    const [a, b, c] = inputString[i].split(" ").map((s) => Number(s));

    if (a === 1) answers.push(1);
    else if (
      (a === 2 && b === 2 && c === 1) ||
      (a === 3 && ((b === 3 && c === 1) || (b === 1 && c === 2)))
    )
      answers.push(3);
    else answers.push(2);
  }

  answers.forEach((v) => console.log(v + " "));
}

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

let inputString = "";

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

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

  main();
});

function main() {
  const testCases = inputString[0];

  const answers = [];

  for (let i = 1; i <= testCases; i++) {
    const [a, b, c] = inputString[i].split(" ").map((s) => Number(s));

    if (a === 1) answers.push(1);
    else if (
      (a === 2 && b === 2 && c === 1) ||
      (a === 3 && ((b === 3 && c === 1) || (b === 1 && c === 2)))
    )
      answers.push(3);
    else answers.push(2);
  }

  answers.forEach((v) => console.log(v + "\n"));
}

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

let inputString = "";

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

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

  main();
});

function main() {
  const testCases = inputString[0];

  const answers = [];

  for (let i = 1; i <= testCases; i++) {
    const [a, b, c] = inputString[i].split(" ").map((s) => Number(s));

    if (a === 1) answers.push(1);
    else if (
      (a === 2 && b === 2 && c === 1) ||
      (a === 3 && ((b === 3 && c === 1) || (b === 1 && c === 2)))
    )
      answers.push(3);
    else answers.push(2);
  }

  answers.forEach((v) => console.log(v));
}

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split(' ').map(Number)
        a = k[0]
        b = k[1]
        c = k[2]
        if(a == 1){
            console.log(1)
        }else{
            if(a == 3 && b == 2 && c == 1){
                console.log(2)
            }else{
                if(b + c == a){
                console.log(3)
                }else{
                    console.log(1)
                }
            }
        }

    }

});

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j =1; j <= n; j++){
        k = lines[j].split(' ').map(Number)
        a = k[0]
        b = k[1]
        c = k[2]
        if(a == 1){
            console.log(1)
        }else{
            if(a == 3 && b == 2 && c == 1){
                console.log(2)
            }else{
                if(b + c == a){
                console.log(3)
                }else{
                    console.log(1)
                }
            }
        }

    }

});//k[k.length - 1] == '' ||

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j =1; j <= n; j++){
        k = lines[j].split(' ').map(Number)
        a = k[0]
        b = k[1]
        c = k[2]
        if(a == 1){
            console.log(1)
        }else{
            if(a == 3 && b == 2 && c == 1){
                console.log(2)
            }else{
                console.log(3)
            }
        }

    }

});//k[k.length - 1] == '' ||

"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 main() {
  const t = readline();
  for (let i = 0; i < t; i++) {
    let sol = 3;

    const [a, b, c] = readline()
      .split(" ")
      .map((x) => parseInt(x));
    if (b < c) {
      if (a - 1 < Math.abs(b - c) + Math.abs(c - 1)) sol = a;
      else if (a - 1 > Math.abs(b - c) + Math.abs(c - 1)) sol = b;
    } else {
      if (a - 1 < Math.abs(b - c - 1)) sol = a;
      else if (a - 1 > Math.abs(b - c - 1)) sol = b;
    }

    console.log(sol);
  }
}

"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 main() {
  const t = readline();
  for (let i = 0; i < t; i++) {
    let sol = 3;

    const [a, b, c] = readline()
      .split(" ")
      .map((x) => parseInt(x));

    if (a - 1 < Math.abs(b - c) + Math.abs(c - 1)) sol = a;
    else if (a - 1 > Math.abs(b - c) + Math.abs(c - 1)) sol = b;
    console.log(sol);
  }
}

"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 main() {
  const t = readline();
  for (let i = 0; i < t; i++) {
    let sol = 3;

    const [a, b, c] = readline()
      .split(" ")
      .map((x) => parseInt(x));

    if (a < Math.abs(b - c) + Math.abs(c)) sol = a;
    else if (a > Math.abs(b - c) + Math.abs(c)) sol = b;
    console.log(sol);
  }
}

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

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() {
  var t = readline();
  for (var i = 0; i < t; i++) {
    var [a, b, c] = readline().trim().split(' ').map(Number);
    if ((a - 1) == ((Math.abs(b - c) + c) -1)) {
      process.stdout.write('3');
    }
    if ((a - 1) > ((Math.abs(b - c) + c) -1)) {
      process.stdout.write('2')
    }
    if ((a - 1) < ((Math.abs(b - c) + c) -1)) {
      process.stdout.write('1')
    }
  }
}
// https://codeforces.com/contest/1729/problem/B
  // function main() {
  //   let Alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  //   let n = readline();
  //   for (let k = 0; k < n; k++) {
  //     var o = readline();
  //     var splittedSTR = readline().trim().split('');
  //     var output = [];
  //     for (var i = 0; i < o; i++) {
  //       if (splittedSTR[i + 1] == 0 && splittedSTR[i + 2] != 0) {
  //         splittedSTR[i] = `${splittedSTR[i - 1] + splittedSTR[i]}`;
  //         splittedSTR.splice(i + 1, 1)
  //         splittedSTR.splice(i - 1, 1)
  //       }
  //       if (o - i == 1) {
  //         for (var j = 0; j < splittedSTR.length; j++) {
  //           output.push(Alpha[splittedSTR[j] - 1])
  //           if (output.length == splittedSTR.length) {
  //             console.log(output.join(''));
  //           }
  //         }
  //       }
  //     }
  //   }
  // }

function twoElevator (lift1, from, to) {
    if (lift1 == 1) return 1
    var result1 = lift1 - 1
    var result2 = 0
    if (from > to) {
        result2 = from - to
    } else { //
        result2 = 2 * (to - from)
    }
    if (result1 === result2) return 3
    if (result1 > result2) {
        return 2
    } else {
        return 1
    }
}

function main() {

    var count = readline();

    var inp = [];

    for(var i = 0 ; i < count ; i++) {

        inp = readline().split(' ').map(el => +el);
        var result = twoElevator(inp[0], inp[1], inp[2]);
        print(result);

    }

}
main()

var t = +readline();

for(var i = 0; i< t; i ++) {

      var nums = [];
    var arr = readline().split(' ').map((t) => +t)
    print(TwoElevators(arr[0],arr[1],arr[2]))

}

function TwoElevators(a,b,c){
    a -= 1;
    var test1 = Math.abs(b - c - 1);
    if (test1 < a){
        return '2'
    }else if (test1 > a){
        return '1'
    }else {
        return '3'
    }
}


var count = +readline();
var abspath = [];

for (var i=0; i<count; i++) {
    var cmd = readline();
    cmd = cmd.split(' ');
    if (cmd[0] == 'cd') {
        var path = cmd[1].split('/');
        if (cmd[1][0] == '/') { abspath.length = 0;  }
        for (var j=0; j<path.length; j++) {
            if(path[j] == '..') { abspath.pop(); }
            else { abspath.push(path[j]); }
        }
    }
    else {
        if (!abspath.length){
            print('/');
        } else if (abspath[0] == ''){
            print(abspath.join('/') + '/');
        } else {
            print('/' + abspath.join('/') + '/');
        }
    }
}

var count = +readline(),
	command,
	temp,
	paths = [],
	path = '/',
	ans;

function filterDoublePoint(temp) {
	for (var i = 0, len = temp.length; i < len; i++) {
		if (temp[i] === '..') {
			temp.splice(i - 1, 2);
			i -= 2;
		}
	}
	return temp.join('/');
}

for (var i = 0; i < count; i++) {
	command = readline().split(' ');
	if (command[0] === 'pwd') {
		paths[i] = path;
	} else {
		temp = command[1].split('/');
		if (temp[0]) {
			path += command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		} else {
			path = command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		}
	}
}

print(paths.join('\n'));

var commandsNumber = readline();
var path = [];
var pathStr;
var command;

for(var i = 0; i < commandsNumber; i++){
  command = readline();
  if(command == "pwd"){
    for(var j = 0; j < path.length; j++){
      if(path[j] == "/") path.splice(j,1, "");
    }

    if(path.length == 0) print("/");
    else{
      pathStr = path.join("/");
      pathStr = "/" + pathStr + "/";
      print(pathStr);
    }
  }
  else{
    command = command.split(" ");
    command = command[1];
    command = command.split("/");
    if(command[0] === ""){
      command.splice(0,1);
      for(var j = 0; j < command.length; j++){
        if(command[j] == "..") {command.splice(j-1, 2); j = 0}
      }
      path = command;
    }
    else{
      path = path.concat(command);
      for(var j = 0; j < path.length; j++){
        if(path[j] == "..") {path.splice(j-1, 2); j = 0;}
      }
    }
  }
}

;(function () {

	var n = +readline();

	var p = [];
	var c, t;
	for (var i = 0; i < n; i++) {
		c = readline();

		if (c == 'pwd') {
			print(('/' + p.join('/') + '/').replace(/\/\//g, '/'));
			continue;
		}

		c = c.split(' ')[1].split('/');

		for (var j = 0; j < c.length; j++)
			switch (c[j]) {
				case '':
					p = [];
					break;

				case '..':
					p.pop();
					break;

				default:
					p.push(c[j]);
			}
	}

}).call(this)

var count = +readline(),
	command,
	temp,
	paths = [],
	path = '/',
	ans;

function filterDoublePoint(temp) {
	for (var i = 0, len = temp.length; i < len; i++) {
		if (temp[i] === '..') {
			temp.splice(i - 1, 2);
			i -= 2;
		}
	}
	return temp.join('/');
}

for (var i = 0; i < count; i++) {
	command = readline().split(' ');
	if (command[0] === 'pwd') {
		paths[i] = path;
	} else {
		temp = command[1].split('/');
		if (temp[0]) {
			path += command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		} else {
			path = command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		}
	}
}

write(paths.join('\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++];
}

function print(s){
    process.stdout.write(s);
}

function println(s){
    console.log(s);
}
// Make a Snippet for the code above this and then write your logic in main();

function main(){
    var n = parseInt(readline().split(' ')[0]);
    var path = [];
    var j = 0;

    for(var i=0; i<n; i++){
        var args = readline().split(' ');
        if(args[0] == "pwd"){
            print("/");
            for(j=0; j<path.length; j++){
                print(path[j]);
                print("/");
            }
            print("\n");
        }else{
            if(args[1][0] == '/'){ //absolute
                path = []
                var ops = args[1].split('/');
                for(j=0; j<ops.length; j++){
                    if(ops[j] == ".."){
                        path.pop();
                    }else if(ops[j] != ""){
                        path.push(ops[j]);
                    }
                }
            }else{ //relative
                var ops = args[1].split('/');
                for(j=0; j<ops.length; j++){
                    if(ops[j] == ".."){
                        path.pop();
                    }else if(ops[j] != ""){
                        path.push(ops[j]);
                    }
                }
            }

        }
    }

}

var count = +readline(),
	command,
	temp,
	paths = [],
	path = '/',
	ans;

function filterDoublePoint(temp) {
	for (var i = 0, len = temp.length; i < len; i++) {
		if (temp[i] === '..') {
			temp.splice(i - 1, 2);
			i -= 2;
		}
	}
	return temp.join('/');
}

for (var i = 0; i < count; i++) {
	command = readline().split(' ');
	if (command[0] === 'pwd') {
		paths[i] = path;
	} else {
		temp = command[1].split('/');
		if (temp[0]) {
			path += command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		} else {
			path = command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		}
	}
}

write(paths.join('/n'));

var count = +readline(),
	command,
	temp,
	paths = [],
	path = '/',
	ans;

function filterDoublePoint(temp) {
	for (var i = 0, len = temp.length; i < len; i++) {
		if (temp[i] === '..') {
			temp.splice(i - 1, 2);
			i -= 2;
		}
	}
	return temp.join('/');
}

for (var i = 0; i < count; i++) {
	command = readline().split(' ');
	if (command[0] === 'pwd') {
		paths[i] = path;
	} else {
		temp = command[1].split('/');
		if (temp[0]) {
			path += command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		} else {
			path = command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		}
	}
}

print(paths.join('/n'));

var commandsNumber = readline();
var path = [""];
var pathStr;
var command;

for(var i = 0; i < commandsNumber; i++){
  command = readline();
  if(command == "pwd"){
    for(var j = 0; j < path.length; j++){
      if(path[j] == "/") path.splice(j,1, "");
    }

    if((path[0] == "" && path.length == 1) || path.length == 0) print("/");
    else{
      pathStr = path.join("/");
      pathStr = "/" + pathStr + "/";
      print(pathStr);
    }
  }
  else{
    command = command.split(" ");
    command = command[1];
    command = command.split("/");
    if(command[0] === ""){
      command.splice(0,1);
      for(var j = 0; j < command.length; j++){
        if(command[j] == "..") {command.splice(j-1, 2); j = 0}
      }
      path = command;
    }
    else{
      path = path.concat(command);
      for(var j = 0; j < path.length; j++){
        if(path[j] == "..") {path.splice(j-1, 2); j = 0;}
      }
    }
  }
}

'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(s){
    process.stdout.write(s);
}

function println(s){
    console.log(s);
}
// Make a Snippet for the code above this and then write your logic in main();

function main(){
    var n = parseInt(readline().split(' ')[0]);
    var path = [];
    var j = 0;

    for(var i=0; i<n; i++){
        var args = readline().split(' ');
        if(args[0] == "pwd"){
            print("/");
            for(j=0; j<path.length; j++){
                print(path[j]);
                print("/");
            }
            print("\n");
        }else{
            var ops = args[1].split('/');
            for(j=0; j<ops.length; j++){
                if(ops[j] == ".."){
                    path.pop();
                }else if(ops[j] !== ""){
                    path.push(ops[j]);
                }
            }
        }
    }

}

'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(s){
    process.stdout.write(s);
}

function println(s){
    console.log(s);
}
// Make a Snippet for the code above this and then write your logic in main();

function main(){
    var n = parseInt(readline().split(' ')[0]);
    var path = [];
    var j =0;

    for(var i=0; i<n; i++){
        var args = readline().split(' ');
        if(args[0] == "pwd"){
            print("/");
            for(j=0; j<path.length; j++){
                print(path[j]);
                print("/");
            }
            print("\n");
        }else{
            var ops = args[1].split('/');
            for(j=1; j<ops.length; j++){
                if(ops[j] == ".."){
                    path.pop();
                }else{
                    path.push(ops[j]);
                }
            }
        }
    }

}

;(function () {

	var n = +readline();

	var p = [];
	var c, t;
	for (var i = 0; i < n; i++) {
		c = readline();

		if (c == 'pwd') {
			print('/' + p.join('/'));
			continue;
		}

		c = c.split(' ')[1].split('/');

		for (var j = 0; j < c.length; j++)
			switch (c[j]) {
				case '':
					p = [];
					break;

				case '..':
					p.pop();
					break;

				default:
					p.push(c[j]);
			}
	}

}).call(this)

;(function () {

	var n = +readline();

	var p = [];
	var c, t;
	for (var i = 0; i < n; i++) {
		c = readline();

		if (c == 'pwd') {
			print('/' + p.join('/') + '/');
			continue;
		}

		c = c.split(' ')[1].split('/');

		for (var j = 0; j < c.length; j++)
			switch (c[j]) {
				case '':
					p = [];
					break;

				case '..':
					p.pop();
					break;

				default:
					p.push(c[j]);
			}
	}

}).call(this)

var count = +readline();
var abspath = [];

for (var i=0; i<count; i++) {
    var cmd = readline();
    cmd = cmd.split(' ');
    if (cmd[0] == 'cd') {
        var path = cmd[1].split('/');
        if (cmd[1][1] == '/') { abspath = [];  }
        for (var j=0; j<path.length; j++) {
            if(path[j] == '..') { abspath.pop(); }
            else { abspath.push(path[j]); }
        }
    }
    else {
        if (!abspath.length){
            print('/');
        } else if (abspath[0] == ''){
            print(abspath.join('/') + '/');
        } else {
            print('/' + abspath.join('/') + '/');
        }
    }
}

var count = +readline();
var abspath = [];

for (var i=0; i<count; i++) {
    var cmd = readline();
    cmd = cmd.split(' ');
    if (cmd[0] == 'cd') {
        var path = cmd[1].split('/');
        if (cmd[1][1] == '/') { abspath = []; }
        for (var j=0; j<path.length; j++) {
            if(path[j] == '..') { abspath.pop(); }
            else { abspath.push(path[j]); }
        }
    }
    else {
        print(abspath.join('/') + '/');
    }
}

var count = +readline();
var abspath = [];

for (var i=0; i<count; i++) {
    var cmd = readline();
    cmd = cmd.split(' ');
    if (cmd[0] == 'cd') {
        var path = cmd[1].split('/');
        if (cmd[1][1] == '/') { abspath = [];  }
        for (var j=0; j<path.length; j++) {
            if(path[j] == '..') { abspath.pop(); }
            else { abspath.push(path[j]); }
        }
    }
    else {
        if (abspath[0] == ''){
            print(abspath.join('/') + '/');
        } else {
            print('/' + abspath.join('/') + '/');
        }
    }
}

var count = +readline(),
	command,
	temp,
	paths = [],
	path = '/';

function filterDoublePoint(temp) {
	for (var i = 0, len = temp.length; i < len; i++) {
		if (temp[i] === '..') {
			temp.splice(i - 1, 2);
			i -= 2;
		}
	}
	return temp.join('/');
}

for (var i = 0; i < count; i++) {
	command = readline().split(' ');
	if (command[0] === 'pwd') {
		paths[i] = path;
	} else {
		temp = command[1].split('/');
		if (temp[0]) {
			path += command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		} else {
			path = command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		}
	}
}

for (var i = 0, len = paths.length; i < len; i++) {
	print(paths[i]);
}

var count = +readline(),
	command,
	temp,
	paths = [],
	path = '/';

function filterDoublePoint(temp) {
	for (var i = 0, len = temp.length; i < len; i++) {
		if (temp[i] === '..') {
			temp.splice(i - 1, 2);
			i -= 2;
		}
	}
	return temp.join('/') + '/';
}

for (var i = 0; i < count; i++) {
	command = readline().split(' ');
	if (command[0] === 'pwd') {
		paths[i] = path;
	} else {
		temp = command[1].split('/');
		if (temp[0]) {
			path += command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		} else {
			path = command[1] + '/';
			path = filterDoublePoint(path.split('/'));
		}
	}
}

for (var i = 0, len = paths.length; i < len; i++) {
	print(paths[i]);
}


const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var s = readline();
  var l = s.indexOf('ab');

  if (l < 0)
    l = s.indexOf('ba');

  var r = l >= 0? l + 1: -1;

  if (l >= 0) {
    r++;
    l++;
  }

  print(l, r);
}

var t = readline();
for (var i = 0; i < t; ++i) {
  var n = readline(),
    input = readline().split("") , counter = 1;
    for(var j = 0 ; j < n - 1 ; ++j){
        if(input[j] != input[j + 1]){
            print(parseInt(input.indexOf(input[j]) + 1) + ' ' + parseInt(input.indexOf(input[j + 1]) + 1));
            break;
        }
        else{
            input[j] = '';
            counter++;
        }
    }
    if(counter == n){
        print(`-1 -1`);
    }
}

function run(){
    var n = readline();
    var s = readline();
    for(var i = 1; i < n; i++){
        if(s[i] != s[i - 1]){
            print(i, i + 1);
            return;
        }
    }
    print(-1, -1);
}

var tc = readline();
while(tc--) {
    run();
}

var t=+readline();
while(t--){
    var n=+readline();
    var s=readline();
    var flag=0;
    for(var i=0; i<n; i++){
        if(s[i]=='a' && s[i+1]=='b'){
            print(i+1,i+2);
            flag=1;
            break;
        }
        if(s[i]=='b' && s[i+1]=='a'){
            print(i+1, i+2);
            flag=1;
            break;
        }
    }
    if(flag===0){
        print(-1,-1);
    }

}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var check = false;
            var n = lines[i].split('');
            if(e == 1){
                console.log(-1, -1);
            }else{
                for(j = 0; j < e-1; j++){
                    if(n[j] != n[j + 1]){
                        console.log(j + 1, j + 2);
                        check = true;
                        break;
                    }
                }
                if(!check){
                    console.log(-1, -1);
                }
            }
        }
    }
});

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++].trim()
        console.log(solve(n, str).join(' '))
    }
// })()
})

function solve(n, str) {
    const sum = []
    for (let i = 0; i < str.length; i++) {
        const [a, b] = i ? sum[i - 1] : [0, 0]
        if (str[i] === 'a') {
            sum[i] = [a + 1, b]
        } else {
            sum[i] = [a, b + 1]
        }
    }
    for (let i = 0; i < str.length; i++) {
        const [a1, b1] = i ? sum[i - 1] : [0, 0]
        for (let j = i; j < str.length; j++) {
            const [a2, b2] = sum[j]
            if (a2 - a1 === b2 - b1) return [i + 1, j + 1]
        }
    }
    return [-1, -1]
}

//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();
	while(hasNext()){
		var N = nextInt();
		var S = next();
		var L = -1;
		var R = -1;
		for(var i = 0; i < N; i++){
			for(var j = i; j < N; j++){
				var AC = 0;
				var BC = 0;
				for(var k = i; k <= j; k++){
					if(S[k] == "a"){
						AC++;
					}else{
						BC++;
					}
				}
				if(AC == BC){
					L = i + 1;
					R = j + 1;
				}
			}
		}
		myout(L + " " + R);
	}
}

var t = readline();
for (var i = 0; i < t; ++i) {
  var n = readline(),
    input = readline().split("") , counter = 1;
    for(var j = 0 ; j < n - 1 ; ++j){
        if(input[j] != input[j + 1]){
            print(parseInt(input.indexOf(input[j]) + 1) + ' ' + parseInt(input.indexOf(input[j + 1]) + 1));
            break;
        }
        else{
            counter++;
        }
    }
    if(counter == n){
        print(`-1 -1`);
    }
}

var t = readline();
for (var i = 0; i < t; ++i) {
  var n = readline(),
    input = readline().split("") , counter = 1;
    for(var j = 0 ; j < n - 1 ; ++j){
        if(input[j] != input[j + 1]){
            print(input.indexOf(input[j]) + ' ' + input.indexOf(input[j + 1]));
            break;
        }
        else{
            counter++;
        }
    }
    if(counter == n){
        print(`-1 -1`);
    }
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var s = readline();
  var l = s.indexOf('ab');

  if (l < 0)
    l = s.indexOf('ba');

  var r = l >= 0? l + 1: -1;

  print(++l, ++r);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var s = readline();
  var l = s.indexOf('ab');

  if (l < 0)
    l = s.indexOf('ba');

  var r = l >= 0? l + 1: -1;

  print(l, r);
}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        var n = lines[i].split('');
        if(i % 2 == 1){
            e = n[0];
        }else{
            var check = false;
            if(e == 1){
                console.log(-1, -1);
            }else{
                for(j = 0; j < e-1; j++){
                    if(n[j] != n[j + 1]){
                        console.log(j + 1, j + 2);
                        check = true;
                        break;
                    }
                }
                if(!check){
                    console.log(-1, -1);
                }
            }
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        var n = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            e = n[0];
        }else{
            var check = false;
            if(e == 1){
                console.log(-1, -1);
            }else{
                for(j = 0; j < e-1; j++){
                    if(n[j] != n[j + 1]){
                        console.log(j + 1, j + 2);
                        check = true;
                        break;
                    }
                }
                if(!check){
                    console.log(-1, -1);
                }
            }
        }
    }
});

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++].trim()
        console.log(solve(n, str).join(' '))
    }
// })()
})

function solve(n, str) {
    const sum = []
    for (let i = 0; i < str.length; i++) {
        const [a, b] = i ? sum[i - 1] : [0, 0]
        if (str[i] === 'a') {
            sum[i] = [a + 1, b]
        } else {
            sum[i] = [a, b + 1]
        }
    }
    for (let i = 0; i < str.length; i++) {
        const [a1, b1] = i ? sum[i - 1] : [0, 0]
        for (let j = i; j < str.length; j++) {
            const [a2, b2] = sum[j]
            if (a2 - a1 === b2 - b1) return [i, j]
        }
    }
    return [-1, -1]
}


function getInt(num){
    return parseInt(num, 10)
}

var t = parseInt(readline(), 10);

for(var i = 0; i < t; i++){
    var line1 = readline().split(' ').map(getInt);
    var line2 = readline().split(' ').map(getInt);
    print(solution(line1[0], line2));
}
function solution(n, arr){
    if(n === 1){
        return 0;
    }
    if(isMInfinite(arr)){
        return 0;
    }
    var c;
    var j = 1;
    while(arr[j] < arr[j-1] && j < n){
        j++;
    }
    /*if(j === n){
        return -1;
    }*/
    c = arr[j] - arr[j-1];
    var k = 1;

    while(arr[k] > arr[k-1] && k < n){
        k++;
    }
    var m = c + arr[k-1] - arr[k];
    if(checkArr(arr,c,m, n)){
        return m + ' ' + c;
    }else{
        return -1;
    }

}
function isMInfinite(arr){
    var c = arr[1] - arr[0];

    return !arr.some(function(item, i){
        return (i && item - arr[i-1] !== c);
    })
}

function checkArr(arr,c,m, n){
    if(arr[0] >= m){
        return false;
    }
    for(var i = 1; i < n; i++){
        if(arr[i] !== (arr[i-1] + c) % m){
            return false;

        }
    }
    return true;
}

'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();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    //   var a = new Array(n)
    //   var marked = new Array(n).fill(false)
    //   var found = new Array(n).fill(false)
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });

    var allEqual = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] !== a[i + 1]) allEqual = false
    }

    if (allEqual) return console.log(0)

    var diff = 0
    var diff1 = 0
    var first = true
    var first1 = true
    var isExist = true
    var isExist1 = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] < a[i + 1]) {
        if (first) {
          diff = a[i + 1] - a[i]
          first = false
          continue
        }
        if (a[i + 1] - a[i] !== diff) isExist = false
      } else {
        if (first1) {
          diff1 = a[i+1] - a[i]
          first1 = false
          continue
        }
        if (a[i+1] - a[i] !== diff1) isExist1 = false

      }
    }

    if (!isExist || !isExist1) return console.log(-1)

    var value = diff
    var mod1 = diff - diff1
    // console.log(mod1, diff, diff1)

    // check all raise
    var allRaise = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] + diff !== a[i + 1]) {
        allRaise = false
      }
    }
    if (allRaise) return console.log(0)
    // check all raise

    // check all raise
    var allDown = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] + diff1 !== a[i + 1]) {
        allDown = false
      }
    }
    if(allDown){
      console.log(0)
      return
    }
    // check all raise

// console.log(mod1, diff1, diff)
    var exist = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] >= mod1) exist = false
      if ((a[i] + value) % mod1 !== a[i + 1]) {
        exist = false
        // console.log(a[i], a[i+1])
      }
    }
    if (!exist) return console.log(-1)
    console.log(mod1, value)
  })
}

function find(value, a) {
  var l = -1
  var r = a.length
  while (r > l + 1) {
    var m = Math.floor((r + l) / 2)
    // console.log(a[m], f, l, r)
    if (a[m] <= value) l = m
    if (a[m] > value) r = m
  }
  return r
}

'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();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    //   var a = new Array(n)
    //   var marked = new Array(n).fill(false)
    //   var found = new Array(n).fill(false)
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });

    var allEqual = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] !== a[i + 1]) allEqual = false
    }

    if (allEqual) return console.log(0)

    var diff = 0
    var diff1 = 0
    var first = true
    var first1 = true
    var isExist = true
    var isExist1 = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] < a[i + 1]) {
        if (first) {
          diff = a[i + 1] - a[i]
          first = false
          continue
        }
        if (a[i + 1] - a[i] !== diff) isExist = false
      } else {
        if (first1) {
          diff1 = a[i+1] - a[i]
          first1 = false
          continue
        }
        if (a[i+1] - a[i] !== diff1) isExist1 = false

      }
    }

    if (!isExist || !isExist1) return console.log(-1)

    var value = diff
    var mod1 = diff - diff1
    // console.log(mod1, diff, diff1)

    // check all raise
    var allRaise = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] + diff !== a[i + 1]) {
        allRaise = false
      }
    }
    if (allRaise) return console.log(0)
    // check all raise

    // check all raise
    var allDown = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] + diff1 !== a[i + 1]) {
        allDown = false
      }
    }
    if(allDown){
      console.log(a[0]+1, a[0]+1+diff1)
      return
    }
    // check all raise

    var exist = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] >= mod1) exist = false
      if ((a[i] + value) % mod1 !== a[i + 1]) {
        exist = false
        // console.log(a[i], a[i+1])
      }
    }
    if (!exist) return console.log(-1)
    console.log(mod1, value)
  })
}

function find(value, a) {
  var l = -1
  var r = a.length
  while (r > l + 1) {
    var m = Math.floor((r + l) / 2)
    // console.log(a[m], f, l, r)
    if (a[m] <= value) l = m
    if (a[m] > value) r = m
  }
  return r
}

'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();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    //   var a = new Array(n)
    //   var marked = new Array(n).fill(false)
    //   var found = new Array(n).fill(false)
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });

    var allEqual = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] !== a[i + 1]) allEqual = false
    }

    if(allEqual) return  console.log(0)

    var diff
    var first= true
    var isExist = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] < a[i + 1]) {
        if(first){
          diff = a[i + 1] - a[i]
          first = false
          continue
        }
        if(a[i + 1] - a[i] !== diff) isExist = false
      }
    }
    var value = diff
    // console.log(diff)
    if (!isExist) return console.log(-1)

    // check all raise
    var allRaise = true
    for (let i = 0; i < n-1; i++) {
      if (a[i] + value !== a[i + 1]) {
        allRaise = false
      }
    }
    if (allRaise) return console.log(0)

    var mod1 = -1
    for (let i = 0; i < n - 1; i++) {
      if (a[i] > a[i + 1]) mod1 = a[i] + value - a[i+1]
    }

    var exist = true
    for (let i = 0; i < n-1; i++) {
      if(a[i] >= mod1) exist = false
      if ((a[i] + value) % mod1 !== a[i + 1]) {
        exist = false
        // console.log(a[i], a[i+1])
      }
    }
    if (!exist) return console.log(-1)
    console.log(mod1, value)
  })
}

function find(value, a) {
  var l = -1
  var r = a.length
  while (r > l + 1) {
    var m = Math.floor((r + l) / 2)
    // console.log(a[m], f, l, r)
    if (a[m] <= value) l = m
    if (a[m] > value) r = m
  }
  return r
}

'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();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    //   var a = new Array(n)
    //   var marked = new Array(n).fill(false)
    //   var found = new Array(n).fill(false)
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });

    var allEqual = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] !== a[i + 1]) allEqual = false
    }

    if(allEqual) return  console.log(0)

    var diff
    var first= true
    var isExist = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] < a[i + 1]) {
        if(first){
          diff = a[i + 1] - a[i]
          first = false
          continue
        }
        if(a[i + 1] - a[i] !== diff) isExist = false
      }
    }
    var value = diff
    // console.log(diff)
    if (!isExist) return console.log(-1)

    var mod1
    for (let i = 0; i < n - 1; i++) {
      if (a[i] > a[i + 1]) mod1 = a[i] + value - a[i+1]
    }

    var exist = true
    for (let i = 0; i < n-1; i++) {
      if(a[i] >= mod1) exist = false
      if ((a[i] + value) % mod1 !== a[i + 1]) {
        exist = false
        // console.log(a[i], a[i+1])
      }
    }
    if (!exist) return console.log(-1)
    console.log(mod1, value)
  })
}

function find(value, a) {
  var l = -1
  var r = a.length
  while (r > l + 1) {
    var m = Math.floor((r + l) / 2)
    // console.log(a[m], f, l, r)
    if (a[m] <= value) l = m
    if (a[m] > value) r = m
  }
  return r
}

function solution(n, arr){
    if(n === 1){
        return 0;
    }
    if(isMInfinite(arr)){
        return 0;
    }
    var c;
    var j = 1;
    while(arr[j] < arr[j-1] && j < n){
        j++;
    }
    c = arr[j] - arr[j-1];
    var k = 1;

    while(arr[k] > arr[k-1] && k < n){
        k++;
    }
    var m = c + arr[k-1] - arr[k];
    if(checkArr(arr,c,m, n)){
        return m + ' ' + c;
    }else{
        return -1;
    }

}
function isMInfinite(arr){
    var c = arr[1] - arr[0];

    return !arr.some(function(item, i){
        return (i && item - arr[i-1] !== c);
    })
}

function checkArr(arr,c,m, n){
    if(arr[0] >= m){
        return false;
    }
    for(var i = 1; i < n; i++){
        if(arr[i] !== (arr[i-1] + c) % m){
            return false;

        }
    }
    return true;
}