We have a point $$$A$$$ with coordinate $$$x = n$$$ on $$$OX$$$-axis. We'd like to find an integer point $$$B$$$ (also on $$$OX$$$-axis), such that the absolute difference between the distance from $$$O$$$ to $$$B$$$ and the distance from $$$A$$$ to $$$B$$$ is equal to $$$k$$$.  The description of the first test case. Since sometimes it's impossible to find such point $$$B$$$, we can, in one step, increase or decrease the coordinate of $$$A$$$ by $$$1$$$. What is the minimum number of steps we should do to make such point $$$B$$$ exist?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 6000$$$) — the number of test cases. The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$0 \le n, k \le 10^6$$$) — the initial position of point $$$A$$$ and desirable absolute difference.

For each test case, print the minimum number of steps to make point $$$B$$$ exist.

NoteIn the first test case (picture above), if we set the coordinate of $$$B$$$ as $$$2$$$ then the absolute difference will be equal to $$$|(2 - 0) - (4 - 2)| = 0$$$ and we don't have to move $$$A$$$. So the answer is $$$0$$$.In the second test case, we can increase the coordinate of $$$A$$$ by $$$3$$$ and set the coordinate of $$$B$$$ as $$$0$$$ or $$$8$$$. The absolute difference will be equal to $$$|8 - 0| = 8$$$, so the answer is $$$3$$$.

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

rl.question("", function (n) {
  functions();
})
function functions() {
  rl.question('', function (n) {
    var input = n.split(' ')
    var a = parseInt(input[0]);
    var k = parseInt(input[1]);
    var o = 0;
    var output;
    if (k >= a) {
      output = k - a;
    } else {
      if ((a % 2 == 0 && k % 2 == 0) || (a % 2 != 0 && k % 2 != 0)) {
        output = 0
      } else {
        output = 1
      }
    }
    console.log(output)
    functions()
  })
}

// function functions() {
//   rl.question('', function (input) {
//     var n = input.split(' ');
//     var x = parseInt(n[0]);
//     var y = parseInt(n[1]);
//     var z = parseInt(n[2]);
//     var a, b, c, bool = false;
//     if (x == y && y >= z) {
//       bool = true;
//       a = x;
//       b = z;
//       c = 1;
//     } else if (x == z && z >= y) {
//       bool = true;
//       b = x;
//       a = y;
//       c = 1;
//     } else if (y == z && z >= x) {
//       bool = true;
//       c = y;
//       b = x;
//       a = 1;
//     } else if (x == y && y == z) {
//       bool = true;
//       a = b = c = x;
//     }
//     if (bool) {
//       console.log('yes')
//       console.log(a, b, c)
//     } else {
//       console.log('no')
//     }
//     // console.log(x == y, x > z, z, y > 2)
//     functions();
//   })
// }
// function functions() {
//   rl.question("", function (n) {
//     rl.question("", function (num) {
//       var arr = num.split(' ');
//       var l = [];
//       for (var i = 0; i < n * 2; i++) {
//         for (var j = 0; j < arr.length; j++) {
//           var lhas = l.includes(arr[j])
//           if (!lhas) {
//             l.push(arr[j]);
//
//           }
//         }
//       }
//       console.log(l.join(' '));
//       functions();
//     });
//   })
// }
// rl.question('', function (o) {
//   rl.question('', function (n) {
//     rl.question('', function (a) {
//       rl.question('', function (b) {
//         var s = 0;
//         var sa = a.split(' ');
//         var sb = b.split(' ');
//         // console.log(n, newA, s, sa, sb)
//         for (var i = 0; i < n; i++) {
//           var newA = [];
//           var ai = sa[i] - Math.min.apply(Math, sa)
//           var bi = sb[i] - Math.min.apply(Math, sb)
//           newA.push(ai);
//           newA.push(bi);
//           s += Math.max.apply(Math, newA);
//         }
//         console.log(s)
//         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));

    if (a <= b) {
      console.log(b - a);
    } else if (a % 2 != b % 2) {
      console.log(1);
    } else {
      console.log(0);
    }
  }
}

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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const [n, k] = readLine().split(/\s/).map(Number)
    console.log(n < k ? k - n : (n - k) % 2)
  }
}

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] = 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])) {
      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);
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;
  let t = $()
  while (t--) {
    let [n, k] = $(2)
    if (n <= k) log(k - n);
    else if (n % 2 == k % 2) log(0);
    else log(1);
  }
}

let _input = '';
let lineNumberToRead = -1;
let outputArray = [];
function readLine() {
  lineNumberToRead += 1;
  return _input[lineNumberToRead];
}

const l = readLine;

function flush() {
  console.log(outputArray.join(''));
  outputArray = [];
}

function out(s) {
  outputArray.push(s);
}
function ria() {
  return l().split(' ').map((x) => +x);
}
function processInput() {
  const t = +l();

  for (let i = 1; i <= t; i += 1) {
    solveTestCase(i);
  }

  flush();
}

function solveTestCase(testCaseNumber) {
  const [n, k] = ria();

  if(n < k) {
    out(k - n + "\n");
  } else  {
    out(((n%2 == k%2) ? 0 : 1) + "\n");
  }
}

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

process.stdin.on('data', (data) => { _input += data; });
process.stdin.on('end', () => {
  _input = _input.trim().split('\n').map((x) => x.trim());
  processInput();
});

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

    probA();
});

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

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if(n < k)
            console.log(k-n);
        else{
            if((n+k) % 2 === 0){
                console.log(0);
            }else{
                console.log(1);
            }
        }
    }
}

function probB(){
    let t = pi(readline());

    while(t > 0){
        t--;
        let a = readline().split(' ');
        let b = readline().split(' ');

        a[0] = pi(a[0]);
        a[1] = pi(a[1]);
        a[2] = pi(a[2]);

        b[0] = pi(b[0]);
        b[1] = pi(b[1]);
        b[2] = pi(b[2]);

        let maxSum = 0;
        if(b[2] - (a[0] + a[2]) > 0){
            b[2] = b[2] - (a[0]+a[2]);
            a[0] = 0;
            a[2] = 0;
        }else if(b[2] - a[0] > 0){
            a[2] = a[2] - (b[2] - a[0]);
            b[2] = 0;
            a[0] = 0;
        }else{
            a[0] -= b[2];
            b[2] = 0;
        }

        if(a[2] > b[1])
            console.log((b[1] - b[2]) * 2)
        else
            console.log((a[2]-b[2]) * 2);

    }
}

function probC(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = readline().split(' ');
        let x = JSON.parse(JSON.stringify(a));

        x.sort((a,b) => pi(a) - pi(b));
        let res = true;
        for(let i = 0; i < n; i++){
            if(x[i] !== a[i]){
                if(pi(a[i]) % pi(x[0]) !== 0){
                    res = false;
                    break;
                }
            }
        }

        if(res)
            console.log('yes');
        else
            console.log('no');
    }
}

var t = +(readline());
while (t--) {
  var inputs = readline().split(' ');
  var n = +inputs[0], k = +inputs[1];
  if (n < k) {
    print(k-n);
  } else if (n%2==k%2) print(0);
  else print(1);
}

var t = parseInt(readline());

while(t--){
    a = readline().split(' ');
    n = parseInt(a[0]);
    k = parseInt(a[1]);

    if (n < k)
        print(k - n);
    else if (n % 2 == k % 2)
        print(0);
    else
        print(1);
}

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

rl.question("", function (n) {
  functions();
})
function functions() {
  rl.question('', function (n) {
    var input = n.split(' ')
    var a = input[0];
    var k = input[1];
    var o = 0;
    var output;
    if (k >= a) {
      output = k - a;
    } else {
      if ((a % 2 == 0 && k % 2 == 0) || (a % 2 != 0 && k % 2 != 0)) {
        output = 0
      } else {
        output = 1
      }
    }
    console.log(output)
    functions()
  })
}

// function functions() {
//   rl.question('', function (input) {
//     var n = input.split(' ');
//     var x = parseInt(n[0]);
//     var y = parseInt(n[1]);
//     var z = parseInt(n[2]);
//     var a, b, c, bool = false;
//     if (x == y && y >= z) {
//       bool = true;
//       a = x;
//       b = z;
//       c = 1;
//     } else if (x == z && z >= y) {
//       bool = true;
//       b = x;
//       a = y;
//       c = 1;
//     } else if (y == z && z >= x) {
//       bool = true;
//       c = y;
//       b = x;
//       a = 1;
//     } else if (x == y && y == z) {
//       bool = true;
//       a = b = c = x;
//     }
//     if (bool) {
//       console.log('yes')
//       console.log(a, b, c)
//     } else {
//       console.log('no')
//     }
//     // console.log(x == y, x > z, z, y > 2)
//     functions();
//   })
// }
// function functions() {
//   rl.question("", function (n) {
//     rl.question("", function (num) {
//       var arr = num.split(' ');
//       var l = [];
//       for (var i = 0; i < n * 2; i++) {
//         for (var j = 0; j < arr.length; j++) {
//           var lhas = l.includes(arr[j])
//           if (!lhas) {
//             l.push(arr[j]);
//
//           }
//         }
//       }
//       console.log(l.join(' '));
//       functions();
//     });
//   })
// }
// rl.question('', function (o) {
//   rl.question('', function (n) {
//     rl.question('', function (a) {
//       rl.question('', function (b) {
//         var s = 0;
//         var sa = a.split(' ');
//         var sb = b.split(' ');
//         // console.log(n, newA, s, sa, sb)
//         for (var i = 0; i < n; i++) {
//           var newA = [];
//           var ai = sa[i] - Math.min.apply(Math, sa)
//           var bi = sb[i] - Math.min.apply(Math, sb)
//           newA.push(ai);
//           newA.push(bi);
//           s += Math.max.apply(Math, newA);
//         }
//         console.log(s)
//         functions();
//       })
//     })
//   })
// })

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] = 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])) {
      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);
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;
  let t = $()
  while (t--) {
    let [n, k] = $(2)
    if (n <= k) log(k - n);
    else if (n % 2 == k % 2) log(0);
    else log(1);
  }
}

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

let inputString = '';
let currentLine = 0;

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

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

    probA();
});

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

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if((n+k) % 2 === 0){
            if(n === 0)
                console.log(k);
            else
                console.log(0);
        }
        else
            console.log(Math.abs(n-k));
    }
}

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

    probA();
});

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

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if(n < k)
            console.log(k-n);
        else{
            if((n+k) % 2 === 0){
                console.log(0);
            }else{
                console.log(n-k);
            }
        }
    }
}

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

    probA();
});

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

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if((n+k) % 2 === 0 && n > k){
            console.log(0);
        }else{
            console.log(Math.abs(n-k));
        }
    }
}


Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:  Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$;  Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$;  Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$;  Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$;  Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$;  Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$;  $$$\dots$$$  Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$;  Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.

The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.

Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array.

NoteThe first example is described in the problem statement.

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const array = is.nextArray();
  for (let i = 0; i < n; i += 1) {
    array[i] = parseInt(array[i], 10);
  }

  let tmp;
  for (let i = 0; i < n; i += 1) {
    tmp = array[i];
    for (let j = 0; j < n; j += 1) {
      if (array[j] === tmp && array[j] % 2 === 0) {
        array[j] = tmp - 1;
      }
    }
  }

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

/*
 *  Api Scanner
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    return this.lines[this.index++]; // eslint-disable-line
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

var readline = (()=>{
    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++];
    }
    return readline;
})()

function main() {
	readline();
	console.log(((str)=>
		str.split(" ").map(item=>item%2===0?item-1:item).join(" ")
	)(readline()));
}

var readline = (()=>{
    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++];
    }
    return readline;
})()

function main() {
	readline();
	console.log(((str)=>{
		let arr=str.split(" ");
		arr = arr.reduce((acc,c,i)=>{
			let n = c%2==0?c-1:c;
			if(acc[n]==null){
				acc[n] = [];
			};
			acc[n].push(i);
			return acc;
		}, {});
		return Object.keys(arr).reduce((acc,e,i)=>{
			let c = arr[e];
			c.map(t=>acc[t]=e);
			return acc;
		},[]).join(" ")
	})(readline()));
}

//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');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
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 N = nextInt();
  var list = nextIntArray();
  for(var i = 0; i < N; i++){
    list[i] -= (list[i] % 2 == 0) ? 1 : 0;
  }
  myout(myconv(list, 8));
}

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  const a = d.split(' ').map(Number);

  for (let i = 0; i < a.length; i++) {
    if (a[i] % 2 === 0) {
      a[i] = a[i] - 1;
    }
  }

  console.log(a.join(' '));

  c++;
});

let input = [];

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

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

RL.on('close', () => {
    let n = parseInt(input[0]);
    let num = [];
    input[1].split(' ').forEach(i => num.push(parseInt(i)));

    for(let i = 0; i < n; i++){
        for(let j = i; j < n; j++){
            if(num[i] === num[j] && num[j] % 2 === 0)
                num[j]--;
        }
    }

    let answer = ''; num.forEach( i => answer+= `${i} `)
    console.log(answer);
});

n=readline()
print(readline().split(' ').map(function(x){return x-(+x+1)%2}).join(' '))

var n = (+ readline ());
var a = readline ();
a = a.trim ().split ( ' ' );
var i;
for ( i = 0; i < n; i ++ ) a [ i ] = Number ( a [ i ] );
for ( i = 0; i < n; i ++ ) {
    if ( a [ i ] % 2 == 0 ) a [ i ] --;
}
print ( a.join ( ' ' ) );

var elements = readline();
elements = readline().split(' ').map(e => e % 2 === 0 ? e - 1 : e).join(' ');
print(elements);

//var h = readline()
var n = parseInt(readline())
var nums = (readline().split(' '))
var i = 0
while (n--) {
    var a = nums[i] - 1
    var b = parseInt((a / 2), 10)
    var c = b * 2
    var res = c + 1
    write(res, ' ')
    i++
}

var n = parseInt(readline())
var nums = (readline().split(' '))
var i = 0
while (n--) {
    var a = nums[i] - 1
    var b = parseInt((a / 2), 10)
    var c = b * 2
    var res = c + 1
    print(res)
    i++
}

// var print = require('lol-io').print
// var readline = require('lol-io').readline

readline();

var arr = readline().split(' ');

var answer = '';

arr.forEach(nr => {
    if(!(nr % 2)) {
        answer += nr - 1;
    } else {
        answer += nr;
    }
    answer += ' ';
});

print(answer);

var n = readline();
var a = readline().split(' ').map(function(el) {
    return parseInt(el, 10);
});

for (var i of a) {
    if (i % 2 == 0) {
        write(i - 1,' ');
    }
    else {
        write(i, ' ')
    }
}

var readline = (()=>{
    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++];
    }
    return readline;
})()

function main() {
	readline();
	console.log(((str)=>{
		let arr=str.split(" ");
		arr = arr.reduce((acc,c,i)=>{
			let n = c%2===0?c-1:c;
			if(acc[n]==null){
				acc[n] = [];
			}
			acc[n].push(i);
			return acc;
		}, {});
		return Object.keys(arr).reduce((acc,e,i)=>{
			let c = arr[e];
			console.log(e);
			c.map(t=>acc[t]=e);
			return acc;
		},[]).join(" ")
	})(readline()));
}


Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is $$$n$$$. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains $$$2$$$ apartments, every other floor contains $$$x$$$ apartments each. Apartments are numbered starting from one, from the first floor. I.e. apartments on the first floor have numbers $$$1$$$ and $$$2$$$, apartments on the second floor have numbers from $$$3$$$ to $$$(x + 2)$$$, apartments on the third floor have numbers from $$$(x + 3)$$$ to $$$(2 \cdot x + 2)$$$, and so on.Your task is to find the number of floor on which Petya lives. Assume that the house is always high enough to fit at least $$$n$$$ apartments.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n, x \le 1000$$$) — the number of Petya's apartment and the number of apartments on each floor of the house except the first one (there are two apartments on the first floor).

For each test case, print the answer: the number of floor on which Petya lives.

NoteConsider the first test case of the example: the first floor contains apartments with numbers $$$1$$$ and $$$2$$$, the second one contains apartments with numbers $$$3$$$, $$$4$$$ and $$$5$$$, the third one contains apartments with numbers $$$6$$$, $$$7$$$ and $$$8$$$. Therefore, Petya lives on the third floor.In the second test case of the example, Petya lives in the apartment $$$1$$$ which is on the first floor.

// let input = `4
// 7 3
// 1 5
// 22 5
// 987 13`

let input = ''

// process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	// f = 0
	// const { EOL } = require('os')
	// const lines = input.split(EOL) /*your input text, split by lines*/
	// main(input, lines)
})

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

let f = 0
// multi line input
readline.on('line', l => {
	if (!f) {
		f = 1
		return
	}
	[n, x] = l.split(' ').map(x => +x)
	// console.log(Math.ceil((n - 3) / x) + 2)
	// console.log(n, x)
	// return
	if (n <= 2) {
		console.log(1)
	}
	else {
		console.log(Math.floor((n - 3) / x + 2))
	}
	// console.log(line);
});

// function main() {
// 	input.split('\n').slice(1).map(l => {
// 		[n, x] = l.split(' ').map(x => +x)
// 		console.log(Math.ceil((n + 2) / x))
// 	})
// }

// process.on('SIGINT', function () {
// 	main()
// 	process.exit(0);
// });

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

// https://codeforces.com/problemset/problem/1426/A
const readline = require('readline');

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

let data = [];
rl.on('line', (input) => {
  data.push(input);
});

rl.on('close', () => {
  solve(data);
});

function solve(data) {

  for (let i = 1; i < data.length; i++) {
    [n, x] = data[i].split(" ");

    if (n <= 2) {

      // first floor
      console.log(1);

    } else {

      floor = 0;
      while (true) {
        lower = floor*x+3;
        upper = (floor+1)*x+2;
        if (n >= lower && n <= upper) {
          console.log(floor + 2);
          break;
        }
        floor++;
      }

    }
  }

}

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() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);
        let b = parseInt(line[1]);
        let res = parseInt(line[1]);
        if (a == 1 || a== 2)
        {
            console.log(1);
        }
        else{
            a -= 2;
            res = a/b;
            res = Math.floor(res)
            if(a%b===0)
            {
                console.log(res+1);
            }
            else
            {
                console.log(res+2);
            }
        }
    }
}

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() {
  var T = readLine();
  var loop = 1010;
  while (T--) {
    var arr = readLine();
    arr = arr.split(" ").map(Number);
    var n = arr[0];
    var x = arr[1];
    var result = 0;
    for (let i = 1; i < loop; i++) {
      if (n <= 2) {
        result = 1;
        break;
      }
      result = Math.floor((n - 3) / x + 2);
    }
    console.log(result);
  }
}

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

let data = [];

rl.on("line", (line) => {
    data.push(line);
});

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

function floor(data) {
    for (let i = 1; i < data.length; i++) {
        [n, x] = data[i].split(" ").map(Number);

        let currentFloor = 1;

        if (n > 2) {
            currentFloor = Math.ceil((n - 2) / x) + 1;
        }

        console.log(currentFloor);
    }
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;

	//let [a,b] = inputReader.readNumberArray();
	let noOfTestCases = inputReader.readNumber();

	//console.log(noOfTestCases,typeof noOfTestCases);
	while(noOfTestCases--){
	    let [a,b] = inputReader.readNumberArray();
	    let count = 1;
	    if(a<=2){
	        console.log(1);
	        continue;
	    }
	    let floor;
	    if((a-2)%b===0)
	        floor = (a-2)/b +1;
	    else
	         floor = Math.ceil((a-2)/b)+1;
	    console.log(floor);

	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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--) {
    let [target, flats] = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    if (target <= 2) console.log(1);
    else if (target >= 3 && target <= flats) console.log(2);
    else {
      target = target - (2 + flats);
      let result = Math.floor(target / flats);
      if (target % flats !== 0) result += 1;
      console.log(result + 2);
    }
  }
}

//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 one = nextIntArray();
    var N = one[0];
    var X = one[1];
    if(N < 3){
      output[i] = 1;
    }else{
      var count = 0;
      while(true){
        if(3 + count * X <= N && N <= (count + 1) * X + 2){
          output[i] = count + 2;
          break;
        }
        count++;
      }
    }
  }
  myout(myconv(output, 9));
}

const readline = require('readline');

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

function print(thing) {
    console.log(thing);
}
const getLine = (function() {
    const getLineGen = (async function*() {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async() => ((await getLineGen.next()).value);
})();

const main = async() => {
    let t = Number(await getLine());
    for (test = 0; test < t; test++) {
        let raw = (await getLine()).split(" ");
        n = Number(raw[0]);
        x = Number(raw[1]);
        if (n <= 2) {
            print(1);
        } else {
            print((Math.floor((n - 3) / x)) + 2);
        }
    }
    process.exit(0);
};

main();

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, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = 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;
  }
}

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];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
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 = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $(), x = $()
    log(max(0, Math.ceil((n - 2) / x)) + 1);
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function solution(n, x){
    return n === 1 ? 1 : Math.floor((n - 3) / x) + 2;
}

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

    for(let i = 0; i < N; i++){
        const line = readline().split(' ').map(item => parseInt(item));
        console.log(solution(line[0], line[1]));
    }
}

function main(){
    var ncases = +readline();
    for(var i = 0; i < ncases; ++i){
        var input = readline().split(' ');
        var res = Math.ceil((+input[0] - 2) / +input[1]) +1;
        print(res || 1);
    }
}

main();

var t = Number(readline());
while(t--){
    var ln = readline().split(" ");
    var n = Number(ln[0]),x = Number(ln[1]);
    if(n<=2)print(1);
    else print(parseInt((n-2)/x)+((n-2)%x>0)+1);
}

var ಠ_ಠ = Number(readline());
while(ಠ_ಠ--){
    var ln = readline().split(" ");
    var n = Number(ln[0]),x = Number(ln[1]);
    if(n<=2)print(1);
    else print(parseInt((n-2)/x)+((n-2)%x>0)+1);
}

var t = Number( readline() );
for(var i=0; i<t; i++){
 var r = readline().split(' ').map(a=>Number(a));
 print((r[0]<3)?1:Math.floor((r[0]-3)/r[1]+2));
}

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var params = readline();
  var n = parseInt(params.split(" ")[0]);
  var apts = parseInt(params.split(" ")[1]);
  var floor = 1;
  if (n > 2) {
    floor = Math.ceil(parseFloat(n - 2) / apts) + 1;
  }

  print(floor);
}

function int(v) {
        return parseInt(v)
}

var t = int(readline())

while(t--) {
        var a = readline().split(' ').map(int)

        var n = a[0], x = a[1]

        if(n == 1 || n == 2) {
                print(1)
        }else {
                n -= 2;
                print(1 + Math.ceil(n / x))
        }

}

var rr=readline()

//var i=0;
for(var j=0;j<rr;j++){
    var inp = readline().split(' ');

var NewFloor=0;
 NewFloor=2;

var petyaApartment=parseInt(inp[0]);
var FloorPetya=0

var otherFloor=parseInt(inp[1]);

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

if((NewFloor==petyaApartment||NewFloor>petyaApartment)&&i===0){
FloorPetya=i+1
print(FloorPetya)

break;

}
if(i!==0){
NewFloor+=otherFloor

}
if(NewFloor==petyaApartment||NewFloor>petyaApartment){

FloorPetya=i+1
print(FloorPetya)

break;

}

}
}
//print(FloorPetya)

var tc = parseInt(readline());

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

    if(n < 3){
        print(1);
    }else{
        print(Math.ceil((n+(x-2))/x));
    }
}

var tc = parseInt(readline());

while (tc--) {
	var numbers = readline().split(' '),
		n = parseInt(numbers[0]),
		x = parseInt(numbers[1]);

	var ans = 1;
	n -= 2;
	while (n > 0) {
		n -= x;
		ans++;
	}

	print(ans);
}

var testcases = readline();

for(var i = 0 ; i < testcases ; i++) {
    var details = readline().split(' ').map(Number)
    var apartmentNumber = details[0];
    var x = details[1];
    var y = Math.ceil(apartmentNumber/x) + 1
    var temp = 2;
    var floor = 1;
    while(y--){
        if(temp >= apartmentNumber){
            print(floor);
            break;
        }
        else{
            temp = temp + x;
            floor++;
        }
    }
}

var t = +readline();
var inp;

for(var i = 0; i < t; i++) {
   inp = readline().split(" ").map(Number);

  if (inp[0] <= 2) {
    print(1);
  } else {
    print(Math.ceil((inp[0] - 2) / inp[1]) + 1);
  }
}

// let input = `4
// 7 3
// 1 5
// 22 5
// 987 13`

let input = ''

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

const readline = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
let f = 0
// multi line input
readline.on('line', l => {
	if (!f) {
		f = 1
		return
	}
	[n, x] = l.split(' ').map(x => +x)
	console.log(Math.ceil((n + 2) / x))
	// console.log(line);
});

function main() {
	input.split('\n').slice(1).map(l => {
		[n, x] = l.split(' ').map(x => +x)
		console.log(Math.ceil((n + 2) / x))
	})
}

// process.on('SIGINT', function () {
// 	main()
// 	process.exit(0);
// });

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

// let input = `4
// 7 3
// 1 5
// 22 5
// 987 13`

let input = ''

// process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	f = 0
	// const { EOL } = require('os')
	// const lines = input.split(EOL) /*your input text, split by lines*/
	// main(input, lines)
})

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

let f = 0
// multi line input
readline.on('line', l => {
	if (!f) {
		f = 1
		return
	}
	[n, x] = l.split(' ').map(x => +x)
	// console.log(Math.ceil((n - 3) / x) + 2)
	if (n <= 2) {
		console.log(1)
	}
	else {
		console.log(Math.ceil((n + 2) / x))
	}
	// console.log(line);
});

// function main() {
// 	input.split('\n').slice(1).map(l => {
// 		[n, x] = l.split(' ').map(x => +x)
// 		console.log(Math.ceil((n + 2) / x))
// 	})
// }

// process.on('SIGINT', function () {
// 	main()
// 	process.exit(0);
// });

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

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

function main(input) {
	input.split('\n').slice(1).map(l => {
		[n, x] = l.split(' ').map(x => +x)
		console.log(Math.ceil((n + 2) / x))
	})
}

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

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() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);
        let b = parseInt(line[1]);
        if (a == 1 || a == 2)
        {
            console.log(1);
        }
        else{
            a /= b;
            if(a%b===0)
            {
                console.log(Math.ceil(a));
            }
            else
            {
                console.log(Math.ceil(a+1));
            }
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);
        let b = parseInt(line[1]);
        if (a == 1 || a == 2)
        {
            console.log(1);
        }
        else{
            a /= b;
            if(a%b===0)
            {
                console.log(a);
            }
            else
            {
                console.log(a+1);
            }
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);
        let b = parseInt(line[1]);
        if (a == 1 || a == 2)
        {
            console.log(1);
        }
        else{
            a -= 2;
            a /= b;
            if(a%b===0)
            {
                console.log(Math.round(a));
            }
            else
            {
                console.log(Math.round(a+1));
            }
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);

        let b = parseInt(line[1]);
        if (a < 3)
        {
            console.log(1);
        }
        else{
            a -= 2;
            a /= b;
            if(a%b===0)
            {
                console.log(Math.round(a+1));
            }
            else
            {
                console.log(Math.round(a+2));
            }
        }
    }
}

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() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);
        let b = parseInt(line[1]);
        if (a == 1 || a == 2)
        {
            console.log(1);
        }
        else{
            a /= b;
            if(a%b===0)
            {
                console.log(Math.round(a));
            }
            else
            {
                console.log(Math.round(a+1));
            }
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readLine();
    t = parseInt(t);

    while(t--) {
        let line = readLine();
        line = line.split(" ");
        let a = parseInt(line[0]);

        let b = parseInt(line[1]);
        if (a == 1 || a== 2)
        {
            console.log(1);
        }
        else{
            a -= 2;
            a /= b;
            if(a%b===0)
            {
                console.log(Math.round(a+1));
            }
            else
            {
                console.log(Math.round(a+2));
            }
        }
    }
}

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() {
  var T = readLine();
  var loop = 1010;
  while (T--) {
    var arr = readLine();
    arr = arr.split(" ").map(Number);
    var n = arr[0];
    var x = arr[1];
    var result = 0;
    for (let i = 1; i < loop; i++) {
      if (n <= 2) {
        result = 1;
      }
      result = (n - 3) / x + 2;
    }
    console.log(Math.floor(result));
  }
}

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() {
  var T = readLine();
  var loop = 1010;
  while (T--) {
    var arr = readLine();
    arr = arr.split(" ").map(Number);
    var n = arr[0];
    var x = arr[1];
    var result = 0;
    for (let i = 0; i < loop; i++) {
      if (n <= 2) {
        result = 1;
      }
      result = (n - 3) / x + 2;
    }
    console.log(Math.floor(result));
  }
}

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, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = 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;
  }
}

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];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
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 = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $(), x = $()
    log(Math.ceil((n - 2) / x) + 1);
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function solution(n, x){
    return Math.floor((n - 3) / x) + 2;
}

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

    for(let i = 0; i < N; i++){
        const line = readline().split(' ').map(item => parseInt(item));
        console.log(solution(line[0], line[1]));
    }
}

// let input = `4
// 7 3
// 1 5
// 22 5
// 987 13`

let input = ''

// process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	f = 0
	// const { EOL } = require('os')
	// const lines = input.split(EOL) /*your input text, split by lines*/
	// main(input, lines)
})

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

let f = 0
// multi line input
readline.on('line', l => {
	if (!f) {
		f = 1
		return
	}
	[n, x] = l.split(' ').map(x => +x)
	// console.log(Math.ceil((n - 3) / x) + 2)
	if (n <= 2) {
		return 1
	}
	console.log(Math.ceil((n + 2) / x))
	// console.log(line);
});

// function main() {
// 	input.split('\n').slice(1).map(l => {
// 		[n, x] = l.split(' ').map(x => +x)
// 		console.log(Math.ceil((n + 2) / x))
// 	})
// }

// process.on('SIGINT', function () {
// 	main()
// 	process.exit(0);
// });

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

// let input = `4
// 7 3
// 1 5
// 22 5
// 987 13`

let input = ''

// process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	// f = 0
	// const { EOL } = require('os')
	// const lines = input.split(EOL) /*your input text, split by lines*/
	// main(input, lines)
})

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

let f = 0
// multi line input
readline.on('line', l => {
	if (!f) {
		f = 1
		return
	}
	[n, x] = l.split(' ').map(x => +x)
	// console.log(Math.ceil((n - 3) / x) + 2)
	// console.log(n, x)
	// return
	if (n <= 2) {
		console.log(1)
	}
	else {
		console.log(Math.ceil((n - 3) / x) + 2)
	}
	// console.log(line);
});

// function main() {
// 	input.split('\n').slice(1).map(l => {
// 		[n, x] = l.split(' ').map(x => +x)
// 		console.log(Math.ceil((n + 2) / x))
// 	})
// }

// process.on('SIGINT', function () {
// 	main()
// 	process.exit(0);
// });

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

// let input = `4
// 7 3
// 1 5
// 22 5
// 987 13`

let input = ''

// process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	setTimeout(() => f = 0)
	// const { EOL } = require('os')
	// const lines = input.split(EOL) /*your input text, split by lines*/
	// main(input, lines)
})

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

let f = 0
// multi line input
readline.on('line', l => {
	if (!f) {
		f = 1
		return
	}
	[n, x] = l.split(' ').map(x => +x)
	console.log(Math.ceil((n + 2) / x))
	// console.log(line);
});

// function main() {
// 	input.split('\n').slice(1).map(l => {
// 		[n, x] = l.split(' ').map(x => +x)
// 		console.log(Math.ceil((n + 2) / x))
// 	})
// }

// process.on('SIGINT', function () {
// 	main()
// 	process.exit(0);
// });

// main(`4
// 7 3
// 1 5
// 22 5
// 987 13`)

function main(){
    var ncases = +readline();
    for(var i = 0; i < ncases; ++i){
        var input = readline().split(' ');
        print(Math.ceil((+input[0] - 2) / +input[1]) +1);
    }
}

main();

var t = Number(readline());
while(t--){

}

var t = Number(readline());
while(t--){
    var ln = readline().split(" ");
    var n = Number(ln[0]),x = Number(ln[1]);
}

var t = Number(readline());
while(t--){
    var ln = readline().split(" ");
    var n = Number(ln[0]),x = Number(ln[1]);
    if(n<=2)print(1);
    else print((n-2)/x+((n-2)%x>0)+1);
}

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var params = readline();
  var n = parseInt(params.split(" ")[0]);
  var apts = parseInt(params.split(" ")[1]);
  var floor = 1;
  if (n > 2) {
    floor = Math.ceil(parseFloat(n) / apts) + 1;
  }

  print(floor);
}

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var params = readline();
  var n = parseInt(params.split(" ")[0]);
  var apts = parseInt(params.split(" ")[1]);
  var floor = 1;
  if (n > 2) {
    floor = Math.ceil(n / apts) + 1;
  }

  print(floor);
}

var inp = readline().split(' ');
var NewFloor=2;
var petyaApartment=parseInt(inp[0]);
var FloorPetya;
const otherFloor=parseInt(inp[1]);

//var i=0;

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

if((NewFloor==petyaApartment||NewFloor>petyaApartment)&&i===0){
FloorPetya=i+1

break;

}
if(i!==0){
NewFloor+=otherFloor

}
if(NewFloor==petyaApartment||NewFloor>petyaApartment){

FloorPetya=i+1

break;

}

}
print(FloorPetya)

var t = readline();
var test = +t;

while(t++ <= 0) {
  var test = readline().split(' ').map(Number);
  if (test[0] <= 2) {
    print(1);
  } else {
    print(Math.ceil((test[0] - 2) / test[1]) + 1)
  }
}

var t = Number(readline());

print(t);
while(false) {
  var test = readline().split(' ').map(Number);

  if (test[0] <= 2) {
    print(1);
  } else {
    print(Math.ceil((test[0] - 2) / test[1]) + 1)
  }
}

var t = +readline();

while(t++ <= 0) {
  var test = readline().split(' ').map(Number);
  if (test[0] <= 2) {
    print(1);
  } else {
    print(Math.ceil((test[0] - 2) / test[1]) + 1)
  }
}

var t = Number(readline());
print(t);
while(t++ <= 0) {
  var test = readline().split(' ').map(Number);

  if (test[0] <= 2) {
    print(1);
  } else {
    print(Math.ceil((test[0] - 2) / test[1]) + 1)
  }
}


DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew $$$n$$$ distinct lines, given by equations $$$y = x + p_i$$$ for some distinct $$$p_1, p_2, \ldots, p_n$$$.Then JLS drew on the same paper sheet $$$m$$$ distinct lines given by equations $$$y = -x + q_i$$$ for some distinct $$$q_1, q_2, \ldots, q_m$$$.DLS and JLS are interested in counting how many line pairs have integer intersection points, i.e. points with both coordinates that are integers. Unfortunately, the lesson will end up soon, so DLS and JLS are asking for your help.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$), the number of test cases in the input. Then follow the test case descriptions. The first line of a test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of lines drawn by DLS. The second line of a test case contains $$$n$$$ distinct integers $$$p_i$$$ ($$$0 \le p_i \le 10^9$$$) describing the lines drawn by DLS. The integer $$$p_i$$$ describes a line given by the equation $$$y = x + p_i$$$. The third line of a test case contains an integer $$$m$$$ ($$$1 \le m \le 10^5$$$), the number of lines drawn by JLS. The fourth line of a test case contains $$$m$$$ distinct integers $$$q_i$$$ ($$$0 \le q_i \le 10^9$$$) describing the lines drawn by JLS. The integer $$$q_i$$$ describes a line given by the equation $$$y = -x + q_i$$$. The sum of the values of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$. Similarly, the sum of the values of $$$m$$$ over all test cases in the input does not exceed $$$10^5$$$. In hacks it is allowed to use only one test case in the input, so $$$t=1$$$ should be satisfied.

For each test case in the input print a single integer — the number of line pairs with integer intersection points.

NoteThe picture shows the lines from the first test case of the example. Black circles denote intersection points with integer coordinates.

var queriesCount = parseInt(readline());
// var queriesCount = 1;

for (var i = 0; i < queriesCount; i++) {
  readline();
  var DSL = readline().split(' ').map(function(num) {
    return parseInt(num);
  })
  readline();
  var JSL = readline().split(' ').map(function(num) {
    return parseInt(num);
  })

  // var DSL = [1,2,3]
  // var JSL = [0,3]

  var oddsDSL = 0;
  var evensDSL = 0;
  var oddsJSL = 0;
  var evensJSL = 0;

  for (var j = 0; j < DSL.length; j++) {
    if (DSL[j] % 2 === 0) {
      evensDSL++;
    } else {
      oddsDSL++;
    }
  }
  for (var k = 0; k < JSL.length; k++) {
    if (JSL[k] % 2 === 0) {
      evensJSL++;
    } else {
      oddsJSL++;
    }
  }

  write(((evensDSL * evensJSL) + (oddsDSL * oddsJSL)) + '\n')
}
// });

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      read();
      var cp = [0, 0];
      read().split(' ').forEach(function(sn) {
         ++cp[Number(sn) % 2];
      });
      read();
      var cq = [0, 0];
      read().split(' ').forEach(function(sn) {
         ++cq[Number(sn) % 2];
      });
      write(cp[0] * cq[0] + cp[1] * cq[1]);
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

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

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

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});

let answer = "";

let lines = [];

rl.on('line', (t)=>{
    lines.push(t);
}).on('close', ()=>{
    let t = parseInt(lines[0]);
    for(let i = 0; i < t; i++){
        let a = lines[1 + i * 4 + 1].split(" ");
        let b = lines[1 + i * 4 + 3].split(" ");

        let n1 = 0, m1 = 0, n2 = 0, m2 = 0;

        a.map((n)=>{if(n%2 == 0) n1++; else m1++;});
        b.map((n)=>{if(n%2 == 0) n2++; else m2++;});

        answer += ("" + (n1 * n2 + m1 * m2) + '\n');
    }
    console.log(answer);
});

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

var gcd = (a, b) => a ? gcd(b % a, a) : b;
var lcm = (a, b) => a * b / gcd(a, b);

function main(){
	let t = +(readLine());

	while(t--){
		let n = +(readLine());
		let p = readLine().split(" ").map(Number);
		let m = +(readLine());
		let q = readLine().split(" ").map(Number);
		let ctr=0;
		let odd1 = p.filter(x=> x%2==1).length;
		let odd2 = q.filter(x=> x%2==1).length;
		let even1 = p.filter(x=> x%2==0).length;
		let even2 = q.filter(x=> x%2==0).length;
		ctr = odd1*odd2 + even2*even1;
		console.log(ctr);

	}
}

var queriesCount = parseInt(readline());
// var queriesCount = 1;

for (var i = 0; i < queriesCount; i++) {
  readline();
  var DSL = readline().split(' ').map(function(num) {
    return parseInt(num);
  })
  readline();
  var JSL = readline().split(' ').map(function(num) {
    return parseInt(num);
  })

  // var DSL = [1,2,3]
  // var JSL = [0,3]

  var oddsDSL = 0;
  var evensDSL = 0;
  var oddsJSL = 0;
  var evensJSL = 0;

  for (var i = 0; i < DSL.length; i++) {
    if (DSL[i] % 2 === 0) {
      evensDSL++;
    } else {
      oddsDSL++;
    }
  }
  for (var i = 0; i < JSL.length; i++) {
    if (JSL[i] % 2 === 0) {
      evensJSL++;
    } else {
      oddsJSL++;
    }
  }

  write(((evensDSL * evensJSL) + (oddsDSL * oddsJSL)) + '\n')
}
// });


You are given an array of positive integers $$$a = [a_0, a_1, \dots, a_{n - 1}]$$$ ($$$n \ge 2$$$).In one step, the array $$$a$$$ is replaced with another array of length $$$n$$$, in which each element is the greatest common divisor (GCD) of two neighboring elements (the element itself and its right neighbor; consider that the right neighbor of the $$$(n - 1)$$$-th element is the $$$0$$$-th element).Formally speaking, a new array $$$b = [b_0, b_1, \dots, b_{n - 1}]$$$ is being built from array $$$a = [a_0, a_1, \dots, a_{n - 1}]$$$ such that $$$b_i$$$ $$$= \gcd(a_i, a_{(i + 1) \mod n})$$$, where $$$\gcd(x, y)$$$ is the greatest common divisor of $$$x$$$ and $$$y$$$, and $$$x \mod y$$$ is the remainder of $$$x$$$ dividing by $$$y$$$. In one step the array $$$b$$$ is built and then the array $$$a$$$ is replaced with $$$b$$$ (that is, the assignment $$$a$$$ := $$$b$$$ is taking place).For example, if $$$a = [16, 24, 10, 5]$$$ then $$$b = [\gcd(16, 24)$$$, $$$\gcd(24, 10)$$$, $$$\gcd(10, 5)$$$, $$$\gcd(5, 16)]$$$ $$$= [8, 2, 5, 1]$$$. Thus, after one step the array $$$a = [16, 24, 10, 5]$$$ will be equal to $$$[8, 2, 5, 1]$$$.For a given array $$$a$$$, find the minimum number of steps after which all values $$$a_i$$$ become equal (that is, $$$a_0 = a_1 = \dots = a_{n - 1}$$$). If the original array $$$a$$$ consists of identical elements then consider the number of steps is equal to $$$0$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case contains two lines. The first line contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_0, a_1, \dots, a_{n - 1}$$$ ($$$1 \le a_i \le 10^6$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ numbers — answers for each test case.

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        var arr = lines[l++].split(' ').map(Number)
        console.log(solve(n, arr))
    }
});

function solve(n, arr) {
const t1 = new Date()
    const d = arr.reduce((s, x) => gcd(s, x), arr[0])
    let same = true
    arr = arr.map(x => {
        if (x !== d) same = false
        return x / d
    })
    if (same) return 0

// console.log('pre', new Date() - t1)
    // let j = 0
    // for (var i = 0; i < 2 * n; i++) {
    //     j++
    // }
    const tree = []
    createTree(tree, 0, 0, 2 * n - 1, 0)
// console.log('tree created', new Date() - t1)
// return
    initTree(tree, gcd, arr)
// console.log('tree inited', new Date() - t1)

    let max = 0
    for (let i = 0; i < n; i++) {
        const last = binarySearch(i, i + n - 1, x => {
            return i === x || queryTree(tree, 0, i, x, gcd) > 1
        })
        const len = last - i + 1
        max = Math.max(max, len)
        // console.log(i, last, queryTree(tree, 0, i, last, gcd))
    }
    return max
}
function createTree(tree, p, left, right, val) {
    tree[p] = { left, right, val }
    if (left === right) return

    const mid = Math.floor((left + right) / 2)
    createTree(tree, 2 * p + 1, left, mid, val)
    createTree(tree, 2 * p + 2, mid + 1, right, val)

    // const tree = []
    // tree[0] = {
    //     left: 0,
    //     right: n - 1,
    //     val
    // }

    // const q = [[0, n - 1, 0]]
    // while (q.length) {
    //     const [left, right, p] = q.shift()
    //     const mid = Math.floor((left + right) / 2)
    //     tree[2 * p + 1] = {
    //         left,
    //         right: mid,
    //         val
    //     }
    //     if (left !== mid) {
    //         q.push([left, mid, 2 * p + 1])
    //     }

    //     tree[2 * p + 2] = {
    //         left: mid + 1,
    //         right,
    //         val
    //     }
    //     if (mid + 1 !== right) {
    //         q.push([mid + 1, right, 2 * p + 2])
    //     }
    //     console.log('q.length ' + q.length)
    // }
    // return tree
}
function initTree(tree, merge, arr) {
    for (let i = tree.length - 1; i >= 0; i--) {
        if (!tree[i]) continue
        const { left, right } = tree[i]
        tree[i].val = left === right
            ? arr[left % arr.length]
            : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)
    }
}
function insertTree(tree, idx, l, r, val) {
    const { left, right } = tree[idx]
    if (l === left && r === right) {
        tree[idx].val = val
        return
    }

    const mid = Math.floor((left + right) / 2)
    if (r <= mid) {
        insertTree(tree, 2 * idx + 1, l, r, val)
    } else if (l > mid) {
        insertTree(tree, 2 * idx + 2, l, r, val)
    } else {
        insertTree(tree, 2 * idx + 1, l, mid, val)
        insertTree(tree, 2 * idx + 2, mid + 1, r, val)
    }
}
function queryTree(tree, idx, l, r, merge) {
    const { left, right } = tree[idx]
    // if (left === right) return tree[idx].val
    if (l === left && r === right) return tree[idx].val

    const mid = Math.floor((left + right) / 2)
    if (r <= mid) {
        return queryTree(tree, 2 * idx + 1, l, r, merge)
    } else if (l > mid) {
        return queryTree(tree, 2 * idx + 2, l, r, merge)
    } else {
        const a = queryTree(tree, 2 * idx + 1, l, mid, merge)
        const b = queryTree(tree, 2 * idx + 2, mid + 1, r, merge)
        return merge(a, b)
    }
}
function gcd(a, b) {
    if (a === 0) return b
    if (b === 0) return a

    while (a) {
        const r = b % a
        b = a
        a = r
    }
    return b
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
const MAX_A = 1000002;
let n;
let arr;
let primes = [];
let sieve = new Int32Array(MAX_A).fill(0); // min pf of i
function pre() {
    sieve[1] = 1;
    for (let i = 2; i < MAX_A; i++) {
        if (sieve[i] == 0) {
            sieve[i] = i;
            primes.push(i);
            for (let j = i; i * j < MAX_A; j++) {
                sieve[i * j] = i;
            }
        }
    }
    // for (let i = 1; i < 60; i++) {
    //   printf("sieve[%d] %d\n", i, sieve[i]);
    // }
}
function gcd(a, b) {
    while (a > 0) {
        let c = a;
        a = b % a;
        b = c;
    }
    return b;
}
function solve() {
    const pf = Array.from({ length: n });
    for (let i = 0; i < n; i++) {
        pf[i] = new Set();
        let t = arr[i];
        while (t != 1) {
            pf[i].add(sieve[t]);
            t /= sieve[t];
        }
    }
    // printf("arr %j\n", arr);
    let ans = 0;
    for (let i = 0; i < n; i++) {
        for (let p of pf[i]) {
            let cnt = 1;
            let j = (n + i - 1) % n;
            while (pf[j].has(p)) {
                pf[j].delete(p);
                cnt++;
                j = (n + j - 1) % n;
            }
            j = (i + 1) % n;
            while (pf[j].has(p)) {
                pf[j].delete(p);
                cnt++;
                j = (j + 1) % n;
            }
            // printf("i %d p %d cnt %d\n",i, p, cnt);
            ans = Math.max(ans, cnt);
        }
        pf[i].clear();
    }
    return ans;
}
function main() {
    let tc = nextInt();
    pre();
    while (tc-- > 0) {
        n = nextInt();
        arr = new Int32Array(n);
        for (let i = 0; i < n; i++) {
            arr[i] = nextInt();
        }
        let com = arr[0];
        for (let i = 1; i < n; i++) {
            com = gcd(com, arr[i]);
        }
        for (let i = 0; i < n; i++) {
            arr[i] /= com;
        }
        printf("%d\n", solve());
    }
}

var sz;
var gets;

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

function ini(n) {
	size = 1;
	while(size < n)
		size *= 2;
	gets = new Array(2 * size).fill(0);
}

function sets(i, v, cur, l, r) {
	if(r - l == 1) {
		gets[cur] = v;
		return;
	}
	var m = (l + r) >> 1;
	if(i<m)
		sets(i, v, 2 * cur + 1, l, m);
	else
		sets(i, v, 2 * cur + 2, m, r);
	gets[cur] = gcd(gets[2 * cur + 1], gets[2 * cur + 2]);
}

function upd(i, v) {
	sets(i, v, 0, 0, size);
}

function gt(l, r, cur, lx, rx) {
	if(l >= rx || lx >= r)
		return 0;
	if(lx >= l && rx <= r)
		return gets[cur];
	var m = (lx + rx) >> 1;
	var s1 = gt(l, r, 2 * cur + 1, lx, m);
	var s2 = gt(l, r, 2 * cur + 2, m, rx);
	return gcd(s1, s2);
}

function ret(l, r) {
	return gt(l, r, 0, 0, size);
}

var t = parseInt(readline());
for(var tc = 0; tc < t; tc++) {
    var n = parseInt(readline());
    var a = readline().split(" ");
	for(var i = 0; i < n; i++) {
	    a[i] = parseInt(a[i]);
	}
	ini(n);
	for(var i = 0; i < n; i++)
		upd(i, a[i]);
	var l = 0, r = n - 1;
	while(l <= r) {
		var mid = (l + r) >> 1;
		var gc = ret(0, mid + 1);
		var ok = 1;
		for(var i = 1; i < n; i++)
		{
			var idx = i + mid;
			if(idx < n)
				ok &= ret(i, idx + 1) == gc;
			else
			{
				idx %= n;
				ok &= gcd(ret(i, n), ret(0, idx + 1)) == gc;
			}
		}
		if(ok) {
		    r = mid - 1;
		}
		else {
		    l = mid + 1;
		}
	}
	print(l);
}


3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or aliveNEKO#ΦωΦ has just got a new maze game on her PC!The game's main puzzle is a maze, in the forms of a $$$2 \times n$$$ rectangle grid. NEKO's task is to lead a Nekomimi girl from cell $$$(1, 1)$$$ to the gate at $$$(2, n)$$$ and escape the maze. The girl can only move between cells sharing a common side.However, at some moments during the game, some cells may change their state: either from normal ground to lava (which forbids movement into that cell), or vice versa (which makes that cell passable again). Initially all cells are of the ground type.After hours of streaming, NEKO finally figured out there are only $$$q$$$ such moments: the $$$i$$$-th moment toggles the state of cell $$$(r_i, c_i)$$$ (either from ground to lava or vice versa).Knowing this, NEKO wonders, after each of the $$$q$$$ moments, whether it is still possible to move from cell $$$(1, 1)$$$ to cell $$$(2, n)$$$ without going through any lava cells.Although NEKO is a great streamer and gamer, she still can't get through quizzes and problems requiring large amount of Brain Power. Can you help her?

The first line contains integers $$$n$$$, $$$q$$$ ($$$2 \le n \le 10^5$$$, $$$1 \le q \le 10^5$$$). The $$$i$$$-th of $$$q$$$ following lines contains two integers $$$r_i$$$, $$$c_i$$$ ($$$1 \le r_i \le 2$$$, $$$1 \le c_i \le n$$$), denoting the coordinates of the cell to be flipped at the $$$i$$$-th moment. It is guaranteed that cells $$$(1, 1)$$$ and $$$(2, n)$$$ never appear in the query list.

For each moment, if it is possible to travel from cell $$$(1, 1)$$$ to cell $$$(2, n)$$$, print "Yes", otherwise print "No". There should be exactly $$$q$$$ answers, one after every update. You can print the words in any case (either lowercase, uppercase or mixed).

NoteWe'll crack down the example test here:  After the first query, the girl still able to reach the goal. One of the shortest path ways should be: $$$(1,1) \to (1,2) \to (1,3) \to (1,4) \to (1,5) \to (2,5)$$$.  After the second query, it's impossible to move to the goal, since the farthest cell she could reach is $$$(1, 3)$$$.  After the fourth query, the $$$(2, 3)$$$ is not blocked, but now all the $$$4$$$-th column is blocked, so she still can't reach the goal.  After the fifth query, the column barrier has been lifted, thus she can go to the final goal again.

var input = readline().split(" ").map(function(x) { return parseInt(x); });
var n = input[0];
var q = input[1];

var field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);
var blocks = 0;
while(q--)
{
    input = readline().split(" ").map(function(x) { return parseInt(x); });
    var r = input[0];
    var c = input[1];

    var blocksPrev = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
    {
        if (field[i] == 0)
            continue;

        var selfstatus = 0;
        if (field[i] == 3)
            selfstatus = field[i] == 3;

        var leftstatus = 0;
        if (i - 1 >= 0 && (field[i] | field[i - 1]) == 3)
        {
            leftstatus = 1;
            selfstatus |= 1;
        }

        var rightstatus = 0;
        if (i + 1 < n && (field[i] | field[i + 1]) == 3)
        {
            rightstatus = 1;
            selfstatus |= 1;
        }

        blocksPrev += rightstatus | leftstatus | selfstatus;
    }

    field[c - 1] ^= r;

    var blocksAfter = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
    {
        if (field[i] == 0)
            continue;

        var selfstatus = 0;
        if (field[i] == 3)
            selfstatus = field[i] == 3;

        var leftstatus = 0;
        if (i - 1 >= 0 && (field[i] | field[i - 1]) == 3)
        {
            leftstatus = 1;
            selfstatus |= 1;
        }

        var rightstatus = 0;
        if (i + 1 < n && (field[i] | field[i + 1]) == 3)
        {
            rightstatus = 1;
            selfstatus |= 1;
        }

        blocksAfter += rightstatus | leftstatus | selfstatus;
    }

    blocks += blocksAfter - blocksPrev;

    /*
    var ans = "yes";
    for(var i = 0; i < n - 1; i++)
    {
        if ((field[i] | field[i + 1]) == 3)
        {
            ans = "no";
            break;
        }
    }
    */
    if (blocks > 0)
        print("no");
    else
        print("yes");
}

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

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

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

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  let t = 0
  const [n, q] = readInts(input,t++)

  let arr = [Array(n).fill(false), Array(n).fill(false)]

  let result = false

  let blocks = 0
  while(t <= q) {
    let [r, c] = readInts(input,t++)
    r--
    c--

    arr[r][c] = !arr[r][c]

    if(!arr[r][c] && !result) wr('YES')

    else if(arr[r][c]) {
      let r1 = (r + 1) % 2
      if(arr[r1][c - 1] && c > 0) blocks ++
      if(arr[r1][c]) blocks ++
      if(arr[r1][c + 1] && c < n - 1) blocks ++
      if(blocks == 0) {
        result = false
        wr('YES')
      }
      else {
        result = true
        wr('NO')
      }
    }
    else if(!arr[r][c] && result) {
      let r1 = (r + 1) % 2
      if(arr[r1][c - 1]) blocks--
      if(arr[r1][c]) blocks--
      if(arr[r1][c + 1]) blocks--
      if(blocks == 0) {
        result = false
        wr('YES')
      }
      else wr('NO')
    }
    // wr(arr, blocks)
  }
}

var input = readline().split(" ").map(function(x) { return parseInt(x); });
var n = input[0];
var q = input[1];

var field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);
var blocks = 0;
while(q--)
{
    input = readline().split(" ").map(function(x) { return parseInt(x); });
    var r = input[0];
    var c = input[1];

    var blocksPrev = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
        if ((field[i - 1] | field[i] | field[i + 1]) == 3)
            blocksPrev++;

    field[c - 1] ^= r;

    var blocksAfter = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
        if ((field[i - 1] | field[i] | field[i + 1]) == 3)
            blocksAfter++;

    blocks += blocksAfter - blocksPrev;

    /*
    var ans = "yes";
    for(var i = 0; i < n - 1; i++)
    {
        if ((field[i] | field[i + 1]) == 3)
        {
            ans = "no";
            break;
        }
    }
    */
    if (blocks > 0)
        print("no");
    else
        print("yes");
}

var input = readline().split(" ").map(function(x) { return parseInt(x); });
var n = input[0];
var q = input[1];

var field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);
var blocks = 0;
while(q--)
{
    input = readline().split(" ").map(function(x) { return parseInt(x); });
    var r = input[0];
    var c = input[1];

    var blocksPrev = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
    {
        var status = field[i];
        if (i - 1 >= 0)
            status |= field[i - 1];
        if (i + 1 < n)
            status |= field[i + 1];

        if (status == 3)
            blocksPrev++;
    }

    field[c - 1] ^= r;

    var blocksAfter = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
    {
        var status = field[i];
        if (i - 1 >= 0)
            status |= field[i - 1];
        if (i + 1 < n)
            status |= field[i + 1];

        if (status == 3)
            blocksAfter++;
    }

    blocks += blocksAfter - blocksPrev;

    /*
    var ans = "yes";
    for(var i = 0; i < n - 1; i++)
    {
        if ((field[i] | field[i + 1]) == 3)
        {
            ans = "no";
            break;
        }
    }
    */
    if (blocks > 0)
        print("no");
    else
        print("yes");
}

var input = readline().split(" ").map(function(x) { return parseInt(x); });
var n = input[0];
var q = input[1];

var field = Array.apply(null, Array(n)).map(Number.prototype.valueOf,0);
var blocks = 0;
while(q--)
{
    input = readline().split(" ").map(function(x) { return parseInt(x); });
    var r = input[0];
    var c = input[1];

    var blocksPrev = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
    {
        var status = field[i];
        if (i - 1 >= 0)
            status |= field[i - 1];
        if (i + 1 < n)
            status |= field[i + 1];

        if (status == 3)
            blocksPrev++;
    }

    field[c - 1] ^= r;

    var blocksAfter = 0;
    for (var i = Math.max(0, c - 3); i < Math.min(n, c + 2); i++)
    {
        var status = field[i];
        if (i - 1 >= 0)
            status |= field[i - 1];
        if (i + 1 < n)
            status |= field[i + 1];

        if (status == 3)
            blocksPrev++;
    }

    blocks += blocksAfter - blocksPrev;

    /*
    var ans = "yes";
    for(var i = 0; i < n - 1; i++)
    {
        if ((field[i] | field[i + 1]) == 3)
        {
            ans = "no";
            break;
        }
    }
    */
    if (blocks > 0)
        print("no");
    else
        print("yes");
}