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, x = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0], x = k[1];
        }else{
            var min = 0, max = 0, total = 0;
            for(j = 0; j < n; j++){
                total += k[j];
                max += Math.floor(k[j] / x);
                if(k[j] % x !== 0){
                    max++;
                }
            }
            min += Math.floor(total / x);
            if(total % x !== 0){
                min++;
            }
            console.log(min, max);
        }
    }
});

const solve = (n, x, a) => {
    let max = sum = 0;
    for (const item of a) {
        sum += item;
        max += Math.ceil(item / x);
    }
    let min = Math.ceil(sum / x);
    console.log(min, max);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            let data = input.slice(i, i + 2);
            solve(data[0][0], data[0][1], data[1]);
            i += 2;
        }
    });
};

main()

const solve = (n, x, a) => {
    let max = 0;
    let sum = a.reduce((x, y) => x + y);
    for (const item of a) {
        max += Math.ceil(item / x);
    }
    let min = Math.ceil(sum / x);
    console.log(min, max);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            let data = input.slice(i, i + 2);
            solve(data[0][0], data[0][1], data[1]);
            i += 2;
        }
    });
};

main()

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

String.prototype.parseInt = (e) => parseInt(e);

let meow=-1,n,x,t;
let sumall,sum2;

function foo(line) {
	if(meow==-1) { n=-1; x=-1; return meow=parseInt(line); }
	if(n==-1) {
		let t = line.split(' ');
		n = t[0]-0;
		x = t[1]-0;

		t=n;
		sumall=0;
		sum2=0;
		return;
	} else {
		let zz = line.split(' ');
		for(let i=0;i<zz.length;i++) {
			let val = zz[i]-0;
			"console.warn(val);"
			sumall+=val;
			sum2+=Math.floor((val+x-1)/x);
		}
			"console.warn('nx=',n,x);"
		if(0==0) { console.log(Math.floor((sumall+(x-1))/x),' ',sum2); }
		n=-1; x=-1;
	}
}

// multi line input
readline.on('line', line => foo(line));

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, x = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0], x = k[1];
        }else{
            var min = 0, max = 0, sum = 0;
            for(j = 0; j < n; j++){
                sum += k[j];
                max += Math.floor(k[j] / x);
                if(k[j] % x !== 0){
                    max++;
                }
            }
            min = Math.floor(sum / x);
            if(sum % x !== 0){
                min++;
            }
            console.log(min, max);
        }
    }
});

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

//-----------main fucntion-----------

function main() {
    var tc = parseInt(readline());
    while (tc--) {
        var ar = readline().split(" ").map(e => +e);
        var n = ar[0], x = ar[1];
        var sum = 0, maxB = 0;
        var a = readline().split(" ").map(e => +e).map(e=>{
           sum+=e;
           maxB+=Math.ceil(e/x);
        });
        var minB = Math.ceil(sum/x);
        console.log(minB + " " + maxB);
    }

}

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

//-----------main function-----------

function main() {

    var t = parseInt(readline());

while (t--) {
  var ar = readline().split(' ').map(n => parseInt(n));
  var arr = readline().split(' ').map(n => parseInt(n));

  var n = ar[0];
  var x = ar[1];

  var minimal, maximal;

  const beauty = (arrayInput, divisor) => {
    var result = 0;
    arrayInput.forEach(element => {
      result = result + Math.ceil(element / divisor);
    });

    return result;
  }

  minimal = beauty(arr, x);

  for (var i = arr.length - 1; i >= 1; i--) {
    arr[i - 1] = arr[i - 1] + arr[i];
    arr.pop();
  }

  maximal = beauty(arr, x);

  print(maximal + ' '+ minimal);

}

}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const [len, x] = readLine().split(' ').map(Number);
		let [sum, divSum] = [0, 0];
		readLine()
			.split(' ')
			.forEach((n) => {
				n = Number(n);
				sum += n;
				divSum += Math.ceil(n / x);
			});
		console.log(`${Math.ceil(sum / x)} ${divSum}`);
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [n, x] = rna();
		const a = rna();

		let mn = 0, mx = 0;
		for (let i = 0; i < n; i++) {
			mn += a[i];
			mx += Math.ceil(a[i]/x);
		}
		mn = Math.ceil(mn/x);

		console.log(mn, mx);
	}
}

'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 x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var [n,xx] = readline().split(' ').map(x => Number(x));
        var sum = 0
        var sum2 = 0
        var array = readline().split(' ').map(x => {
            sum+=Number(x)
            sum2+=Math.ceil(Number(x)/xx)
            Number(x)
        });
        console.log(Math.ceil(sum/xx),  sum2)
        // console.log(sum2)

    })

}

const { EOL } = require('os');

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

function main() {
    const lines = input.trim().split(EOL).map(line => line.trim());
    for (let i = 1; i < lines.length - 1; i += 2) {
        let ints = lines[i].split(' ').map(Number);
        let arr =  lines[i+1].split(' ').map(Number);
        beauty(ints, arr);
    }
}

function beauty(ints, arr) {
    let [n, x] = ints;
    let max = b(arr, x);
    let min = b([arr.reduce((a, c) => a + c, 0)], x);
    console.log(min, max)
}

function b(arr, x) {
    return arr.reduce((a, c) => a + Math.ceil(c / x), 0);
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
    inputString += data;
})
process.stdin.on('end', function (){
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => str.trim());
    main();
})
function readLine(){
    return inputString[currentLine++];
}
function main(){
    let t = +readLine();
    while(t--){
        const [n, x] = readLine().split(' ').map(Number);
        let [mn, mx] = [0, 0];
        readLine()
            .split(' ')
            .forEach((val) => {
                val = Number(val);
                mn += val;
                mx += Math.ceil(val / x);
            });
        mn = Math.ceil(mn / x);
        console.log(`${mn} ${mx}`);
    }
}

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

    const t = parseInt(lines[0]);

    for (let i = 1; i <= t * 2; i += 2) {
        let split = lines[i].split(' ');
        const n = parseInt(split[0]);
        const x = parseInt(split[1]);

        const arr = lines[i + 1].split(' ').map(num => parseInt(num));
        solve(n, x, arr);
    }
});

function solve(n, x, arr) {
    let max = 0;
    let sum = 0;

    for (let i = 0; i < n; i++) {
        sum += arr[i];
        max += Math.ceil(arr[i] / x);
    }

    const min = Math.ceil(sum / x);

    console.log(min, max);
}

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var x = nextInt();
		var list = nextIntArray(N);
		var sum = 0;
		var max = 0;
		for(var j = 0; j < N; j++){
			sum += list[j];
			max += Math.ceil(list[j] / x);
		}
		myout(Math.ceil(sum / x) + " " + max);
	}
}

r = readline

for(k = r(); k--; ) {

    x = r().split(' ')[1]
    a = r().split(' ')
    ma = 0; mi = 0;
    a.map(a => {ma += Math.ceil(a/x); mi-=-a;})
    print(Math.ceil(mi/x)+" "+ma)
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;
  var min = 0;

  for (var k = 0, z = 0; k < n; k++, z += 2) {
    max += Math.ceil(a[k] / x);
    min += a[k];
  }

  print(Math.ceil(min / x), max);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;
  var min = 0;

  for (var k = 0, z = 0; k < n; k++, z += 2) {
    max += Math.ceil(a[k] / x);
  }

  for (var z = 0; z < n; z += 2) {
    min += a[z] + (a[z+1] || 0);
  }

  print(Math.ceil(min / x), max);
}

"use strict"
let t = +readline ();
while (t--)
{
  let count = 0, count2 = 0;
  let list = readline ().split (' ').map (i => +i);
  let arr = readline ().split (' ').map (i => +i);
    for (let j of arr)
    {
      count += j;
      count2 += Math.ceil (j / list[1]);
    }
  print (Math.ceil (count / list[1]), count2);
}

"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let input = readline().split(" ").map(x => parseInt(x));
    let n = input[0];
    let x = input[1];
    let arr = readline().split(" ").map(x => parseInt(x));

    let sum = 0;
    let sum2 = 0;

    for(let j = 0; j < n; j++){
        sum += arr[j];
        sum2 += Math.ceil(arr[j] / x)
    }

    print(Math.ceil(sum / x) + " " + (sum2));
}

var tc = parseInt(readline());
while (tc-- > 0) {
    var Ar = readline().split(' ').map(x => +x);
    var n = Ar[0], m = Ar[1];

    var sum = 0, res = 0;
    var arr = readline().split(' ').map(x => +x);
    for (var i = 0; i < arr.length; i++){
        sum += arr[i];
        res += Math.ceil(arr[i] / m);
    }
    print(Math.ceil(sum / m), res);
}

const solve = (n, x, a) => {
    let sum = a.reduce((x, y) => x + y);
    let restT = 0;
    for (const item of a) {
        let tmp = item / x - Math.floor(item / x);
        restT += item % n;
    }
    let min = Math.round(sum / n);
    let max = Math.round(sum / n) + Math.floor(restT / n);
    console.log(min, max);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            let data = input.slice(i, i + 2);
            solve(data[0][0], data[0][1], data[1]);
            i += 2;
        }
    });
};

main()

const solve = (n, x, a) => {
    let sum = a.reduce((x, y) => x + y);
    let restT = 0;
    for (const item of a) {
        restT += item % n;
    }
    let min = Math.floor(sum / n);
    let max = Math.floor(sum / n) + Math.floor(restT / n);
    console.log(min, max);
}

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            let data = input.slice(i, i + 2);
            solve(data[0][0], data[0][1], data[1]);
            i += 2;
        }
    });
};

main()

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

String.prototype.parseInt = (e) => parseInt(e);

let meow=-1,n,x,t;
let sumall,sum2;

function foo(line) {
	if(meow==-1) { n=-1; x=-1; return meow=parseInt(line); }
	if(n==-1) {
		let t = line.split(' ');
		n = t[0]-0;
		x = t[1]-0;

		t=n;
		sumall=0;
		sum2=0;
		return;
	} else {
		let zz = line.split(' ');
		for(let i=0;i<zz.length;i++) {
			let val = zz[i]-0;
			"console.warn(val);"
			sumall+=val;
			sum2+=((val+x-1)/x) | 0;
		}
			"console.warn('nx=',n,x);"
		if(0==0) { console.log(((sumall+(x-1))/x)|0,' ',sum2); }
		n=-1; x=-1;
	}
}

// multi line input
readline.on('line', line => foo(line));

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

String.prototype.parseInt = (e) => parseInt(e);

let meow=-1,n,x,t;
let sumall,sum2;

function foo(line) {
	if(meow==-1) { n=-1; x=-1; return meow=parseInt(line); }
	if(n==-1) {
		let t = line.split(' ');
		n = t[0]-0;
		x = t[1]-0;

		t=n;
		sumall=0;
		sum2=0;
		return;
	} else {
		let zz = line.split(' ');
		for(let i=0;i<n;i++) {
			let val = zz[i]-0;
			"console.warn(val);"
			sumall+=val;
			sum2+=((val+x-1)/x) | 0;
		}
			"console.warn('nx=',n,x);"
		if(0==0) { console.log(((sumall+(x-1))/x)|0,' ',sum2); }
		n=-1; x=-1;
	}
}

// multi line input
readline.on('line', line => foo(line));

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

//-----------main fucntion-----------

function main() {
    var tc = parseInt(readline());
    while (tc--) {
        var ar = readline().split(" ").map(e => +e);
        var n = ar[0], x = ar[1];
        var sum = 0, maxB = 0;
        var a = readline().split(" ").map(e => +e).map(e=>{
            sum+=e;maxB+=parseInt(e/x);if(e%x)maxB++
        });
        var minB = parseInt(sum / x);
        if (sum % x) minB++;
        console.log(minB + " " + maxB);
    }

}

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

//-----------main function-----------

function main() {

    var t = parseInt(readline());

while (t--) {
  var ar = readline().split(' ').map(n => parseInt(n));
  var arr = readline().split(' ').map(n => parseInt(n));

  var n = ar[0];
  var x = ar[1];

  var minimal, maximal;

  const beauty = (arrayInput, divisor) => {
    var result = 0;
    arrayInput.forEach(element => {
      result = result + Math.ceil(element / divisor);
    });

    return result;
  }

  minimal = beauty(arr, x);

  for (var i = arr.length - 1; i >= 1; i--) {
    arr[i - 1] = arr[i - 1] + arr[i];
    arr.pop();
  }

  maximal = beauty(arr, x);

  print(maximal, minimal);

}

}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const [len, x] = readLine().split(' ').map(Number);
		let [sum, divSum] = [0, 0];
		readLine()
			.split(' ')
			.forEach((n) => {
				n = Number(n);
				sum += n;
				divSum += Math.ceil(n / x);
			});
		console.log(`${Math.floor(sum / x)} ${divSum}`);
	}
}

r = readline

for(k = r(); k--; ) {

    x = r().split(' ')[1]
    a = r().split(' ')
    ma = 0; mi = 0;
    a.map(a => {ma += Math.ceil(a/x); mi-=-a;})
    print(ma + " " + Math.ceil(mi/x))
}

r = readline

for(k = r(); k--; ) {

    x = r().split('')[1]
    a = r().split('')
    ma = 0; mi = 0;
    a.map(a => {ma += Math.ceil(a/x); mi-=-a;})
    print(ma + " " + Math.ceil(mi/x))
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;
  var min = 0;

  for (var k = 0; k < n; k++) {
    max += Math.ceil(a[k] / x);
  }

  for (var z = 0; z < n; z += 2) {
    min += Math.ceil((a[z] + (a[z+1] || 0)) / x);
  }

  print(min, max);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;
  var min = 0;

  for (var k = 0; k < n; k++) {
    max += Math.ceil(a[k] / x);
  }

  for (var z = 0; z < n; z += 2) {
    min += (a[z] + (a[z+1] || 0)) / x;
  }

  print(min.toFixed(0), max);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;
  var min = 0;

  for (var k = 0; k < n; k++) {
    max += Math.ceil(a[k] / x);
  }

  for (var z = 0; z < n; z += 2) {
    min += (a[z] + (a[z+1] || 0)) / x;
  }

  print(Math.ceil(min), max);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;
  var min = 0;
  var temp = [];

  for (var k = 0; k < n; k++) {
    max += Math.ceil(a[k] / x);
  }

  for (var z = 0, d = 0; z < n - 1; z++) {
    if (a[d+1]) {
      min += (a[d] + a[d+1]) / x;
    } else {
      min += a[d] / x;
    }

    d += 2;
  }

  print(min, max);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = readline().split(' ').map(i => +i);
  var n = l[0];
  var x = l[1];
  var a = readline().split(' ').map(i => +i);
  var max = 0;

  for (var k = 0; k < a.length; k++) {
    max += Math.ceil(a[k] / x);
  }

  print(Math.max(...a) - Math.min(...a), max);
}

"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let input = readline().split(" ").map(x => parseInt(x));
    let n = input[0];
    let x = input[1];
    let arr = readline().split(" ").map(x => parseInt(x));

    let sum = 0;
    let temp = 0;

    for(let j = 0; j < n; j++){
        sum += arr[j];
        if(arr[j] % x !== 0){
            temp++;
        }
    }
    let min = Math.ceil(sum / x);
    print(min + " " + (min + temp));
}

"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let input = readline().split(" ").map(x => parseInt(x));
    let n = input[0];
    let x = input[1];
    let arr = readline().split(" ").map(x => parseInt(x));

    let min = 0;
    let temp = 0;

    for(let j = 0; j < n; j++){
        min += Math.ceil(arr[j] / x);
        if(arr[j] % x !== 0){
            temp++;
        }
    }
    print(min + " " + (min + temp));
}


const input = Number(readline());
print(input === 1 ? "-1" : `${input} ${input + 1} ${input * (input + 1)}`);

const input = Number(readline());
print(`${input} ${input + 1} ${input * (input + 1)}`);


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

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

process.stdin.on('end', () => {
  arr = arr.split('\n')

  const no = parseInt(arr.shift())
  const cans = arr[0].split(' ')
  const map = new Map()

  for(let i = 1; i <= no; i++) {
    map.set(i, parseInt(cans[i - 1]))
  }

  const map2 = new Map([...map.entries()].sort((a, b) => b[1] - a[1]))
  var sum = 0
  var i = 0
  map2.forEach((v) => {
    sum += v * i + 1
    i++
  })

  console.log(sum)

  const keys = map2.keys()
  let result = keys.next()
  while(!result.done) {
    process.stdout.write(result.value + ' ')
    result = keys.next()
  }
  console.log()
})

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

    function foo (data) {

        let list = [...data];

        let pushCount = 0;
        let order = []
        let i = 0;
        while (i < list.length) {
            let max = Math.max(...list);
            let index = list.indexOf(max);

            pushCount += (list[index] * i + 1);
            order.push(index + 1);
            list[index] = 0;

            i++;
        }

        return {pushCount, order: order.join(' ')};
    }

    let count = +lines[0];
    let data = lines[1].split(' ').map(Number);

    let result = foo(data);

    let answer = '';
    answer += result.pushCount + "\n";
    answer += result.order;

    console.log(answer);
})

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((x, i) => {
    return {
      val: Number(x),
      idx: i + 1,
    }
  });

  arr.sort((a, b) => b.val - a.val);
  let ans = 0;
  const ansArr = [];

  for (let i = 0; i < arr.length; i++) {
    ans += i * arr[i].val + 1;
    ansArr.push(arr[i].idx);
  }

  console.log(ans);
  console.log(ansArr.join(' '));

  // const arr = d.split(' ').map(Number);
  // const copyArr = arr.concat();
  // copyArr.sort((a, b) => b - a);

  // let ans = 0;
  // const ansArr = [];

  // for (let i = 0; i < copyArr.length; i++) {
  //   let currPoints = i * copyArr[i] + 1;
  //   ans += currPoints;
  // }

  // for (let i = 0; i < copyArr.length; i++) {
  //   for (let j = 0; j < arr.length; j++) {
  //     if (arr[j] === copyArr[i]) {
  //       ansArr.push(j + 1);
  //       arr[j] = 0;
  //     }
  //   }
  // }

  // console.log(ans);
  // console.log(ansArr.join(' '));

  c++;
});

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 copyArr = arr.concat();
  copyArr.sort((a, b) => b - a);

  let ans = 0;
  const ansArr = [];

  for (let i = 0; i < copyArr.length; i++) {
    let currPoints = i * copyArr[i] + 1;
    ans += currPoints;
  }

  for (let i = 0; i < copyArr.length; i++) {
    for (let j = 0; j < arr.length; j++) {
      if (arr[j] === copyArr[i]) {
        ansArr.push(j + 1);
        arr[j] = 0;
      }
    }
  }

  console.log(ans);
  console.log(ansArr.join(' '));

  c++;
});

'use strict'

const n = parseInt(readline());
const a = readline().split(' ').map(Number);

const b = a.map((v, k) => ({ k, v })).sort((x, y) => y.v - x.v);

write(b.map(i => i.v).reduce((r, i, ix) => r + ix * i + 1, 0) + '\n' + b.map(i => i.k + 1).join(' '));

'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() {
    var n = readline();
    var a = readline();
    solve(n, a);
}

function solve(n, a){
    let sortAr = [];
    let res = [];
    let x = 0;
    let cnt = 0;
    a.split(' ').forEach((el, idx) => {
        sortAr.push({i: idx, a: el});
    });
    sortAr.sort((a, b) => parseInt(a.a) - parseInt(b.a)).reverse();
    sortAr.forEach((el, idx) => {
        x += el.a*cnt + 1;
        res.push(el.i+1);
        cnt++;
    });
    console.log(x);
    console.log(res.join(' '));
}

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*/
    const scores = lines[1]
        .split(' ')
        .map(r => parseInt(r))
        .filter(r => r)
        .map((v, i) => ({ i, v }))
    scores.sort((x, y) => y.v - x.v)
    const total = scores.reduce((s, r, i) => s + (i * r.v + 1), 0)
    const order = scores.map(r => r.i + 1).join(' ')
    console.log(total);
    console.log(order)
})


process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

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

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let n = +input[z++];
        if(n === 1) console.log(1);
        else if(n === 2) console.log(-1);
        else{
            let counter = 1;
            let arr = Array.from({length : n}, ()=>[])
            for (let i = 0; i < n; i++) {
                arr[i][i] = counter;
                counter++;
            }
            for (let i = 1; i < n; i++) {
                let j = 0;
                let k = i;
                while (k < n && j < n) {
                    arr[j][k] = counter;
                    counter++;
                    k++;
                    j++;
                }
                j = 0;
                k = i;
                while (k < n && j < n) {
                    arr[k][j] = counter;
                    counter++;
                    k++;
                    j++;
                }
            }
            for (let i = 0; i < n; i++) {
                console.log(...arr[i]);
            }
        }
    }
}

const solve = (n) => {
    try {
        if (n === 2) return -1;
        const matrix = [];
        let even = 2;
        let odd = 1;

        for (let i = 0; i < n; i += 1) {
            const internal = [];

            for (let j = 0; j < n; j += 1) {
                if (odd <= n * n) {
                    internal.push(odd);
                    odd += 2;
                } else if (even <= n * n) {
                    internal.push(even);
                    even += 2;
                }
            }
            matrix.push(internal);
        }
        return matrix.map((line) => line.join(' ')).join('\n');
    } catch (ex) {
        console.log('ex:', ex);
    }
};

let input = '';
process.stdin.on('data', (str) => input += str);
process.stdin.on('end', () => {
    const [n, ...lines] = input.trim().split('\n')
        .map((l) => l.trim());

    for (let i = 0; i < n; i++) {
        console.log(solve(+lines[i]));
    }
});

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		if (n == 2) {
			console.log(-1);
			continue;
		}

		const ans = Array.from(Array(n), x => Array(n));

		let r = 0, c = 0, nxt = 0;
		while (c < n) {
			let i = r, j = c;
			while (i >= 0 && j < n) {
				ans[i][j] = ++nxt;
				i--; j++;
			}
			if (r < n - 1)
				r++;
			else
				c++;
		}

		[ans[0][0], ans[n-1][n-1]] = [ans[n-1][n-1], ans[0][0]];

		for (const row of ans)
			console.log(row.join(' '));
	}
}

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    for (var a = 1; a < input.length; a++) {
        var n = Number(input[a]);
        if (n === 1) {
            console.log(1);
        } else if (n === 2) {
            console.log(-1);
        } else {
            var arr = new Array(n).fill();
            for (var i = 0; i < n; i++) {
                arr[i] = new Array(n);
            }
            var count = 1;
            for (var k = 0; k < n; k++) {
                arr[k][k] = count;
                count++;
            }
            for (var k = 1; k < n; k++) {
                var i = 0, j = k;
                while (i < n && j < n) {
                    arr[i][j] = count;
                    count++;
                    i++;
                    j++;
                }
                var i = k, j = 0;
                while (i < n && j < n) {
                    arr[i][j] = count;
                    count++;
                    i++;
                    j++;
                }
            }
            for (var i = 0; i < arr.length; i++) {
                console.log(arr[i].join(" "));
            }
        }
    }
})

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        main()
        process.exit(0)
    }
})

function solve(n) {
    if (n === 2) {
        console.log('-1')
        return
    }
    let matrix = Array(n * n)
    let num = 0, row = 0
    for (let i = 0; i < n * n; i += 2) matrix[i] = ++num
    for (let i = 1; i < n * n; i += 2) matrix[i] = ++num
    for (let i = 0; i < n; i++) {
        console.log(matrix.slice(row, row + n).join(' '))
        row += n
    }
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(Number(inputArr[i]))
}

const solve = (n) => {
	if (n === 2) {
		return -1;
	}

	const matrix = [];

	let counter = 1;
	for (let i=0; i<n; i++) {
		for (let j=0; j<n; j++) {
			matrix[(i+j)%n] = matrix[(i+j)%n] || [];
			matrix[(i+j)%n][j] = counter;
			counter += 1;
		}
	}

	return matrix.map(line => line.join(' ')).join('\n');
}

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const [n, ...lines] = input.trim().split('\n')
		.map(l => l.trim());

	for (let i=0; i<n; i++) {
		console.log(solve(+lines[i]))
	}
})

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const n = +readLine();
		if (n === 1) console.log(1);
		else if (n === 2) console.log(-1);
		else {
			const arr = Array(n)
				.fill(0)
				.map((_) => Array(n).fill(0));
			let [status, count] = ['odd', 1];
			for (let row = 0; row < n; row++) {
				for (let col = 0; col < n; col++) {
					if (status === 'odd') {
						if (count <= n ** 2) {
							arr[row][col] = count;
							count += 2;
						} else {
							status = 'even';
							arr[row][col] = 2;
							count = 4;
						}
					} else {
						if (count <= n ** 2) {
							arr[row][col] = count;
							count += 2;
						}
					}
				}
			}

			for (let row = 0; row < n; row++) {
				console.log(arr[row].join(' '));
			}
		}
	}
}

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		if(N == 2){
			myout(-1);
			continue;
		}
		var list = new Array(N);
		for(var j = 0; j < N; j++){
			list[j] = new Array(N);
		}
		var V = 1;
		for(var j = 0; j < N; j++){
			for(var k = (j % 2 == 0) ? 0 : 1; k < N; k += 2){
				list[j][k] = V;
				V++;
			}
		}
		for(var j = 0; j < N; j++){
			for(var k = 0; k < N; k++){
				if(list[j][k] == null){
					list[j][k] = V;
					V++;
				}
			}
		}
		for(var j = 0; j < N; j++){
			myout(myconv(list[j], 8));
		}
	}
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());

  if (n === 1)
    print(n);
  else if (n === 2)
    print(-1);
  else {
    var sqn = n * n;
    var p = 0;
    var s = "";
    for (var i = 1; i <= sqn; i += 2) {
      s += i + ' ';
      p++;
      if (p === n) {
        print(s);
        s = "";
        p = 0;
      }
    }
    for (var i = 2; i <= sqn; i += 2) {
      s += i + ' ';
      p++;
      if (p === n) {
        print(s);
        s = "";
        p = 0;
      }
    }
  }
}

var numberOfCases = Number(readline());
for (var i = 0; i < numberOfCases; ++i) {
    processCase();
}

function processCase() {
    var n = Number(readline());
    if (n === 1) {
        return print("1");
    }

    if (n === 2) {
        return print("-1");
    }

    var currentNumber = 1;
    for (var i = 0; i < n; ++i) {
        for (var j = 0; j < n; ++j) {
            write(currentNumber, "");
            currentNumber += 2;
            if (currentNumber > n * n) {
                currentNumber = 2;
            }

        }

        write("\n");
    }
}

var T = parseInt(readline());
var U = 1
var N = 1
var u = 1
var s = ""
function next() {
    var t = (u).toString(10);
    u += 2;
    if (u > U)
        u = 2;
    return t; }
while (T--) {
    N = parseInt(readline());
    U = N*N
    switch (N) {
    case 1:
        print(1); break;
    case 2:
        print(-1); break;
    default:
        for (var i = 0; i < N; ++i) {
		    s += next();
		    for (var j = 1; j < N; ++j)
				s += " "+next();
			print(s);
			s = ""; }
		u = 1; } }

"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 = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    if (n === 1) console.log(1);
    else if (n === 2) console.log(-1);
    else {
      let res = new Array(n).fill(0).map((cur) => new Array(n).fill(0));
      let ans = 0;
      for (let i = 0; i + 1 < n; i++) {
        for (let j = i; j >= 0; j--) res[i - j][j] = ++ans;
      }
      let j = 0;
      for (let i = n - 1; i >= 0; i--) res[j++][i] = ++ans;
      for (let i = 1; i < n; i++) {
        let j = i,
          k = n - 1;
        while (j < n) res[j++][k--] = ++ans;
      }
      res[0][0] = n * n;
      res[n - 1][n - 1] = 1;
      let r = "";
      for (let i = 0; i < n; i++) r += res[i].join(" ") + "\n";
      console.log(r);
    }
  }
};
solve();

"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 = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    if (n === 1) console.log(1);
    else if (n === 2) console.log(-1);
    else {
      let res = new Array(n).fill(0).map((cur) => new Array(n).fill(0));
      let ans = 0;
      for (let i = 0; i + 1 < n; i++) {
        for (let j = i; j >= 0; j--) res[i - j][j] = ++ans;
      }
      let j = 0;
      for (let i = n - 1; i >= 0; i--) res[j++][i] = ++ans;
      for (let i = 1; i < n; i++) {
        let j = i,
          k = n - 1;
        while (j < n) res[j++][k--] = ++ans;
      }
      let r = "";
      for (let i = 0; i < n; i++) r += res[i].join(" ") + "\n";
      console.log(r);
    }
  }
};
solve();

const solve = (n) => {
    try {
        if (n === 2) return -1;
        const matrix = [];
        let even = 2;
        let odd = 1;
        for (let i = 0; i < n; i += 1) {
            for (let j = 0; j < n; j += 1) {
                if (odd <= n * n) {
                    matrix.push(odd);
                    odd += 2;
                } else if (even <= n * n) {
                    matrix.push(even);
                    even += 2;
                }
            }
        }
        return matrix;
    } catch (ex) {
        console.log('ex:', ex);
    }
};

let input = '';
process.stdin.on('data', (str) => input += str);
process.stdin.on('end', () => {
    const [n, ...lines] = input.trim().split('\n')
        .map((l) => l.trim());

    for (let i = 0; i < n; i++) {
        console.log(solve(+lines[i]));
    }
});

const t=parseInt(readline());

for(var k=0;k<t;k++)
{
    var n=parseInt(readline());
    if(n%2===0)
    {
        print("-1");
    }
    else
    {
        var p=1;
        var q=n*n;
        for(var i=0;i<n;i++)
        {
            var s="";
            for(var j=0;j<n;j++)
            {

                if((i+j)%2==1)
                {
                    s+= p+" ";
                    p++;
                }
                else
                {
                    s+= q+" ";

                    q--;
                }
            }
            print(s);
        }
    }

}


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++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var a = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 0; j < n; j++){
                for(l = j; l < n; l++){
                    var e = 0;
                    for(k = j; k <= l; k++){
                        if(a[k] === 0){
                            e++;
                        }
                    }
                    ans += l - j + 1 + e;
                }
            }
            console.log(ans);
        }
    }
});

const main = () => {

	// simply break every subsegment into individual items
	var t = readInt();
	while (t--) {
		var n = readInt();
		var a = readIntArr();
		var l = 1;
		var r = n;
		var ans = 0;
		for (var x of a) {
			var v;
			if (x === 0) v = 2;
			else v = 1;
			ans += v * l++ * r--;
		}
		print(ans);
	}

	return;
}

const readInt = () => parseInt(readline());
const readString = () => readline();
const readIntArr = () => readline().split(" ").map(zzzz => parseInt(zzzz));
const parseLong = (string) => { // javascript's largest long is < (1<<62)
	var n = string.length;
	var res = 0;
	for (var i = 0; i < n; i++) {
		res *= 10;
		res += parseInt(string[i]);
	}
	return res;
}
const readLong = () => parseLong(readLong());
const readLongArr = () => readline().split(" ").map(zzzz => parseLong(zzzz));
const oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));
const multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\n'));
const multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\n'));
const makeArr = (defaultVal, dimensionsArr) => {
	var n = dimensionsArr.length;
	if (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);
	else {
		var temp = [];
		for (var i = 0; i < dimensionsArr[0]; i++)
			temp.push(makeArr(defaultVal, dimensionsArr.slice(1)));
		return temp;
	}
}

for (_ = 0; _ < 1; _++) {
	main();
}

// newline for testing
 //newline for testing
// codeforces js cannot use "let" keyword. use "var" instead
// codeforces js cannot destructure arrays


'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const arr = get_ints();

        b(n,arr);
    }
});

function a(k)
{
    let e = 0;
    let w = 0;
    let pe = k;
    let pw = 100 - k;
    const c = gcd(pe,pw);
    return console.log(pe / c + pw / c);
}

function b(n,arr)
{
    let flag = true;
    for(let i = 0 ; i < n; i++)
    {
        if(arr[i] !== i+1) {
            flag = false;
            break;
        }
    }
    if(flag) return console.log(0);
    if(arr[0] === n && arr[n-1] === 1) return console.log(3);
    if(arr[0] === 1 || arr[n-1] === n) return console.log(1);
    return console.log(2);
}

function gcd(x, y) {
    if ((typeof x !== 'number') || (typeof y !== 'number'))
      return false;
    x = Math.abs(x);
    y = Math.abs(y);
    while(y) {
      var t = y;
      y = x % y;
      x = t;
    }
    return x;
  }

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

module.exports = b;

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 05/15/21 night
 * https://codeforces.com/contest/1525/problem/B
 */

const solve = (n, a) => {
    if (isAscending(a)) return pr(0);
    if (a[0] == 1 || a[n - 1] == n) return pr(1);
    if (a[0] == n && a[n - 1] == 1) return pr(3);
    pr(2);
};

const isAscending = (arr) => {
    return arr.every((x, i) => {
        return i === 0 || x > arr[i - 1];
    });
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

//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 list = nextIntArray(N);
		var isOK = true;
		for(var i = 1; i < N; i++){
			if(list[i - 1] + 1 != list[i]){
				isOK = false;
				break;
			}
		}
		if(isOK){
			myout(0);
			continue;
		}
		if(list[0] == 1 || list[N - 1] == N){
			myout(1);
		}else if(list[0] == N && list[N - 1] == 1){
			myout(3);
		}else{
			myout(2);
		}

	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while(t--) {
		let n = rl();
		let a = rl();

		let min = max = a[0], isSorted = true;
		for (let i = 1; i < n; i++) {
			if (a[i] < a[i - 1]) isSorted = false;
			min = Math.min(min, a[i]);
			max = Math.max(max, a[i]);
		}
		let ans;
		if (isSorted) ans = 0;
		else if (min == a[n - 1] && max == a[0]) ans = 3;
		else if (min == a[0] || max == a[n - 1]) ans = 1;
		else ans = 2;

		console.log(ans);
	}
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map(d => parseInt(d));

  var min = a[0];
  var max = min;
  var min_i = 0;
  var max_i = min_i;
  var sorted = true;

  for (var i = 1; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
      min_i = i;
    } else if (a[i] > max) {
      max = a[i];
      max_i = i;
    }
    if (a[i] < a[i - 1])
      sorted = false;
  }

  if (sorted)
    print(0);
  else if (min_i === n - 1 && max_i === 0)
    print(3);
  else if (min_i !== 0 && max_i !== n - 1)
    print(2);
  else
    print(1);
}

const isSorted = (arr, temp) => {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] != temp[i]) {
            return false
        }
    }
    return true
}

const cases = readline();
for (var i = 0; i < cases; i++) {
    var size = readline()
    var inp = readline()
    var arr = inp.split(' ')
    var temp = inp.split(' ')
    temp = temp.sort((a, b) => { return a - b })
    var res = 2
    if (isSorted(arr, temp))
        res = 0;
    else if (arr[0] == 1 || arr[size - 1] == size)
        res = 1;
    else if (arr[0] == size && arr[size - 1] == 1)
        res = 3;
    print(res)
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 05/15/21 night
 * https://codeforces.com/contest/1525/problem/B
 */

const solve = (n, a) => {
    if (isAscending(a)) return pr(0);
    if (a[0] == 1 || a[n - 1] == n) return pr(1);
    if (a[0] == n || a[n - 1] == 1) return pr(3);
    pr(2);
};

const isAscending = (arr) => {
    return arr.every((x, i) => {
        return i === 0 || x > arr[i - 1];
    });
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const solve = (n, a) => {
    let sa = [...a];
    stin(sa);
    // pr(sa);
    // pr(n, a)
    let res = 0;
    if (isAscending(a)) return pr(res);
    while (!isAscending(a)) {
        // let next = 0;
        for (let i = 0; i < n; i++) {
            let should = i + 1;
            if (a[i] != should) {
                let l = a.slice(0, i + 1);
                let ol = [...l];
                stin(l);
                if (!aeq(l, ol)) res++;
                let r = a.slice(i + 1);
                let or = [...r]
                stin(r);
                if (!aeq(r, or)) res++;
                a = l.concat(r);
            }
        }
    }
    // pr(a);
    pr(res);
};

const isAscending = (arr) => {
    return arr.every((x, i) => {
        return i === 0 || x > arr[i - 1];
    });
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const arr = get_ints();

        b(arr);
    }
});

function a(k)
{
    let e = 0;
    let w = 0;
    let pe = k;
    let pw = 100 - k;
    const c = gcd(pe,pw);
    return console.log(pe / c + pw / c);
}

function b(n,arr)
{
    let flag = true;
    for(let i = 0 ; i < n; i++)
    {
        if(arr[i] !== i+1) {
            flag = false;
            break;
        }
    }
    if(flag) return console.log(0);
    if(arr[0] === n && arr[n-1] === 1) return console.log(3);
    if(arr[0] === 1 || arr[n-1] === n) return console.log(1);
    return console.log(2);
}

function gcd(x, y) {
    if ((typeof x !== 'number') || (typeof y !== 'number'))
      return false;
    x = Math.abs(x);
    y = Math.abs(y);
    while(y) {
      var t = y;
      y = x % y;
      x = t;
    }
    return x;
  }

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

module.exports = b;

'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const arr = get_ints();

        b(arr);
    }
});

function a(k)
{
    let e = 0;
    let w = 0;
    let pe = k;
    let pw = 100 - k;
    const c = gcd(pe,pw);
    return console.log(pe / c + pw / c);
}

function b(arr)
{
    let peaks = 0;
    for(let i = 0; i < arr.length - 2; i++)
    {
        if(i === 0 && arr[0] !== 1) peaks++;
        if(arr[i] < arr[i+1] && arr[i+1] > arr[i+2]) peaks++;
    }
    return console.log(peaks)
}

function gcd(x, y) {
    if ((typeof x !== 'number') || (typeof y !== 'number'))
      return false;
    x = Math.abs(x);
    y = Math.abs(y);
    while(y) {
      var t = y;
      y = x % y;
      x = t;
    }
    return x;
  }

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

module.exports = b;

'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const arr = get_ints();

        b(arr);
    }
});

function a(k)
{
    let e = 0;
    let w = 0;
    let pe = k;
    let pw = 100 - k;
    const c = gcd(pe,pw);
    return console.log(pe / c + pw / c);
}

function b(arr)
{
    let peaks = 0;
    for(let i = 0; i < arr.length - 2; i++)
    {
        if(i === 0 && arr[0] !== 1) peaks++;
        if(arr[i] < arr[i+1] && arr[i+1] > arr[i+2]) peaks++;
    }
    return console.log(peaks)
}

function gcd(x, y) {
    if ((typeof x !== 'number') || (typeof y !== 'number'))
      return false;
    x = Math.abs(x);
    y = Math.abs(y);
    while(y) {
      var t = y;
      y = x % y;
      x = t;
    }
    return x;
  }

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

module.exports = b;

//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 list = nextIntArray(N);
		var isOK = true;
		for(var i = 1; i < N; i++){
			if(list[i - 1] + 1 != list[i]){
				isOK = false;
				break;
			}
		}
		if(isOK){
			myout(0);
			continue;
		}
		if(list[0] == 1 || list[N - 1] == N || list[0] == N || list[N - 1] == 0){
			myout(1);
		}else{
			myout(2);
		}

	}
}

//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 list = nextIntArray(N);
		var isOK = true;
		for(var i = 1; i < N; i++){
			if(list[i - 1] + 1 != list[i]){
				isOK = false;
				break;
			}
		}
		if(isOK){
			myout(0);
			continue;
		}
		if(list[0] == 1 || list[N - 1] == N){
			myout(1);
		}else{
			myout(2);
		}

	}
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map(d => parseInt(d));

  var min = a[0];
  var max = min;
  var min_i = 0;
  var max_i = min_i;
  var sorted = true;

  for (var i = 1; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
      min_i = i;
    } else if (a[i] > max) {
      max = a[i];
      max_i = i;
    }
    if (a[i] < a[i - 1])
      sorted = false;
  }

  print(sorted? 0: (min_i !== 0 && max_i !== n - 1 && n > 2)? 2: 1);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map(d => parseInt(d));

  var min = a[0];
  var max = min;
  var min_i = 0;
  var max_i = min_i;
  var sorted = true;

  for (var i = 1; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
      min_i = i;
    } else if (a[i] > max) {
      max = a[i];
      max_i = i;
    }
    if (a[i] < a[i - 1])
      sorted = false;
  }

  print(sorted? 0: (min_i !== 0 && max_i !== n - 1)? 2: 1);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map(d => parseInt(d));

  var min = a[0];
  var min_index = 0;
  var sorted = true;

  for (var i = 1; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
      min_index = i;
      sorted = false;
    }
    if (a[i] < a[i - 1])
      sorted = false;
  }

  print(sorted? 0: min_index? 2: 1);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map(d => parseInt(d));

  var min = a[0];
  var min_index = 0;
  var sorted = true;

  for (var i = 1; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
      min_index = i;
    }
    if (a[i] < a[i - 1])
      sorted = false;
  }

  print(sorted? 0: min_index? 2: 1);
}

const cases = readline();
for (var i = 0; i < cases; i++) {
  var size = readline()
  var inp = readline()
  var a = inp.split(' ')
  var temp = inp.split(' ')
  temp = temp.sort((a,b)=>{return a-b})
  var res = 2
  if (temp == a)
    res = 0;
  else if (a[0] == 1 || a[size - 1] == size)
    res = 1;
  else if (a[0] == size && a[size - 1] == 1)
    res = 3;
  print(res)
}

const cases = readline()
for (var i = 0; i < cases; i++) {
  var size = readline()
  var inp = readline()
  var arr = inp.split(' ')
  var temp = inp.split(' ')
  temp = temp.sort((a,b)=>{return a-b})
  var count = 0
  for (var k=0; k < size; k++){
    if(arr[k] != temp[k]){
      count++
    }
  }
  print(Math.floor(count/2))
}


const nm = readline().split(" ").map(e => parseInt(e));

const n = nm[0];
const m = nm[1];

readMatrix = () => {
	const result = [];
	for (var i = 0; i < n; i++) {
		result.push(readline().split(" ").map(e => parseInt(e)));
	}
	return result;
};

const a = readMatrix();
const b = readMatrix();

const inA = [];
const inB = [];

for (var i = 0; i < n; i++) {
	for (var j = 0; j < m; j++) {
		if (inA[i + j] === undefined) {
			inA[i + j] = [];
			inB[i + j] = [];
		}
		inA[i + j].push(a[i][j]);
		inB[i + j].push(b[i][j]);
	}
}

const cmp = function(a, b) {
	if (a.length != b.length) {
		return false;
	}
	for (var i in a) {
		if (a[i] !== b[i]) {
			return false;
		}
	}
	return true;
};
var result = true;
for (var i in inA) {
	if (inB[i] === undefined || !cmp(inA[i].sort((a, b) => a - b), inB[i].sort((a, b) => a - b))) {
		result = false;
		break;
	}
}
print(result ? "YES" : "NO");

var inp = readline().split(' ').map(x => parseInt(x));
var n = inp[0], m = inp[1];
var tot = n * m;

var A = new Array(),
	B = new Array(),
	adiag = new Array(),
	bdiag = new Array();

for(var i = 0; i < n; i++){
	inp = readline().split(' ').map(x => parseInt(x));
	A.push(inp);
}
for(var i = 0; i < n; i++){
	inp = readline().split(' ').map(x => parseInt(x));
	B.push(inp);
}

const cmp = (a, b) => (a - b);

var bad = false;
for(var col = 0; col < m; col++){
	var j = col;
	var i = 0;
	adiag = [];
	bdiag = [];
	while(j >= 0 && i < n){
		adiag.push(A[i][j]);
		bdiag.push(B[i][j]);
		j--;
		i++;
	}
	adiag.sort(cmp);
	bdiag.sort(cmp);
	var match = 0;
	adiag.forEach((x, i) => {
		if(x === bdiag[i]) match++;
	});
	if(match === adiag.length) continue;
	else{
		bad = true;
		break;
	}
}
if(bad) print("NO");
else{
	for(var row = 1; row < n; row++){
		var j = m;
		var i = row;
		adiag = [];
		bdiag = [];
		while(j >= 0 && i < n){
			adiag.push(A[i][j]);
			bdiag.push(B[i][j]);
			j--;
			i++;
		}
		adiag.sort(cmp);
		bdiag.sort(cmp);
		var match = 0;
		adiag.forEach((x, i) => {
			if(x === bdiag[i]) match++;
		});
		if(match === adiag.length) continue;
		else{
			bad = true;
			break;
		}
	}
	if(bad) print("NO");
	else print("YES");
}


process.stdin.resume();
process.stdin.setEncoding("ascii");

_data = "";
process.stdin.on("data", function (data) {
   _data += data;
});

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

function processData(data) {
    const lines = data.trim().split("\n");
    for (let i = 0; i < lines[0]; i++) {
        processTC(lines, i+1);
    }
}

function processTC(lines, startLine) {
    const [n, m] = lines[startLine].trim().split(" ").map(x => Number(x));
    if (m == 3 && n == 3) {
        return console.log(2, 2);
    } else if (m == 3) {
        return console.log(n, 2);
    } else if (n == 3) {
        return console.log(2, m);
    }
    return console.log(n, m);
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseArray = readline().split(" ");
    var rows = parseInt(caseArray[0]);
    var columns = parseInt(caseArray[1]);
    var result = "1 1";
    if ((rows === 2 || rows === 3) && (columns === 2 || columns == 3))
    {
        result = "2 2";
    }
    print(result);
}

var rl = readline
var toN = function(x) { return +x }
var rn = function() { return toN(rl()) }
var ran = function() {
	return (rl()
		.split(' ')
		.map(toN)
	)
}

var mid = function(x) {
	return Math.floor(x/2)+1
}

var main = function() {
	var t = rn()
	var res = new Array(t).fill([0,0])

	res.forEach(function(x) {
		var nm = ran()
		var n = mid(nm[0])
		var m = mid(nm[1])
		print(n, m)
	})
}

main()

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

let currentLine = 0;
let inputString = "";

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

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

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

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

function readArrayInt() {
  return inputString[currentLine++].split(" ").map(Number);
}

function readArray() {
  return inputString[currentLine++].split(" ");
}

function solve() {
  const T = readInt();

  for (let i = 0; i < T; ++i) {
    const [n, m] = readArrayInt();

    const arr = [];

    let count = 1;
    for (let i = 0; i < n; ++i) {
      const brr = [];
      for (let j = 0; j < m; ++j) {
        brr.push(count);
        ++count;
      }
      arr.push(brr);
    }

    let check = false;
    for (let i = 0; i < n; ++i) {
      for (let j = 0; j < m; ++j) {
        if (!isOk(arr, i, j)) {
          console.log(i + 1, j + 1);
          check = true;
          break;
        }
      }
      if (check) break;
    }

    if (!check) {
      console.log(n, m);
    }

    // # # #
    // # # #
    // # # #
  }
}

// function isOk(arr, i, j) {
//   if (
//     arr?.[i + 2]?.[j + 1] ||
//     arr?.[i + 2]?.[j - 1] ||
//     arr?.[i + -2]?.[j + 1] ||
//     arr?.[i - 2]?.[j - 1] ||
//     arr?.[i + 1]?.[j + 2] ||
//     arr?.[i + 1]?.[j - 2] ||
//     arr?.[i + -1]?.[j + 2] ||
//     arr?.[i - 1]?.[j - 2]
//   ) {
//     return true;
//   }

//   return false;
// }

function isOk(arr, i, j) {
  var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;

  if (
    (arr !== null &&
      arr !== void 0 &&
      (_arr = arr[i + 2]) !== null &&
      _arr !== void 0 &&
      _arr[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr2 = arr[i + -2]) !== null &&
      _arr2 !== void 0 &&
      _arr2[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr3 = arr[i + 2]) !== null &&
      _arr3 !== void 0 &&
      _arr3[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr4 = arr[i - 2]) !== null &&
      _arr4 !== void 0 &&
      _arr4[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr5 = arr[i + 1]) !== null &&
      _arr5 !== void 0 &&
      _arr5[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr6 = arr[i + -1]) !== null &&
      _arr6 !== void 0 &&
      _arr6[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr7 = arr[i + 1]) !== null &&
      _arr7 !== void 0 &&
      _arr7[j - 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr8 = arr[i - 1]) !== null &&
      _arr8 !== void 0 &&
      _arr8[j - 2])
  ) {
    return true;
  }

  return false;
}

function main() {
  solve();
}

var toN = x => +x

class Input {
	constructor(data)  {
		this.lines = data.split(/\r?\n/)
		this.index = 0
	}

	readL() {
		return this.lines[this.index++]
	}

	readN() {
		return toN(this.readL())
	}

	readAr() {
		return this.readL().split(' ')
	}

	readArN() {
		return this.readAr().map(toN)
	}
}

/*var createInput = (data) => {
	var lines = data.split(/\r?\n/)
	var index = 0;

	var readL = () => lines[index++]
	var readN = () => toN(readL())
	var readAr = () => readL().split(' ')
	var readArN = () => readAr().map(toN)

	return {
		readL, readN, readAr, readArN
	}
}
*/
var input = async () => new Promise(r=>{
	var data = ''
	process.stdin.on('data', chunk=>data+=chunk)
	process.stdin.on('end', () => r(new Input(data)))
})

var mid = x => (x-x%2)/2+1

var main = async () => {
	var inp = await input()
	var t = inp.readN()
	var res = new Array(t).fill(0).map(()=>inp.readArN())
	res.forEach(([n, m]) => console.log(mid(n), mid(m)))
}

main()

var createInput = (data) => {
	var lines = data.replace(/\r/g, '').split('\n')
	var index = 0;

	var toN = x => +x
	var readL = () => lines[index++]
	var readN = () => toN(readL())
	var readAr = () => readL().split(' ')
	var readArN = () => readAr().map(toN)

	return {
		readL, readN, readAr, readArN
	}
}

var input = async () => new Promise(r=>{
	var data = ''
	process.stdin.on('data', chunk=>data+=chunk)
	process.stdin.on('end', () => r(createInput(data)))
})

var mid = x => (x-x%2)/2+1

var main = async () => {
	var {readN, readArN} = await input()
	var t = readN()
	var res = new Array(t).fill(0).map(readArN)
	res.forEach(([n, m]) => console.log(mid(n), mid(m)))
}

main()

var readline = require('readline');
var inputString = [], currentLine = 0;
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var rl = readline.createInterface(process.stdin);
rl.on('line', line => { inputString.push(line) });
process.stdin.on('end', () => {  main()  });

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

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        // const n = +readLine();
        // const arr = readLine().split(' ').map(p => +p);
        const l_c = readLine().split(' ').map(p => +p);
        let result = myFunc(l_c[0], l_c[1]);
        // console.log(result);
    }
}

function myFunc(l, c){

    let lr = Math.ceil(l/2);
    let cr = Math.ceil(c/2);
    console.log(lr, cr);

}

// 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 //

const getSolution = (n, m) => {

    if( n == 1 || m == 1) return [n,m].join(' ') // all are isolated
    else if( n <= 2 && m <= 2) return [n,m].join(' ') // all are isolated
    else if( n == 3 && m == 3) return [2,2].join(' ') // only 2,2 is isolated
    else if( n > 3 && m > 3) return [1,1].join(' ') // none are isolated
    else {
        let x = Math.floor(n/2) + 1
        let y = Math.floor(m/2) + 1
        return [x,y].join(' ')
    }
}

// Driver Function Starts //
function main() {

    let testcases = parseInt( readline() )
    while(testcases--){

        let arr = readline().split(' ').map(Number)
        let n = arr[0]
        let m = arr[1]

        console.log( getSolution(n,m)  )
    }

}
// Driver Function Ends //

'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 [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        m = rn();
  if (n === 1 || m === 1) return `1 1`;
  if (n === 2) return `2 ${Math.ceil(m / 2)}`;
  if (m === 2) return `${Math.ceil(n / 2)} 2`;
  return `2 2`;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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

let currentLine = 0;
let inputString = "";

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

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

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

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

function readArrayInt() {
  return inputString[currentLine++].split(" ").map(Number);
}

function readArray() {
  return inputString[currentLine++].split(" ");
}

function solve() {
  const T = readInt();

  for (let i = 0; i < T; ++i) {
    const [n, m] = readArrayInt();

    const arr = [];

    let count = 1;
    for (let i = 0; i < n; ++i) {
      const brr = [];
      for (let j = 0; j < m; ++j) {
        brr.push(2000);
        ++count;
      }
      arr.push(brr);
    }

    let check = false;
    for (let i = 0; i < n; ++i) {
      for (let j = 0; j < m; ++j) {
        if (!isOk(arr, i, j)) {
          console.log(i + 1, j + 1);
          check = true;
          break;
        }
      }
    }

    if (!check) {
      console.log(n, m);
    }

    // # # #
    // # # #
    // # # #
  }
}

// function isOk(arr, i, j) {
//   if (
//     arr?.[i + 2]?.[j + 1] ||
//     arr?.[i + 2]?.[j - 1] ||
//     arr?.[i + -2]?.[j + 1] ||
//     arr?.[i - 2]?.[j - 1] ||
//     arr?.[i + 1]?.[j + 2] ||
//     arr?.[i + 1]?.[j - 2] ||
//     arr?.[i + -1]?.[j + 2] ||
//     arr?.[i - 1]?.[j - 2]
//   ) {
//     return true;
//   }

//   return false;
// }

function isOk(arr, i, j) {
  var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;

  if (
    (arr !== null &&
      arr !== void 0 &&
      (_arr = arr[i + 2]) !== null &&
      _arr !== void 0 &&
      _arr[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr2 = arr[i + -2]) !== null &&
      _arr2 !== void 0 &&
      _arr2[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr3 = arr[i + 2]) !== null &&
      _arr3 !== void 0 &&
      _arr3[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr4 = arr[i - 2]) !== null &&
      _arr4 !== void 0 &&
      _arr4[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr5 = arr[i + 1]) !== null &&
      _arr5 !== void 0 &&
      _arr5[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr6 = arr[i + -1]) !== null &&
      _arr6 !== void 0 &&
      _arr6[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr7 = arr[i + 1]) !== null &&
      _arr7 !== void 0 &&
      _arr7[j - 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr8 = arr[i - 1]) !== null &&
      _arr8 !== void 0 &&
      _arr8[j - 2])
  ) {
    return true;
  }

  return false;
}

function main() {
  solve();
}

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

let currentLine = 0;
let inputString = "";

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

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

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

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

function readArrayInt() {
  return inputString[currentLine++].split(" ").map(Number);
}

function readArray() {
  return inputString[currentLine++].split(" ");
}

function solve() {
  const T = readInt();

  for (let i = 0; i < T; ++i) {
    const [n, m] = readArrayInt();

    const arr = [];

    let count = 1;
    for (let i = 0; i < n; ++i) {
      const brr = [];
      for (let j = 0; j < m; ++j) {
        brr.push(count);
        ++count;
      }
      arr.push(brr);
    }

    let check = false;
    for (let i = 0; i < n; ++i) {
      for (let j = 0; j < m; ++j) {
        if (!isOk(arr, i, j)) {
          console.log(i + 1, j + 1);
          check = true;
          break;
        }
      }
    }

    if (!check) {
      console.log(n, m);
    }

    // # # #
    // # # #
    // # # #
  }
}

// function isOk(arr, i, j) {
//   if (
//     arr?.[i + 2]?.[j + 1] ||
//     arr?.[i + -2]?.[j + 1] ||
//     arr?.[i + 2]?.[j - 1] ||
//     arr?.[i - 2]?.[j - 1] ||
//     arr?.[i + 1]?.[j + 2] ||
//     arr?.[i + -1]?.[j + 2] ||
//     arr?.[i + 1]?.[j - 2] ||
//     arr?.[i - 1]?.[j - 2]
//   ) {
//     return true;
//   }

//   return false;
// }

function isOk(arr, i, j) {
  var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;

  if (
    (arr !== null &&
      arr !== void 0 &&
      (_arr = arr[i + 2]) !== null &&
      _arr !== void 0 &&
      _arr[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr2 = arr[i + -2]) !== null &&
      _arr2 !== void 0 &&
      _arr2[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr3 = arr[i + 2]) !== null &&
      _arr3 !== void 0 &&
      _arr3[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr4 = arr[i - 2]) !== null &&
      _arr4 !== void 0 &&
      _arr4[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr5 = arr[i + 1]) !== null &&
      _arr5 !== void 0 &&
      _arr5[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr6 = arr[i + -1]) !== null &&
      _arr6 !== void 0 &&
      _arr6[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr7 = arr[i + 1]) !== null &&
      _arr7 !== void 0 &&
      _arr7[j - 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr8 = arr[i - 1]) !== null &&
      _arr8 !== void 0 &&
      _arr8[j - 2])
  ) {
    return true;
  }

  return false;
}

function main() {
  solve();
}

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

let currentLine = 0;
let inputString = "";

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

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

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

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

function readArrayInt() {
  return inputString[currentLine++].split(" ").map(Number);
}

function readArray() {
  return inputString[currentLine++].split(" ");
}

function solve() {
  const T = readInt();

  for (let i = 0; i < T; ++i) {
    const [n, m] = readArrayInt();

    const arr = [];

    let count = 1;
    for (let i = 0; i < n; ++i) {
      const brr = [];
      for (let j = 0; j < m; ++j) {
        brr.push(count);
        ++count;
      }
      arr.push(brr);
    }

    for (let i = 0; i < n; ++i) {
      for (let j = 0; j < m; ++j) {
        if (!isOk(arr, i, j)) {
          console.log(i + 1, j + 1);
          return;
        }
      }
    }
    console.log(n, m);

    // # # #
    // # # #
    // # # #
  }
}

// function isOk(arr, i, j) {
//   if (
//     arr?.[i + 2]?.[j + 1] ||
//     arr?.[i + -2]?.[j + 1] ||
//     arr?.[i + 2]?.[j - 1] ||
//     arr?.[i - 2]?.[j - 1] ||
//     arr?.[i + 1]?.[j + 2] ||
//     arr?.[i + -1]?.[j + 2] ||
//     arr?.[i + 1]?.[j - 2] ||
//     arr?.[i - 1]?.[j - 2]
//   ) {
//     return true;
//   }

//   return false;
// }

function isOk(arr, i, j) {
  var _arr, _arr2, _arr3, _arr4, _arr5, _arr6, _arr7, _arr8;

  if (
    (arr !== null &&
      arr !== void 0 &&
      (_arr = arr[i + 2]) !== null &&
      _arr !== void 0 &&
      _arr[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr2 = arr[i + -2]) !== null &&
      _arr2 !== void 0 &&
      _arr2[j + 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr3 = arr[i + 2]) !== null &&
      _arr3 !== void 0 &&
      _arr3[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr4 = arr[i - 2]) !== null &&
      _arr4 !== void 0 &&
      _arr4[j - 1]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr5 = arr[i + 1]) !== null &&
      _arr5 !== void 0 &&
      _arr5[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr6 = arr[i + -1]) !== null &&
      _arr6 !== void 0 &&
      _arr6[j + 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr7 = arr[i + 1]) !== null &&
      _arr7 !== void 0 &&
      _arr7[j - 2]) ||
    (arr !== null &&
      arr !== void 0 &&
      (_arr8 = arr[i - 1]) !== null &&
      _arr8 !== void 0 &&
      _arr8[j - 2])
  ) {
    return true;
  }

  return false;
}

function main() {
  solve();
}