You are given two integers $$$a$$$ and $$$b$$$.In one move, you can choose some integer $$$k$$$ from $$$1$$$ to $$$10$$$ and add it to $$$a$$$ or subtract it from $$$a$$$. In other words, you choose an integer $$$k \in [1; 10]$$$ and perform $$$a := a + k$$$ or $$$a := a - k$$$. You may use different values of $$$k$$$ in different moves.Your task is to find the minimum number of moves required to obtain $$$b$$$ from $$$a$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

For each test case, print the answer: the minimum number of moves required to obtain $$$b$$$ from $$$a$$$.

NoteIn the first test case of the example, you don't need to do anything.In the second test case of the example, the following sequence of moves can be applied: $$$13 \rightarrow 23 \rightarrow 32 \rightarrow 42$$$ (add $$$10$$$, add $$$9$$$, add $$$10$$$).In the third test case of the example, the following sequence of moves can be applied: $$$18 \rightarrow 10 \rightarrow 4$$$ (subtract $$$8$$$, subtract $$$6$$$).

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

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

//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 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 {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` `))
    }
})

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

}

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

})


Burenka came to kindergarden. This kindergarten is quite strange, so each kid there receives two fractions ($$$\frac{a}{b}$$$ and $$$\frac{c}{d}$$$) with integer numerators and denominators. Then children are commanded to play with their fractions.Burenka is a clever kid, so she noticed that when she claps once, she can multiply numerator or denominator of one of her two fractions by any integer of her choice (but she can't multiply denominators by $$$0$$$). Now she wants know the minimal number of claps to make her fractions equal (by value). Please help her and find the required number of claps!

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then follow the descriptions of each test case. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 \leq a, c \leq 10^9$$$, $$$1 \leq b, d \leq 10^9$$$) — numerators and denominators of the fractions given to Burenka initially.

For each test case print a single integer — the minimal number of claps Burenka needs to make her fractions equal.

NoteIn the first case, Burenka can multiply $$$c$$$ by $$$2$$$, then the fractions will be equal.In the second case, fractions are already equal.In the third case, Burenka can multiply $$$a$$$ by $$$4$$$, then $$$b$$$ by $$$3$$$. Then the fractions will be equal ($$$\frac{1 \cdot 4}{2 \cdot 3} = \frac{2}{3}$$$).

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

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

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

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


You are given two integers $$$n$$$ and $$$k$$$. You are asked to choose maximum number of distinct integers from $$$1$$$ to $$$n$$$ so that there is no subset of chosen numbers with sum equal to $$$k$$$.A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.

The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 100$$$). Each of the next $$$T$$$ lines contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 1000$$$) — the description of test cases.

For each test case output two lines. In the first line output a single integer $$$m$$$ — the number of chosen integers. In the second line output $$$m$$$ distinct integers from $$$1$$$ to $$$n$$$ — the chosen numbers. If there are multiple answers, print any. You can print the numbers in any order.

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

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

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


Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.

Print a single number — the minimum number of operations needed to make all the letters read.

NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.

var n= readline();
var stateLetters= readline().replace(/\s/g,"").replace(/0/g," ");
stateLetters= stateLetters.trim();
var costoLettersLeidosDosOperaciones= (stateLetters.match(/\s+1/g)|| "").length* 2;
var costoLettersLeidosUnaOperacion= (stateLetters.replace(/\s+1/g, "")|| "").length;
print(costoLettersLeidosDosOperaciones+ costoLettersLeidosUnaOperacion);

var n = parseInt(readline());

var l = readline().trim().split(' ').map((x)=>parseInt(x));

var ans = 0;

var isOne = false;
var nbrOnes=0;
for(var i=0;i<n;i++){
    if(l[i]==0){
        if(nbrOnes>0)
        ans+=nbrOnes+1;
        nbrOnes=0;
        isOne = false;
    }else{
        isOne=true;
        nbrOnes++;
    }
}
if(l[n-1]==0)
    ans=ans==0?0:(ans-1);
else
    ans+=nbrOnes;
print(ans)

;(function () {
	print(function (n, s) {
		var t = 0, q = false;

		for (var i = 0; i < n; i++ ) {
			if (s[i] === '1') {
				t++;
				q = true;
			} else if (q) {
				t++;
				q = false;
			}
		}

		if (!q && t > 0) t--;

		return t;
	}(+readline(), readline().split(' ')));
}.call(this));

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = true;

	this.dp = function( i , fl ) {
		if( i >= this.n ) {
			return 0 ;
		}
		var ret , res , re , r1 , a ;
		ret = this.memo[ i ][ fl ] ;
		re = this.done[ i ][ fl ] ;
		if( re == this.cc ) {
			return ret ;
		}
		this.done[ i ][ fl ] = this.cc ;
		res = ( 1 << 29 ) ;
		if( fl == 0 ) {
			if( this.arr[ i ] == 0 ) {
				r1 = this.dp( i + 1 , 0 ) ;
				res = Math.min( res , r1 ) ;
			}
			else {
				r1 = this.dp( i + 1 , 1 ) + 1 ;
				res = Math.min( res , r1 ) ;
				a = 2 ;
				if( this .brr[ i + 1 ] == 0 ) {
					a = 1 ;
				}
				r1 = this.dp( i + 1 , 0 ) + a ;
				res = Math.min( res , r1 ) ;
			}
		}
		else {
			if( this.arr[ i ] == 0 ) {
				a = 2 ;
				if( this .brr[ i + 1 ] == 0 ) {
					a = 1 ;
				}
				r1 = this.dp( i + 1 , 0 ) + a ;
				res = Math.min( res , r1 ) ;
			}
			else {
				r1 = this.dp( i + 1 , 1 ) + 1 ;
				res = Math.min( res , r1 ) ;
				a = 2 ;
				if( this .brr[ i + 1 ] == 0 ) {
					a = 1 ;
				}
				r1 = this.dp( i + 1 , 0 ) + a ;
				res = Math.min( res , r1 ) ;
			}
		}
		return this.memo[ i ][ fl ] = res ;
	};

    this.solveCase = function() {
        var res , i , j , fl , cn , temp ;
        for( i = this.n - 1 ; i >= 0 ; i-- ) {
        	if( i == this.n - 1 ) {
        		this.brr[ i ] = this.arr[ i ] ;
        	}
        	else {
        		this.brr[ i ] = this.brr[ i + 1 ] + this.arr[ i ] ;
        	}
        }
        res = this.dp( 0 , 0 ) ;
        print( res );
    };

    this.init = function() {
        this.lim1 = 1010;
        this.lim2 = 3;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
    	var i ;
    	for( i = 0 ; i < this.lim1 ; i++ ) {
    		this.brr[ i ] = 0 ;
    	}
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    };

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        return this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {
                    environmentType = 'local-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

var n = Number(readline()),
    letters = readline().split(' ');

// var n = Number("5"),
//     letters = "0 0".split(' ');

function solver() {
    var operationsCount = 0,
        inTheList = true,
        inALetter = false,
        isNextUnread = false,
        readSoFar = 0,
        totalLetters = letters.reduce(function (a, b) {
            return Number(a) + Number(b);
        });

    for (var i = 0; i < letters.length; i++) {
        if (letters[i] === "1") {
            readSoFar++;
            if (inTheList || (isNextUnread && inALetter)) {
                operationsCount++;
            }

            inALetter = true;
            inTheList = false;

            if (i + 1 < letters.length) {
                if (letters[i + 1] == "1") {
                    isNextUnread = true;
                } else {
                    isNextUnread = false;
                    inTheList = true;

                    if (readSoFar < totalLetters) {
                        operationsCount++;
                    }
                    inALetter = false;
                }
            }
        }
    }

    return operationsCount;
}

print(solver());
// console.log(solver());

n = readline();
list = readline().split(' ').map(Number);
num = 0;
i = list.indexOf(1);
if (i != -1) {
while (i < list.length){
	num++;
	list[i]=2;
	if (list[i+1] == 1){
		i++;
	}
	else {
		if (list.indexOf(1) == -1){
			i = list.length;
		}
		else {
			i = list.indexOf(1);
			num++;
		}
	}
	}
}
print(num);

var n = parseInt(readline()),
			arr = readline().replace(/\s{1,}/gi, ' ').split(/\s/),
			click = 0, goList = false;

		for(var i = 0; i < n; i++)	{
			if(arr[i] == 1)	{
				click++;
				goList = false;

				if(arr[i + 1] == 0)	{
					click++;
					goList = true;
				}
			}
		}

		if(goList)	click--;

		//console.log(bits, count);

		print(click);

readline(); // not needed

print(readline().split(' ').map(function (x) {
    return parseInt(x);
}).reduce(function (p, x) {
    if (x || p[1]) {
        p[0]++;
    }
    p[1] = x;
    return p;
}, [0, 0]).reduce(function (s, r) {
    if (s && !r) {
        s--;
    }
    return s;
}));


Numbers $$$1, 2, 3, \dots n$$$ (each integer from $$$1$$$ to $$$n$$$ once) are written on a board. In one operation you can erase any two numbers $$$a$$$ and $$$b$$$ from the board and write one integer $$$\frac{a + b}{2}$$$ rounded up instead.You should perform the given operation $$$n - 1$$$ times and make the resulting number that will be left on the board as small as possible. For example, if $$$n = 4$$$, the following course of action is optimal:  choose $$$a = 4$$$ and $$$b = 2$$$, so the new number is $$$3$$$, and the whiteboard contains $$$[1, 3, 3]$$$;  choose $$$a = 3$$$ and $$$b = 3$$$, so the new number is $$$3$$$, and the whiteboard contains $$$[1, 3]$$$;  choose $$$a = 1$$$ and $$$b = 3$$$, so the new number is $$$2$$$, and the whiteboard contains $$$[2]$$$. It's easy to see that after $$$n - 1$$$ operations, there will be left only one number. Your goal is to minimize it.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The only line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of integers written on the board initially. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, in the first line, print the minimum possible number left on the board after $$$n - 1$$$ operations. Each of the next $$$n - 1$$$ lines should contain two integers — numbers $$$a$$$ and $$$b$$$ chosen and erased in each operation.

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 num = +readLine();
    const arr = [];
    for (let i = 1; i <= num; i++) arr.push(i);

    console.log(2);
    for (let i = 0; i < num - 1; i++) {
      const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];
      console.log(`${a} ${b}`);
      arr.pop();
      arr.pop();
      const avg = Math.ceil((a + b) / 2);
      arr.push(avg);
    }
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = $()
  while (t--) {
    let n = $(), c = n;
    out.push(2)
    ForR(n - 1, 1, i => {
      out.push(`${c} ${i}`)
      c = Math.round((c + i) / 2);
    })
  }
  log(out.join('\n'))
}

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

    C();
});

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 n = pi(readline());
        let a = 0;
        let b = 0;
        let c = 0;
        let isFound = false;
        for(let i = 0; i <= Math.floor(n/3); i++){
            if(isFound)
                break;
            if(3*i > n)
                break;
            else if(3*i === n){
                a = i;
                isFound = true;
                break;
            }
            for(let j = 0; j <= Math.floor(n/5); j++){
                if(isFound)
                    break;
                if(3*i + 5*j > n)
                    break;
                else if(3*i + 5*j === n){
                    a = i; b = j;
                    isFound = true;
                    break;
                }
                for(let k = 0; k <= Math.floor(n/7); k++){
                    if(3*i + 5*j + 7*k === n){
                        a = i; b = j; c = k;
                        isFound = true;
                        break;
                    }else if(3*i + 5*j + 7*k > n){
                        break;
                    }
                }
            }
        }

        if(isFound)
            console.log(a,b,c)
        else
            console.log(-1);
    }
}

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

        let d = 0;
        for(let i = 0; i < k; i++){
            if(i < n){
                d += a[i];
            }else{
                break;
            }
        }

        if(k < n)
            console.log(d+a[k]);
        else
            console.log(d);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let ans = [];
        let curr = n-1;
        let last = n;
        let i = 0;
        while(i < n-1 && curr > 0){
            ans.push([curr, last]);
            last = Math.ceil((last+curr)/2);
            curr = curr-1;
            i++;
        }
        console.log(last);
        for(let item of ans){
            console.log(item[0], item[1]);
        }
    }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var n = parseInt(readline());
  if(n===2)
  {
      print("2");
  print(n , " ", n -1);
  continue;
  }
  print("2");
  print(n , " ", n -2);
  print(n-1 , " ", n -1);
  for (var j = n-1; j >= 3; j--) {
    print(j , " " , j - 2);
  }
}

function solv() {
    var x = parseInt(readline())
    var res = [];
    var cur = x;
    var pv = x - 1;
    for (var n = 0; n < x - 1; n++) {
        res.push([cur, pv]);
        cur = Math.ceil((cur + pv) / 2);
        pv--;
    }
    print(cur);
    for (n in res) {
        print(res[n][0], res[n][1])
    }
}

var tc = parseInt(readline())
while (tc--) solv()

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 num = +readLine();
    const arr = [];
    for (let i = 1; i <= num; i++) arr.push(i);

    console.log(num - 1);
    for (let i = 0; i < num - 1; i++) {
      const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];
      console.log(`${a} ${b}`);
      arr.pop();
      arr.pop();
      const avg = Math.ceil((a + b) / 2);
      arr.push(avg);
    }
  }
}

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 num = +readLine();
    let [same, n, first] = [false, num, true];

    for (let i = 0; i < num - 1; i++) {
      if (same) {
        console.log(`${n} ${n}`);
      } else {
        if (first) {
          let other = n - 2;
          if (other <= 0) other = n - 1;
          console.log(`${n} ${other}`);
          n = Math.floor((n + other) / 2);
          first = false;
        } else {
          let other = n - 3;
          if (n - 3 <= 0) other = n - 2;

          console.log(`${n} ${other}`);
          n = Math.floor((n + other) / 2);
        }
      }
      same = !same;
    }
  }
}

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 num = +readLine();
    const arr = [];
    for (let i = 1; i <= num; i++) arr.push(i);

    for (let i = 0; i < num - 1; i++) {
      const [a, b] = [arr[arr.length - 1], arr[arr.length - 2]];
      console.log(`${a} ${b}`);
      arr.pop();
      arr.pop();
      const avg = Math.ceil((a + b) / 2);
      arr.push(avg);
    }
  }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var n = parseInt(readline());
  print("2");
  print(n + " " + n - 1);
  for (var j = n; j >= 3; j--) {
    print(j + " " + j - 2);
  }
}

function solve(nu) {
  print("2");
  print(nu + " " + nu - 1);
  for (var j = nu; j >= 3; j--) {
    print(j + " " + j - 2);
  }
}