'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const MOD = 32768;

let can_achieve = (h, days, goal)=>{
  let doubles = Math.floor(days/2);
  let ones = Math.floor((days+1)/2);
  //l({doubles, ones, days})
  let leftovers = [];
  for (let x of h){
    if (goal-x>0){
      let g = goal-x;
      if (g%2){
        g--;
        ones--;
      }
      leftovers.push(g);
    }
  }
  //l({leftovers})
  if (ones<0)
    return false;
  for (let l of leftovers){
    let deduct_doubles = Math.min(doubles, Math.floor(l/2));
    doubles -= deduct_doubles;
    l -= deduct_doubles*2;
    let deduct_ones = Math.min(ones, l);
    ones -= deduct_ones;
    l -= deduct_ones;
    if (l>0)
      return false;
  }
  //l('yes')
  return true
};

const calc = (n, h)=>{
  h.sort((a, b)=>a-b);
  let min = h[0];
  let max = h[h.length-1]
  if (min==max)
    return 0;
  let l = 0, r = 3*1e14+5;
  while (l<r){
    let m = Math.floor((l+r)/2);
    if (can_achieve(h, m, max) || can_achieve(h, m, max+1))
      r = m;
    else
      l = m+1;
  }
  if (can_achieve(h, l-1, max) || can_achieve(h, l-1, max+1))
    return l-1;
  if (can_achieve(h, l, max) || can_achieve(h, l, max+1))
    return l;
  return l+1;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let h = ra();
      l('ans')
      print(calc(n, h));
    }
}

E.calc = calc;

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

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

		const ans = [];
		let goal = 0;
		for (let i = 0; i < n; i++) goal = Math.max(goal, h[i]);
		for (let round = 0; round < 2; round++, goal++) {
			let need = 0, oddReq = 0, oddHas;
			for (let i = 0; i < n; i++) {
				need += goal - h[i];
				oddReq += (goal- h[i]) & 1;
			}
			ans[round] = Math.ceil(need*2/3);
			oddHas = Math.ceil(ans/2);
			//console.log({goal, need, oddReq, oddHas, ans});
			if (oddReq > oddHas) {
				ans[round] += (oddReq - oddHas) * 2 - (ans%2 == 0 ? 1 : 0);
			}
		}

		console.log(Math.min(...ans));
	}
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const check = (a, days, max) => {
    let twos = div(days, 2);
    let ones = div(days + 1, 2);

    for (const num of a) {
        if (num === max) continue;
        let diff = max - num;
        if (diff % 2 === 1) {
            ones--;
            diff--;
        }
        if (ones < 0) return false;
        if (diff === 0) continue;
        let used2s = Math.min(div(diff, 2), twos);
        twos -= used2s;
        diff -= used2s * 2;
        if (diff === 0) continue;
        let used1s = Math.min(diff, ones);
        ones -= used1s;
        diff -= used1s;
        if (diff !== 0) return false;
    }
    return true;
}

const calc = (n, a)=>{
    if (n === 1) return 0;

    let max = a[0];
    for (const num of a) {
        max = Math.max(max, num);
    }

    let l = 0, r = 300000000000000;
    let mid;
    while (l < r) {
        mid = l + div((r - l), 2);
        // console.log(`mid`, mid);
        const res = check(a, mid, max) || check(a, mid, max + 1);
        // console.log(`res`, res);
        if (!res) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }

    return r;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

const readline = require('readline')

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

function solve(n, arr) {
    let max = -Infinity
    for (let i = 0; i < arr.length; i++) {
        max = Math.max(max, arr[i])
    }
    return Math.min(help(n, arr, max), help(n, arr, max + 1))
}
function help(n, arr, max) {
    //
    let odd = 0
    let even = 0
    for (let i = 0; i < arr.length; i++) {
        const d = max - arr[i]
        if (d & 1) {
            odd++
        }
        even += Math.floor(d / 2)
        // const r = d % 3
        // if (r === 1) {
        //     odd++
        // } else if (r === 2) {
        //     even++
        // }
        // ans += 2 * Math.floor(d / 3)
    }
// console.log(odd, even)
    let ans = 0
    if (odd > even) {
        ans = 2 * odd - 1
    } else {
        const diff = even - odd
        const k = Math.floor(diff / 3)
        const r = diff % 3
        ans = 2 * (odd + 2 * k)
        if (r === 1) {
            ans += 2
        } else if (r === 2) {
            ans += 3
        }
    }
    return ans
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function solve(n, data, max) {
  let b = 0,
    a = 0
  for (let i = 0; i < n; i++) {
    let num = max - data[i]
    if (num % 2) b++
    a += Math.floor(num / 2)
  }
  // if (b > a) return b * 2 - 1
  let x = Math.max(Math.floor((a - b) / 3), 0)
  a -= x
  b += 2 * x
  if (b === a - 2) {
    a--
    b += 2
  }
  if (b > a) return b * 2 - 1
  return a * 2
}

void (function main() {
  const _ = Number(inputs[0])
  let res = []

  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)
    let t = -1
    for (let [k, v] of data.entries()) {
      if (t === -1 || data[t] < v) t = k
    }

    let ans = solve(n, data, data[t])

    ans = Math.min(ans, solve(n, data, data[t] + 1))

    res.push(ans)
  }

  console.log(res.join('\n'))
})()

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

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

		const ans = [];
		let goal = 0;
		for (let i = 0; i < n; i++) goal = Math.max(goal, h[i]);
		for (let round = 0; round < 2; round++, goal++) {
			let need = 0, oddReq = 0, oddHas;
			for (let i = 0; i < n; i++) {
				need += goal - h[i];
				oddReq += (goal- h[i]) & 1;
			}
			ans[round] = Math.ceil(need*2/3);
			oddHas = Math.ceil(ans[round]/2);
			if (oddReq > oddHas) {
				ans[round] += (oddReq - oddHas) * 2 - (ans[round]%2 == 0 ? 1 : 0);
			}
			//console.log({oddHas});
		}

		console.log(Math.min(...ans));
	}
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function solve(n, data, max) {
  let b = 0,
    a = 0
  for (let i = 0; i < n; i++) {
    let num = max - data[i]
    if (num % 2) b++
    a += Math.floor(num / 2)
  }
  // if (b > a) return b * 2 - 1
  let x = Math.max(Math.floor((a - b) / 3), 0)
  a -= x
  b += 2 * x
  if (b === a - 2) {
    a--
    b += 2
  }
  if (b > a) return b * 2 - 1
  return a * 2
}

void (function main() {
  const _ = Number(inputs[0])
  let res = []

  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)
    let t = -1
    for (let [k, v] of data.entries()) {
      if (t === -1 || data[t] < v) t = k
    }

    let ans = solve(n, data, data[t])
    data[t]++
    ans = Math.min(ans, solve(n, data, data[t]))

    res.push(ans)
  }

  console.log(res.join('\n'))
})()

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function solve(n, data, max) {
  let b = 0,
    a = 0
  for (let i = 0; i < n; i++) {
    let num = max - data[i]
    if (num % 2) b++
    a += Math.floor(num / 2)
  }
  // if (b > a) return b * 2 - 1
  let x = Math.max(Math.floor((a - b) / 3), 0)
  a -= x
  b += 2 * x
  if (b === a - 2) {
    a--
    b += 2
  }
  if (b > a) return b * 2 - 1
  return a * 2
}

void (function main() {
  const _ = Number(inputs[0])
  let res = []

  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)
    let t = -1
    for (let [k, v] of data.entries()) {
      if (t === -1 || data[t] < v) t = k
    }

    let ans = solve(n, data, data[t])
    data[t]++
    ans = Math.min(ans, solve(n, data, data[t]) + 1)

    res.push(ans)
  }

  console.log(res.join('\n'))
})()

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function solve(n, data, max) {
  let b = 0,
    a = 0
  for (let i = 0; i < n; i++) {
    let num = max - data[i]
    if (num % 2) b++
    a += Math.floor(num / 2)
  }
  if (b > a) return b * 2 - 1
  let x = Math.ceil((a - b) / 3)
  a -= x
  b += 2 * x
  return a + b
}

void (function main() {
  const _ = Number(inputs[0])
  let res = []

  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)
    let t = -1
    for (let [k, v] of data.entries()) {
      if (t === -1 || data[t] < v) t = k
    }

    let ans = solve(n, data, data[t])
    data[t]++
    ans = Math.min(ans, solve(n, data, data[t]) + 1)

    res.push(ans)
  }

  console.log(res.join('\n'))
})()

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function solve(n, data) {
  let b = 0,
    a = 0,
    max = Math.max(...data)
  for (let i = 0; i < n; i++) {
    let num = max - data[i]
    if (num % 2) b++
    a += Math.floor(num / 2)
  }
  let x = Math.ceil((a - b) / 3)
  a -= x
  b += 2 * x
  return a + b
}
void (function main() {
  const _ = Number(inputs[0])
  let res = []

  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)

    res.push(solve(n, data))
  }

  console.log(res.join('\n'))
})()

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

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

		const goal = Math.max(...h);

		let need = 0, oddReq = 0, oddHas;
		for (let i = 0; i < n; i++) {
			need += goal - h[i];
			oddReq += (goal- h[i]) & 1;
		}

		let ans = Math.ceil(need*2/3);
		oddHas = Math.ceil(ans/2);
		if (oddReq > oddHas) {
			ans += (oddReq - oddHas) * 2 - (ans%2 == 0 ? 1 : 0);
		}

		console.log(ans);
	}
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const check = (a, days) => {
    let twos = div(days, 2);
    let ones = div(days + 1, 2);

    let max = a[0];
    for (const num of a) {
        max = Math.max(max, num);
    }

    for (const num of a) {
        if (num === max) continue;
        let diff = max - num;
        if (diff % 2 === 1) {
            ones--;
            diff--;
        }
        if (ones < 0) return false;
        if (diff === 0) continue;
        let used2s = Math.min(div(diff, 2), twos);
        twos -= used2s;
        diff -= used2s * 2;
        if (diff === 0) continue;
        let used1s = Math.min(diff, ones);
        ones -= used1s;
        diff -= used1s;
        if (diff !== 0) return false;
    }
    return true;
}

const calc = (n, a)=>{
    if (n === 1) return 0;

    let l = 0, r = 300000000000000;
    let mid;
    while (l < r) {
        mid = l + div((r - l), 2);
        // console.log(`mid`, mid);
        const res = check(a, mid);
        // console.log(`res`, res);
        if (!res) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }

    return r;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, a)=>{
    if (n === 1) return 0;
    let res = 0;

    let max = a[0];
    for (const num of a) {
        max = Math.max(max, num);
    }
    let rem = 0;
    let count = 0;
    for (const num of a) {
        if (num !== max) {
            rem += max - num;
            count++;
        }
    }

    const days2 = div(rem, 3);
    // console.log(`days2`, days2);
    const left = rem % 3;
    // console.log(`left`, left);
    res = (days2 * 2) + (left === 1 ? 1 : (left === 2 ? 2 : 0));

    return res;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, a)=>{
    if (n === 1) return 0;
    let res = 0;

    let max = a[0];
    for (const num of a) {
        max = Math.max(max, num);
    }
    let rem = 0;
    let count = 0;
    for (const num of a) {
        if (num !== max) {
            rem += max - num;
            count++;
        }
    }

    const days2 = div(rem, 3);
    const left = rem % 3;
    res = (days2 * 2) + (left === 1 ? 1 : 2);

    return res;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

const readline = require('readline')

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

function solve(n, arr) {
    let max = -Infinity
    for (let i = 0; i < arr.length; i++) {
        max = Math.max(max, arr[i])
    }
    //
    let odd = 0
    let even = 0
    for (let i = 0; i < arr.length; i++) {
        const d = max - arr[i]
        if (d & 1) {
            odd++
        }
        even += Math.floor(d / 2)
        // const r = d % 3
        // if (r === 1) {
        //     odd++
        // } else if (r === 2) {
        //     even++
        // }
        // ans += 2 * Math.floor(d / 3)
    }
// console.log(odd, even)
    let ans = 0
    if (odd > even) {
        ans = 2 * odd - 1
    } else {
        const diff = even - odd
        const k = Math.floor(diff / 3)
        const r = diff % 3
        ans = 2 * (odd + 2 * k)
        if (r === 1) {
            ans += 2
        } else if (r === 2) {
            ans += 3
        }
    }
    return ans
}

const readline = require('readline')

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

function solve(n, arr) {
    let max = -Infinity
    for (let i = 0; i < arr.length; i++) {
        max = Math.max(max, arr[i])
    }
    //
    let ans = 0
    let odd = 0
    let even = 0
    for (let i = 0; i < arr.length; i++) {
        const d = max - arr[i]
        if (d & 1) {
            odd++
        }
        even += Math.floor(d / 2)
        // const r = d % 3
        // if (r === 1) {
        //     odd++
        // } else if (r === 2) {
        //     even++
        // }
        // ans += 2 * Math.floor(d / 3)
    }
// console.log(ans, odd, even)
    if (odd >= even) {
        ans += 2 * odd - 1
    } else {
        const diff = even - odd
        const k = Math.floor(diff / 3)
        const r = diff % 3
        ans = 2 * (odd + 2 * k)
        if (r === 1) {
            ans += 2
        } else if (r === 2) {
            ans += 3
        }
    }
    return ans
}

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const MOD = 32768;

let can_achieve = (h, days, goal)=>{
  let doubles = Math.floor(days/2);
  let ones = Math.floor((days+1)/2);
  //l({doubles, ones, days})
  let leftovers = [];
  for (let x of h){
    if (goal-x>0){
      let g = goal-x;
      if (g%2){
        g--;
        ones--;
      }
      leftovers.push(g);
    }
  }
  //l({leftovers})
  if (ones<0)
    return false;
  for (let l of leftovers){
    let deduct_doubles = Math.min(doubles, Math.floor(l/2));
    doubles -= deduct_doubles;
    l -= deduct_doubles*2;
    let deduct_ones = Math.min(ones, l);
    ones -= deduct_ones;
    l -= deduct_ones;
    if (l>0)
      return false;
  }
  //l('yes')
  return true
};

const calc = (n, h)=>{
  h.sort((a, b)=>a-b);
  let min = h[0];
  let max = h[h.length-1]
  let l = 0, r = 3*1e14+5;
  while (l<r){
    let m = Math.floor((l+r)/2);
    if (can_achieve(h, m, max) || can_achieve(h, m, max+1))
      r = m;
    else
      l = m+1;
  }
  if (can_achieve(h, l-1, max) || can_achieve(h, l-1, max+1))
    return l-1;
  return l;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let h = ra();
      l('ans')
      print(calc(n, h));
    }
}

E.calc = calc;


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

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

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

function main() {
	var numPads = parseInt(readline(), 10);
	var visits = new Array(numPads);
	var currentPad = 1*1,
		jumpSize = numPads-1;
	for (var visitIndex = 0; visitIndex < numPads; ++visitIndex) {
		visits[visitIndex] = currentPad;
		currentPad += (visitIndex % 2 == 0 ? jumpSize : -jumpSize);
		--jumpSize;
	}
	print(visits.join(" "));
}

main();

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

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

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

function main() {
	var numPads = parseInt(readline(), 10);
	var visits = new Array(numPads);
	var currentPad = +1,
		jumpSize = numPads-1;
	for (var visitIndex = 0; visitIndex < numPads; ++visitIndex) {
		visits[visitIndex] = currentPad;
		currentPad += (visitIndex % 2 == 0 ? jumpSize : -jumpSize);
		--jumpSize;
	}
	print(visits.join(" "));
}

main();

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

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

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

function main() {
	var numPads = parseInt(readline(), 10);
	var visits = new Array(numPads);
	var currentPad = 1,
		jumpSize = numPads-1;
	for (var visitIndex = 0; visitIndex < numPads; ++visitIndex) {
		visits[visitIndex] = currentPad;
		currentPad += (visitIndex % 2 == 0 ? jumpSize : -jumpSize);
		--jumpSize;
	}
	print(visits.join(" "));
}

main();


print(function(n) {

	var zero = [];
	var ans = 0;
	var t = 1;
	for (var i = 0; i < n; i++)
		readline().split(' ').map(Number).reduce(function(a, b) {
			if (b === 0) zero.push(a);
			else ans += a, t += b - 1;
		});

	zero.sort(function(a, b) {
		return b - a
	});
	for (var i = 0, l = Math.min(t,zero.length); i < l; i++)
		ans += zero[i];

	return ans;
}(+readline()));

print(function(n) {

	var a = [];
	for (var i = 0; i < n; i++)
		a.push(readline().split(' ').map(Number));
	a.sort(function(a, b) {
		if (a[1] === b[1]) return b[0] - a[0];
		return b[1] - a[1];
	});

	var t = 1;
	var ans = 0;
	var i = 0;
	while (t > 0 && i < a.length) {
		ans += a[i][0];
		t += a[i][1]-1;
		i++;
	}
	return ans;
}(+readline()));

;(function () {

	print(function (n) {

		var cards = [], points = 0;

		while (n--) {
			cards.push(readline().split(' ').map(Number));
		}

		cards.sort(function (a, b) { return (b[1] * 1e5 + b[0]) - (a[1] * 1e5 + a[0]); });

		n = 1;
		for (var i = 0, _i = cards.length; i < _i && 0 < n; i++) {
			n += cards[i][1] - 1;
			points += cards[i][0];
		}

		return points;

	}(+readline()));

}.call(this));

print(function(n) {

	var zero = [];
	var ans = 0;
	var t = 0;
	for (var i = 0; i < n; i++)
		readline().split(' ').map(Number).reduce(function(a, b) {
			if (b === 0) zero.push(a);
			else ans += a, t += b - 1;
		});

	zero.sort(function(a, b) {
		return b - a
	});
	for (var i = 0, l = Math.min(t,zero.length); i < l; i++)
		ans += zero[i];

	return ans;
}(+readline()));


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--) {
		let [n, k] = rna();

		let ans = [];
		n -= k - 3;
		if (n % 2 == 0) {
			if (n % 4 == 0){
				ans = [n/2, n/4, n/4];
			} else {
				ans = [n/2-1, n/2-1, 2]
			}
		} else {
			ans = [(n-1)/2, (n-1)/2, 1];
		}

		ans.push(...Array(k-3).fill(1));

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

'use strict';

function solve(n, m) {
  let res = [],
      one = 0;
  if (n & 1) {
    if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;
    m--;
    one++;
    n--;
  }
  for (let i = 30; i >= 0; i--) {
    if (res.length) {
      while (1 << i <= n) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    } else {
      if (1 << i <= n / 2) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    }
  }
  if (res.length === m) {
    if (one) res.push(1);
    return res.join(' ');
  } else if (res.length > m) {
    let sum = res.splice(2, res.length - m).reduce((a, b) => a + b, 0) / 2;
    res[0] += sum;
    res[1] += sum;
    if (one) res.push(1);
    return res.join(' ');
  }
  m -= res.length;
  while (m--) {
    let cur = res[res.length - 1];
    if (cur === 2) {
      res.pop();
      one += 2;
    } else {
      res[res.length - 1] /= 2;
      res.push(cur / 2);
    }
  }
  return (res.join(' ') + ' 1'.repeat(one)).trim();
}

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

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    // var a = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var ans = new Array(k).fill(1)
    n = n-(k-3)
    var x
    if (n % 2 === 1) {
      x = (n - 1) / 2
      ans[0] = 1
      ans[1] = x
      ans[2] = x
      // return console.log(1, x, x)
    }
    if (n % 2 === 0) {
      ans[0] = 2
      ans[1] = (n-2)/2
      ans[2] = (n-2)/2
    }

    if (n % 4 === 0) {
      x = n / 4
      ans[0] = x*2
      ans[1] = x
      ans[2] = x
    }

    return console.log(ans.join(' '))

  });
}

'use strict';

function solve(n, m) {
  let res = [],
      one = 0;
  if (n & 1) {
    if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;
    m--;
    one++;
    n--;
  }
  for (let i = 30; i >= 0; i--) {
    if (res.length) {
      while (1 << i <= n) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    } else {
      if (1 << i <= n / 2) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    }
  }
  if (res.length === m) {
    if (one) res.push(1);
    return res.join(' ');
  } else if (res.length > m) {
    let sum = res.splice(2, res.length - m + 2).reduce((a, b) => a + b, 0) / 2;
    res[0] += sum;
    res[1] += sum;
    if (one) res.push(1);
    return res.join(' ');
  }
  m -= res.length;
  while (m--) {
    let cur = res[res.length - 1];
    if (cur === 2) {
      res.pop();
      one += 2;
    } else {
      res[res.length - 1] /= 2;
      res.push(cur / 2);
    }
  }
  return (res.join(' ') + ' 1'.repeat(one)).trim();
}

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

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


print(function(n, m) {
	var ans = [],
		t = 0,
		a = ('0 ' + readline()).split(' ').map(Number);

	for (var i = 0; i < m; i++) {
		go.apply(0, rn());
	}

	return ans.join('\n');

	function go(type, x, y) {
		if (type === 1) a[x] = y - t;
		else if (type === 2) t += x;
		else ans.push(a[x] + t);
	}

} .apply(0, rn()));
function rn() {
	return readline().split(' ').map(Number);
}

function main()
{
    var tmp;
    tmp = readline().split(" ").map(function (x) { return parseInt(x); });
    var n = tmp[0],
        m = tmp[1];
    var a = readline().split(" ").map(function (x) { return parseInt(x); });
    var y = 0;
    while ( m-- )
    {
        tmp = readline().split(" ").map(function (x) { return parseInt(x); });
        if ( tmp[0] == 1 )
        {
            a[tmp[1]-1] = tmp[2]-y;
        }
        else if ( tmp[0] == 2 )
        {
            y += tmp[1];
        }
        else if ( tmp[0] == 3 )
        {
            print(a[tmp[1]-1]+y);
        }
    }
}

main();

function main(){
    var tmp;
    tmp = readline().split(" ").map(function (x) { return parseInt(x); });
    var n = tmp[0],
        m = tmp[1];
    var a = readline().split(" ").map(function (x) { return parseInt(x); });
    var y = 0;
    while ( m-- ){
        tmp = readline().split(" ").map(function (x) { return parseInt(x); });
        if ( tmp[0] == 1 ){
            a[tmp[1]-1] = tmp[2]-y;
        }
        else if ( tmp[0] == 2 ){
            y += tmp[1];
        }
        else if ( tmp[0] == 3 ){
            print(a[tmp[1]-1]+y);
        }
    }
}

main();

print(function(n, m) {
	var ans = [],
		t = 0,
		a = ('0 ' + readline()).split(' ').map(Number);

	for (var i = 0; i < m; i++) {
		var l = readline().split(' ').map(Number);
		if (l[0] === 1)
			a[l[1]] = l[2] - t;
		else if (l[0] === 2)
			t += l[1];
		else
			ans.push(a[l[1]] + t);
	}

	return ans.join('\n');

} .apply(0, readline().split(' ').map(Number)));

var data = readline().split(" ").map( c => parseInt(c))
var arra = readline().split(" ").map( c => parseInt(c))
var artt = new Array(arra.length).fill(0)
var incre = 0
for (var i = 0; i< data[1]; i++){
	var query = readline().split(" ").map( c => parseInt(c))
	if (query[0] == 1){
		arra[query[1]-1] = query[2]
		artt[query[1]-1] = incre
	}
	else if (query[0] == 2){
		incre += query[1]
	}
	else {
		print(arra[query[1]-1]+incre-artt[query[1]-1])
	}
}


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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var tmp = nextIntArray();
    var A = tmp[0];
    var B = tmp[1];
    output[i] = Math.ceil(Math.abs(A - B) / 10);
  }
  myout(myconv(output, 9));
}

const {EOL} = require('os')
function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

let i = ''

process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {

    const lines = i.split(EOL).slice(1)

    for( let line of lines ) {
      if(line.split` `.length>1)
      console.log(solve(...line.split` `))
    }
})

T = readline();

while ( T-- ) {
    a = readline().split(' ');

    d = Math.abs ( a[0] - a[1] );

    print (Math.floor(d/10) + ( d % 10 !== 0 ) );
}

T = readline();
while (T--) {
  a = readline().split(' ');
  d = Math.abs(+a[0] - +a[1]);
  print(Math.floor(d / 10) + (d % 10 ? 1 : 0));
}

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}
const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
readline.on('line', line => {
    if(line.split` `.length > 1)
  console.log(solve(...line.split` `));
});

const {EOL} = require('os')

let i = ''

process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {

    const lines = i.split(EOL).slice(1)

    for( let line of lines ) {
      if(line.split` `.length>1)
      console.log(solve(...line.split` `))
    }
})

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

const readline = require("readline");

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

const lines = [];

reader.on("line", (line) => {
  const nums = line.split(" ").map(Number);
  lines.push(nums);
});

reader.on("close", () => {
  const [N, ...tests] = lines;

  for (let i = 0; i < tests.length; i++) {
    let A = tests[i][0];
    let B = tests[i][1];

    if (A === B) {
      console.log(0);
    } else if (A > B) {
      let diff = A - B;
      if (diff <= 10) {
        console.log(1);
      } else {
        console.log(Math.ceil(diff / 10));
      }
    } else if (A < B) {
      let diff1 = B - A;
      if (diff1 <= 10) {
        console.log(1);
      } else {
        console.log(Math.ceil(diff1 / 10));
      }
    }
  }
});

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

    A();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [a,b] = ti(readline().split(' '));

        if(a === b){
            console.log(0);
            continue;
        }

        let d = Math.abs(a-b);
        if(d <= 10){
            console.log(1);
            continue;
        }else{
            if(d % 10 !== 0)
                console.log(1 + Math.floor(d/10));
            else
                console.log(d / 10);
        }
    }
}

'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++];
}
/**
6
5 5
13 42
18 4
1337 420
123456789 1000000000
100500 9000

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let [x, y] = readline().split(" ");

    if(x === y) {
        console.log(0);
        return;
    }

    console.log(Math.ceil(Math.abs(x - y) / 10));

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
let standardInputString = "";
let currentLine = 0;

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

process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});

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

  main();
});

function main() {
  const n = parseInt(readLine());
  for (let i = 0; i < n; i++) {
    let l = readLine()
      .split(" ")
      .map((el) => parseInt(el));
    let [a, b] = l;
    let res = Math.ceil(Math.abs(a - b) / 10);
    console.log(res);
  }
}

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

rl.question("", function (n) {
  functions();
})
function functions() {
  rl.question('', function (k) {
    var input = k.split(' ');
    var a = parseInt(input[0]);
    var b = parseInt(input[1]);
    var output;
    // if (a == 'undefined' || b == 'undefined') {
    //
    // }
    if (a > b) {
      output = Math.ceil((a - b) / 10);
    } else if (b > a) {
      output = Math.ceil((b - a) / 10);
    } else if (a == b) {
      output = 0;
    }
    console.log(output);
    functions();
  })
}

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 [a, b] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const diff = Math.abs(a - b);
    let ans = Math.floor(diff / 10);
    if (diff % 10 !== 0) ans++;
    console.log(ans);
  }
}

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

let input = [];

rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solve(input);
  process.exit();
});

function solve(input) {
  const t = input[0];

  for (let x = 1; x <= t; x++) {
    const [a, b] = input[x].split(" ").map((num) => Number(num));

    if (b === a) {
      console.log(0);
      continue;
    }

    const diff = Math.abs(b - a);

    const tenCnt = parseInt(diff / 10);
    const oneCnt = diff % 10 > 0 ? 1 : 0;

    console.log(tenCnt + oneCnt);
  }
}

/*
  Q. a를 b가 되게 하기 위한 최소한의 move 횟수는?

  1. 2개의 정수 a, b
  2. 1 ~ 10 사이의 정수 k를 선택 -> a에 더하거나 빼기
  3. 각 move마다 서로 다른 k를 선택가능

*/

const readline = require("readline");
const r1 = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
function moves(a,b){

        let num1= Number(a);
        let num2 = Number(b);

    // if( isNaN(num1) ) console.error(" Bhul Hoise");
    // if( isNaN(num2) ) console.error("Etao Bhul Hoise");

        let diff = Math.abs (num2-num1);
        let div = parseInt(diff/10);
        let quo = diff%10;

        if(quo>0) quo=1;
        let move = div+quo;

        console.log(move);

}

let inputs = [];

r1.on("line",function(a){
   inputs.push(a);
});

r1.on("close",function(){

    for(let i=1; i<inputs.length; ++i){
        let vals = inputs[i].split(" ");
        moves(vals[0],vals[1]);
        //console.log(inputs[i].split(" "));
    }

});

const readline = require("readline");
const r1 = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
function moves(a,b){

        let num1= Number(a);
        let num2 = Number(b);

    if( isNaN(num1) ) console.error(" Bhul Hoise");
    if( isNaN(num2) ) console.error("Etao Bhul Hoise");

        let diff = Math.abs (num2-num1);
        let div = parseInt(diff/10);
        let quo = diff%10;

        if(quo>0) quo=1;
        let move = div+quo;

        console.log(move);

}

let inputs = [];

r1.on("line",function(a){
   inputs.push(a);
});

r1.on("close",function(){

    for(let i=1; i<inputs.length; ++i){
        let vals = inputs[i].split(" ");
        moves(vals[0],vals[1]);
        //console.log(inputs[i].split(" "));
    }

});

const readline = require("readline");
const r1 = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
function moves(a,b){

        let num1= Number(a);
        let num2 = Number(b);

    // if( isNaN(num1) ) console.error(" Bhul Hoise");
    // if( isNaN(num2) ) console.error("Etao Bhul Hoise");

        let diff = Math.abs (num2-num1);
        let div = parseInt(diff/10);
        let quo = diff%10;

        if(quo>0) quo=1;
        let move = div+quo;

        console.log(move);

}

let testCases;

r1.on("line",function(a){

   let vals = a.trim().split(" ");
   if(vals.length === 1 && testCases === undefined){
       testCases = Number(vals[0]);
   }
   else if(vals.length === 2)
   {
       testCases--;
       moves(vals[0],vals[1]);
   }
   if(testCases === 0){
       r1.close();
   }

});

// r1.on("close",function(){

//     for(let i=1; i<inputs.length; ++i){
//         let vals = inputs[i].split(" ");
//         moves(vals[0],vals[1]);
//         //console.log(inputs[i].split(" "));
//     }

// });

const readline = require("readline");
const r1 = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
function moves(a,b){

        let num1= Number(a);
        let num2 = Number(b);

    if( isNaN(num1) ) throw "Bhul hoise";
    if( isNaN(num2) ) throw "Etao Bhul Hoise";

        let diff = Math.abs (num2-num1);
        let div = parseInt(diff/10);
        let quo = diff%10;

        if(quo>0) quo=1;
        let move = div+quo;

        console.log(move);

}

let inputs = [];

r1.on("line",function(a){
   inputs.push(a);
});

r1.on("close",function(){

    for(let i=1; i<inputs.length; ++i){
        let vals = inputs[i].split(" ");
        moves(vals[0],vals[1]);
        //console.log(inputs[i].split(" "));
    }

});

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i < b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = b - 1; i >= a; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

(async () => {
  await inputPromise;
  let inp = input.split(/\D+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(0, t, i => {
    let a = inp[r++], b = inp[r++];
    console.log(Math.ceil(Math.abs(a - b) / 10))
  })
})();

const { SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION } = require('constants')

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*/
    for (let i = 1; i < lines.length - 1; ++i) {
      const [a, b] = lines[i].split(' ')
      const answer = solution(a, b)
      console.log(answer)
    }
})

function solution(a, b) {
  if (b === a) {
    return 0
  }

  const r = Math.abs(b - a)

  return (
    Math.floor(r/10)
    + ((r % 10 === 0) ? 0 : 1)
  )
}

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

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

readLine.on("line", (line) => input.push(line));
readLine.on("close", () => {
  let t = parseInt(input[0]);

  for (let i = 1; i <= t; i += 1) {
    const [a, b] = splitAndParseInt(input[i]);

    if (a === b) {
      console.log(0);
    } else if (a < b) {
      const diff = Math.ceil((b - a) / 10);
      console.log(diff);
    } else {
      console.log(Math.ceil((a - b) / 10));
    }
  }
});

function solve(a, b) {
  const base = 10;
  const diff = Math.abs(a - b);
  const r = diff % base;
  const q = (diff - r) / base;
  return (r === 0) ? q : (q + 1);
}

function main(lines) {
  lines.shift();
  const whitespace = /\s+/;
  for (const line of lines) {
    const [a, b] = line.split(whitespace).map(Number);
    const result = solve(a, b);
    console.log(result);
  }
}

function trim_line(s) {
  return s.trim();
}

function has_content(s) {
  return (s.length > 0);
}

async function processLinesFromStream(rs, pf) {
  const chunks = [];
  const encoding = 'utf-8';
  rs.setEncoding(encoding);
  for await (let chunk of rs) {
    chunks.push(chunk);
  }
  const empty = '';
  const newline = /\n/;
  const lines = chunks.join(empty)
                      .split(newline)
                      .map(trim_line)
                      .filter(has_content);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

function solve(a, b) {
  const base = 10;
  const diff = Math.abs(a - b);
  const r = diff % base;
  const q = (diff - r) / base;
  return (r === 0) ? q : (q + 1);
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    let t = line.trim();
    if (line.length > 0) {
      const [a, b] = t.split(/\s+/).map(Number);
      const result = solve(a, b);
      console.log(result);
    }
  }
}

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding("utf-8");
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

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

//     for( var line of lines ){
//         var [a,b] = line.split(' ');
//         console.log(solve(a,b));
//     }

// });

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

// // single line input
// readline.on('line', line => {
//   readline.close(), console.log(line);
// });
// var m = [];
// multi line input
// readline.on('line', line => {
//   line = line.split` `
//   console.log(line[0])
// });
let i = ''

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

    for( let line of lines ) {
      if(line.split` `.length>1)
      console.log(solve(...line.split` `))
    }
})

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

rl.question("", function (n) {
  functions();
})
function functions() {
  rl.question('', function (k) {
    var input = k.split(' ');
    var a = parseInt(input[0]);
    var b = parseInt(input[1]);
    var output;
    if (a > b) {
      output = Math.ceil((a - b) / 10);
    } else if (b > a) {
      output = Math.ceil((b - a) / 10);
    } else if (a == b) {
      output = 0;
    }
    console.log(output);
    functions();
  })
}

const readline = require("readline");
const r1 = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
function moves(a,b){

        let num1= Number(a);
        let num2 = Number(b);

        let diff = Math.abs (num2-num1);
        let div = parseInt(diff/10);
        let quo = diff%10;

        if(quo>0) quo=1;
        let move = div+quo;

        console.log(move);

}

let inputs = [];

r1.on("line",function(a){
   inputs.push(a);
});

r1.on("close",function(){

    for(let i=1; i<inputs.length; ++i){
        let vals = inputs[i].split(" ");
        moves(vals[0],vals[1]);
        //console.log(inputs[i].split(" "));
    }

});

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

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

    for( var line of lines ){
        console.log(line);
        var [a,b] = line.split(' ')
        console.log(solve(a,b));
    }

});

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

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

//     for( var line of lines ){
//         var [a,b] = line.split(' ');
//         console.log(solve(a,b));
//     }

// });

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

// // single line input
// readline.on('line', line => {
//   readline.close(), console.log(line);
// });
// var m = [];
// multi line input
// readline.on('line', line => {
//   line = line.split` `
//   console.log(line[0])
// });
let i = ''

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

    for( let line of lines ) console.log(solve(...line.split` `))
})

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

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

    for( var line of lines ){
        // console.log(line);
        var [a,b] = line.split(' ')
        console.log(solve(a,b));
    }

});

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

let i = ''

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

    for( let line of lines ) console.log(solve(...line.split` `))
})

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

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*/
    // console.log(lines);

    for( var line of lines ){
        var [a,b] = line.split(' ');
        console.log(solve(a,b));
    }

});

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10);
}

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

    for( var line of lines ){
        var [a,b] = line.split(' ');
        console.log(solve(a,b));
    }

});

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10)
}

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

    for( var line of lines ){
        console.log(line)
        solve(...line.split` `)
    }

})

function solve(a,b){
    return Math.ceil((Math.max(a,b) - Math.min(a,b)) / 10)
}

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

    for( var line of lines ){
        // console.log(line)
        console.log(solve(...line.split` `))
    }

})


process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function myFunc(a, b, c, d){
    a = BigInt(a);
    b = BigInt(b);
    c = BigInt(c);
    d = BigInt(d);

    let x = BigInt(a*d);
    let y = BigInt(b*c);

    // console.log(x, y);

    if(x == y) return 0;
    if(a == 0 || c == 0) return 1;
    if( (x % y) == 0 || (y % x) == 0) return 1;

    return 2;
}

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [a, b, c, d] = input[index]
      .split(" ")
      .map((item) => BigInt(parseInt(item)));
    const testCase = {
      a,
      b,
      c,
      d,
    };
    testCases.push(testCase);
  }
}

const gcd = (a, b) => (b ? gcd(b, a % b) : [a]);

const egcd = (a, b) => {
  let [oldR, r] = [a, b];
  let [oldS, s] = [1, 0];
  let [oldT, t] = [0, 1];

  while (r) {
    const q = Math.floor(oldR / r);
    [oldR, r] = [r, oldR - q * r];
    [oldS, s] = [s, oldS - q * s];
    [oldT, t] = [t, oldT - q * t];
  }
  return [oldR, oldS, oldT];
};

function solution(testCase) {
  let { a, b, c, d } = testCase;

  // console.log(a, b, c, d);

  let result = 0;

  if (a * d == b * c) {
    result = 0;
  } else if (a == 0 || c == 0) {
    result = 1;
  } else {
    const [g1] = gcd(a, b);
    const [g2] = gcd(c, d);
    // console.log(a / g1, b / g1, c / g2, d / g2);
    a = a / g1;
    b = b / g1;
    c = c / g2;
    d = d / g2;
    const [g] = gcd(a * d, b * c);
    if ((a * d) / g != 1) result++;
    if ((b * c) / g != 1) result++;
    // console.log(a, b, c, d, g, (a * d) / g, (b * c) / g);
  }

  console.log(result);
  // console.log("------");
}

parseInput();

testCases.forEach(solution);

process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "",
  currentLine = 0;
process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((string) => string.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// code here

function main() {
  const t = +readLine(); // convert t in number
  for (let i = 0; i < t; i++) {
    // iterate in each case
    // const n = +readLine();
    const arr = readLine()
      .split(" ")
      .map((p) => +p); // convert p in number
    let a = BigInt(arr[0]);
    let b = BigInt(arr[1]);
    let c = BigInt(arr[2]);
    let d = BigInt(arr[3]);
    let x = BigInt(a * d);
    let y = BigInt(b * c);
    if (x == y) {
      console.log(0);
    } else if (a == 0 || c == 0) {
      console.log(1);
    } else if (x % y == 0 || y % x == 0) {
      console.log(1);
    } else {
      console.log(2)
    }
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function gcd(a,  b){
    if (a == 0) return b;
    return gcd(b % a, a);
}

function myFunc(a, b, c, d){

    let gcd_ab = gcd(a, b);
    let gcd_cd = gcd(c, d);
    a = a/gcd_ab;
    b = b/gcd_ab;
    c = c/gcd_cd;
    d = d/gcd_cd;

    let x = BigInt(a*d);
    let y = BigInt(b*c);

    // console.log(x, y);

    if(x == y) return 0;
    if(a == 0 || c == 0) return 1;
    if( (x % y) == 0 || (y % x) == 0) return 1;

    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function gcd(a,  b){
    if (a == 0) return b;
    return gcd(b % a, a);
}

function myFunc(a, b, c, d){
    if(a == 0 || c == 0) return 1;

    let gcd_ab = gcd(a, b);
    let gcd_cd = gcd(c, d);
    a = a/gcd_ab;
    b = b/gcd_ab;
    c = c/gcd_cd;
    d = d/gcd_cd;

    let x = BigInt(a*d);
    let y = BigInt(b*c);

    if(x == y) return 0;
    if( (x % y) == 0 || (y % x) == 0) return 1;

    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;

    if( (a % b) == 0 && (d % c) == 0) return 1;
    if( (a % c) == 0 && (d % b) == 0) return 1;

    if( (b % a) == 0 && (c % d) == 0) return 1;
    if( (b % d) == 0 && (c % a) == 0) return 1;

    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function gcd(a,  b){
    if (a == 0) return b;
    return gcd(b % a, a);
}

function myFunc(a, b, c, d){
    let gcd_ab = gcd(a, b);
    let gcd_cd = gcd(c, d);
    a = a/gcd_ab;
    b = b/gcd_ab;
    c = c/gcd_cd;
    d = d/gcd_cd;

    const x = a * d;
    const y = b * c;
    if(x == y) return 0;
    if(a == 0 || c == 0) return 1;
    if( (x % y) == 0 || (y % x) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function gcd(a,  b){
    if (a == 0) return b;
    return gcd(b % a, a);
}

function myFunc(a, b, c, d){
    let gcd_ab = gcd(a, b);
    let gcd_cd = gcd(c, d);
    a = a/gcd_ab;
    b = b/gcd_ab;
    c = a/gcd_cd;
    d = b/gcd_cd;
    const x = a * d;
    const y = b * c;
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    if( (x % y) == 0 || (y % x) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    const x = a*d;
    const y = b*c;
    if( (x % y) == 0 || (y % x) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

//reenviar
function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    const x = a*d;
    const y = b*c;
    if( x % y == 0 || y % x == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

//reenviar
function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    if(((a*d) % (b*c)) == 0 || ((b*c) % (a*d)) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

//reenviar
function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    if((a*d % b*c) == 0 || (b*c % a*d) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

//reenviar
function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;

    if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

//reenviar
function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    if(a == b || c == d) return 1;
    // if(a == c || b == d) return 1;
    if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;

    if(a == b || c == d) return 1;
    if(a == c || b == d) return 1;

    if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;
    return 2;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    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);
        let result = myFunc(arr[0], arr[1], arr[2], arr[3]);
        console.log(result);
    }
}

function myFunc(a, b, c, d){
    if(a*d == b*c) return 0;
    if(a == 0 || c == 0) return 1;
    if(a == b || c == d) return 1;

    if((a*d) % (b*c) == 0 || (b*c) % (a*d) == 0) return 1;
    return 2;
}

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

// Main Function, code here

function main() {
  const testCases = readline();
  for (let i = 0; i < testCases; i++) {
    const arrFrac = readline()
      .split(" ")
      .map((number) => parseInt(number));
    const a = arrFrac[0];
    const b = arrFrac[1];
    const c = arrFrac[2];
    const d = arrFrac[3];
    let x = a * d
    let y = b * c
    if (a / b === c / d) {
      console.log(0);
    } else if (a === 0 || c === 0) {
      console.log(1);

    } else if (x % y == 0 || y % x == 0) {
      console.log(1);
    } else {
      console.log(2);
    }
  }
}

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const testCases = readline();
  for (let i = 0; i < testCases; i++) {
    const arrFrac = readline().split(" ").map((number) => parseInt(number));
    const a = arrFrac[0];
    const b = arrFrac[1];
    const c = arrFrac[2];
    const d = arrFrac[3];
    if (a / b === c / d) {
      console.log(0);
    } else if (a === 0 || c === 0) {
      console.log(1);
    } else if ((a * d) % (c * b) === 0 || (c * b) % (a * d) === 0) {
      console.log(1);
    } else {
      console.log(2);
    }
  }
}

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

// Main Function, code here

function main() {
  const testCases = readline();
  for (let i = 0; i < testCases; i++) {
    const arrWFrac = readline().split(" ").map(number => parseInt(number))
    let numerator = arrWFrac[0] / arrWFrac[2]
    let denominator = arrWFrac[1] / arrWFrac [3]
    if (numerator === Infinity) {
      numerator = 0
    }
    if (!denominator || denominator === Infinity) {
      denominator = 0
    }

    if (numerator === denominator || isNaN(numerator)) {
      console.log(0)
    } else if (Number.isInteger(numerator) || Number.isInteger(denominator)) {
      console.log(1)
    } else {
      console.log(2)
    }
  }
}

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [a, b, c, d] = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      a,
      b,
      c,
      d,
    };
    testCases.push(testCase);
  }
}

function solution(testCase) {
  const { a, b, c, d } = testCase;

  const gcd = (e, f) => (f ? gcd(f, e % f) : e);

  const g1 = gcd(a, b);
  const g2 = gcd(c, d);

  const aa = a / g1;
  const bb = b / g1;
  const cc = c / g2;
  const dd = d / g2;

  const g = gcd(aa * dd, bb * cc);

  let result = [(aa * dd) / g, (bb * cc) / g].filter((v) => v != 1).length;
  if (aa == 0 && cc == 0) result = 0;

  console.log(result);
}

parseInput();

testCases.forEach(solution);

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [a, b, c, d] = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      a,
      b,
      c,
      d,
    };
    testCases.push(testCase);
  }
}

function solution(testCase) {
  const { a, b, c, d } = testCase;

  const gcd = (e, f) => (f ? gcd(f, e % f) : e);

  const g = gcd(a * d, b * c);

  let result = [(a * d) / g, (b * c) / g].filter((v) => v != 1).length;
  if (a == 0 && c == 0) result = 0;
  console.log(result);
}

parseInput();

testCases.forEach(solution);


let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var n = k[0], m = k[1];
        var ans = '';
        console.log(n - m + Math.floor(m / 2));
        for(j = m + 1; j <= n; j++){
            ans += j + ' ';
        }
        for(j = Math.floor((m + 1) / 2); j < m; j++){
            ans += j + ' ';
        }
        console.log(ans);
	}
});

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) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([n, k]) {
    let res = [], counter = 0
    counter += n - k
    counter += Math.floor(k / 2)
    console.log(counter)
    for (let i = k + 1; i <= n; ++i) res.push(i)
    for (let i = 1; i <= Math.floor(k / 2); ++i) res.push(k - i)
    console.log(res.join(' '))
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  // var [n, k, l] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })

  Array(Number(x)).fill(1).map((t, iii) => {
    //   var n = parseInt(readline())
    // var [a, b, c] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    //
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    // var a = readline().split('').map((x, iii) => {
    //   return parseInt(x)
    // })
    // for (let i = Math.floor(k/2); i <= n; i++) {
    //   if(i!==k) res.push(i)
    // }
    var res = []
    var values = {}
    var btm = k % 2===1 ? Math.floor(k/2)+1 : Math.floor(k/2)
    for (let i = k-1; i >= btm; i--) {
      // var canAdd = true
      // Object.keys(values).map(key => {
      //   if (parseInt(key) + i === k) canAdd = false
      // })
      // if (!canAdd || i === k) continue
      // Object.keys(values).map(key => {
      //   values[parseInt(key) + i] = true
      // });
      // values[i] = true
      res.push(i)
    }
    for (let i = k+1; i <= n; i++) {
      res.push(i)
    }

    // console.log(values)
    console.log(res.length)
    console.log(res.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 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 K = nextInt();
		var output = [];
		myout(N - K + Math.floor(K / 2));
		for(var j = K + 1; j <= N; j++){
			output.push(j);
		}
		for(var j = Math.floor((K + 1) / 2); j < K; j++){
			output.push(j);
		}
		myout(myconv(output, 8));
	}
}

let lines=require('fs').readFileSync(0).toString().split('\n'),line=0;
input=()=>lines[line++];
for(let t=+input();t--;){
    let [n,k]=input().split(' ').map(Number),ans=[];
    console.log(n-k+~~(k/2));
    for(let i=k+1;i<=n;i++) ans.push(i);
    for(let i=~~((k+1)/2);i<k;i++) ans.push(i);
    console.log(ans.join(' '));
}

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

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var nk = readNumArray();
    var n = nk[0];
    var k = nk[1];
    var kSum = 0;
    var arr = [];
    for (var j = k - 1; j > (k - 1) / 2; j--) {
      arr.push(j);
    }
    for (var j = k + 1; j <= n; j++) {
      arr.push(j);
    }
    print(arr.length);
    print(arr.join(' '));
  }
}

main();

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) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([n, k]) {
    let arr = Array(n)
        .fill(1)
        .map((_, i) => i + 1)
        .filter(i => i !== k)
    if (!arr.length) return null
    for (let j = 0; ; j++) {
        let subarr = arr.filter(i => i <= k)
        let sum = subarr.reduce((acc, curr) => acc + curr, 0)
        if (sum !== k) return arr
        else arr.splice(arr.indexOf(subarr[subarr.length - 1]), 1)
    }

}

function main() {
    for (let i = 0; i < inputArr.length; i++) {
        let res = solve(inputArr[i])
        if (res && res.length) {
            console.log(res.length)
            console.log(res.join(' '))
        } else console.log(0)
    }
}

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) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([n, k]) {
    let arr = Array(n)
        .fill(1)
        .map((_, i) => i + 1)
        .filter(i => i !== k)
    if (!arr.length) return null
    for (let j = 0; ; j++) {
        let sum = arr.filter(i => i <= k).reduce((acc, curr) => acc + curr, 0);
        if (sum !== k) return arr
        else arr.shift()
    }

}

function main() {
    for (let i = 0; i < inputArr.length; i++) {
        let res = solve(inputArr[i])
        if (res && res.length) {
            console.log(res.length)
            console.log(res.join(' '))
        } else console.log(0)
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j].split('');
        var answer = k.length;
        console.log(answer);
    }
});

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

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var nk = readNumArray();
    var n = nk[0];
    var k = nk[1];
    var kSum = 0;
    var arr = [];
    for (var j = 1; j < k; j++) {
      kSum += j;
      if (kSum >= k) {
        break;
      }
      arr.push(j);
    }
    for (var j = k + 1; j <= n; j++) {
      arr.push(j);
    }
    print(arr.length);
    print(arr.join(' '));
  }
}

main();

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

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var nk = readNumArray();
    var n = nk[0];
    var k = nk[1];
    var kSum = 0;
    var arr = [];
    for (var j = 1; j < k; j++) {
      kSum += j;
      if (kSum !== k) {
        arr.push(j);
      }
      if (kSum >= k) {
        break;
      }
    }
    for (var j = k + 1; j <= n; j++) {
      arr.push(j);
    }
    print(arr.length);
    print(arr.join(' '));
  }
}

main();