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

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

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = y[n-1]-y[0];
        for (let i = 1; i < n;++i) {
          res = Math.max(res,y[i]-y[0]);
          res = Math.max(res,y[n-1]-y[i-1])
          res = Math.max(res,y[i-1]-y[i])
        }
        console.log(res);
    }
}

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

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

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

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const a = await rns();
  let res = a[n - 1] - a[0],
      min = Infinity,
      max = -Infinity;
  for (let i = 0; i < n; i++) {
    if (i < n - 1) {
      res = Math.max(res, a[i] - a[i + 1]);
      min = Math.min(min, a[i]);
    }
    if (i > 0) max = Math.max(max, a[i]);
  }
  res = Math.max(res, max - a[0], a[n - 1] - min);
  return res;
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

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

let i = 0;
rl.on('line', function(line){
    i++;
    if (i > 1 && i % 2 === 1) {
        // console.log('--->', line);
        processLine(line)
    }
})

function processLine(line) {
    const arr = line.split(' ').map(Number);
    if (arr.length < 2) {
        console.log(0);
        return;
    };
    if (arr.length === 2) {
        console.log(Math.abs(arr[1] - arr[0]));
        return;
    }
    const asIs = arr[arr.length - 1] - arr[0];
    const left = Math.max(...arr.slice(1)) - arr[0];
    const right = arr[arr.length - 1] - Math.min(...arr.slice(0, arr.length - 1));
    const pairs = [];
    for (let i = 0; i < arr.length - 1; i++) {
        pairs.push(arr[i] - arr[i+1]);
    }
    console.log(Math.max(asIs, left, right, ...pairs));
}

;
var inp = [];
var lines;
var lineCounter = 0;
var readline = function () { return lines[lineCounter++]; };
process.stdin.on('data', function (c) { return inp.push(c); });
process.stdin.on('end', function () {
    lines = inp.join('').split('\n');
    myMain();
});
function myMain() {
    var ntest = +readline();
    for (var testcase = 0; testcase < ntest; ++testcase) {
        var n = +readline();
        var a = readline().split(' ').map(function (x) { return +x; });
        var ans = a[n - 1] - a[0];
        for (var i = 0; i < n - 1; ++i) {
            ans = Math.max(ans, a[i] - a[i + 1]);
        }
        for (var i = 1; i < n; ++i) {
            ans = Math.max(ans, a[i] - a[0]);
        }
        for (var i = 0; i < n - 1; ++i) {
            ans = Math.max(ans, a[n - 1] - a[i]);
        }
        console.log(ans);
    }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = 0;
        for (let i = 1; i < n;++i) {
          res = Math.max(res,y[i]-y[0]);
          res = Math.max(res,y[n-1]-y[i-1])
        }
        if (n > 1) {
          res = Math.max(res,y[n-2]-y[n-1]);
        }
        console.log(res);
    }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = 0;
        for (let i = 1; i < n;++i) {
          res = Math.max(res,y[i]-y[0]);
          res = Math.max(res,y[n-1]-y[i-1])
        }
        console.log(res);
    }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = 0;
        for (let i = 0; i < n;++i) {
          for (let j = 0;j < n;++j) {
            res = Math.max(res,y[i]-y[j]);
          }
        }
        console.log(res);
    }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        for (let i = 0; i < n;++i) {
          nin = Math.min(nin,y[i]);
          nax = Math.max(nax,y[i]);
        }
        console.log(nax-nin);
    }
}

let inputString = [], currentLine = 0;
var fs = require( 'fs');
var readline = require('readline');
function read() {
   const readStream = fs.createReadStream('data', 'utf-8');
   let rl = readline.createInterface({ input: readStream });
   rl.on('line', line => { inputString.push(line) });
   readStream.on('error', (error) => console.log(error.message));
   readStream.on('end', () => {  main()  });
};
read();

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

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

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

let inputString = [], currentLine = 0;
var fs = require( 'fs');
var readline = require('readline');
function read() {
   const readStream = fs.createReadStream('data.txt', 'utf-8');
   let rl = readline.createInterface({ input: readStream });
   rl.on('line', line => { inputString.push(line) });
   readStream.on('error', (error) => console.log(error.message));
   readStream.on('end', () => {  main()  });
};
read();

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

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

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

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

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

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = Math.abs(arr[n-1-i] - arr[(n-i)%n]);
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = min;
    else arr[n-1] = max;

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const a = await rns();
  let res = a[n - 1] - a[0],
      min = Infinity,
      max = -Infinity;
  for (let i = 0; i < n; i++) {
    if (i < n - 1) {
      res = Math.max(res, a[i + 1] - a[i]);
      min = Math.min(min, a[i]);
    }
    if (i > 0) max = Math.max(max, a[i]);
  }
  res = Math.max(res, max - a[0], a[n - 1] - min);
  return res;
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();


const n = readline();

for (var i = 0; i < n; i++) {
    var num = readline();
    print(Math.ceil(num / 2) - 1);
}

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

const input = [];

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

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

  for (let i = 1; i <= t; i += 1) {
    const n = parseInt(input[i]);
    if (n <= 2) console.log(0);
    else {
      if (n % 2 === 0) console.log(n / 2 - 1);
      else console.log((n - 1) / 2);
    }
  }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n'); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    while (tests--) {
        var n = parseInt(readline());
        if ((n % 2) === 0) {
            console.log(Math.floor((n / 2) - 1));
        }
        else {
            console.log(Math.floor(n / 2));
        }
    }
}

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

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

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

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input = parseInt(readline());
        if (input % 2 == 0) {
            print(parseInt((input / 2) - 1))
        }
        else {
            print(parseInt(input / 2))
        }

    }

}

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const n = +lines[i+1]
    if (n > 2) {
      console.log(Math.floor((n-1)/2))
    } else {
      console.log(0)
    }
  }
}

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

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const main = () => {
  let t = Number(readline());
  while (t--) {
    const n = Number(readline());
    print(n - Math.ceil(n / 2) - (n % 2 === 0 ? 1 : 0));
  }
  // let t = readline().split(' ').map(x => parseInt(x));
};

function div(a, b) {
  if (a < 0) {
    throw Error('numerator must be non-negative');
  } else if (b <= 0) {
    throw Error('denominator must be positive');
  } else {
    const r = a % b;
    return (a - r) / b;
  }
}

function solve(n) {
  return ((n % 2) === 0) ? div(n - 2, 2) : div(n - 1, 2);
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    const n = Number(line);
    const result = solve(n);
    console.log(result);
  }
}

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

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

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

processLinesFromStream(process.stdin, main);

function div(a, b) {
  if (a < 0) {
    throw Error('numerator must be positive');
  } else if (b <= 0) {
    throw Error('denominator must be positive');
  } else {
    const r = a % b;
    return (a - r) / b;
  }
}

function solve(n) {
  return ((n % 2) === 0) ? div(n - 2, 2) : div(n - 1, 2);
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    let t = line.trim();
    if (line.length > 0) {
      const n = Number(t);
      console.log(solve(n));
    }
  }
}

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

processLinesFromStream(process.stdin, main);

'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.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n) {
  return Math.floor((n-1)/2);
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    // let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

var data = "";

process.stdin.on("data", x => data += x);

// process.on("SIGINT", () => {
process.stdin.on("end", () => {

    var eol = data.indexOf("\r")+1 ? (data.indexOf("\n")+1 ? "\r\n" : "\r") : "\n";

    var lines = data.split(eol);

	var lines0 = lines.shift();

    var n = lines0;

    if(lines[lines.length-1] == "") lines.pop();

    for(let i = 0; i < n; i++) {

        var arr = [];
        var l = f.length;
        for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);
        if(!l) {
            arr = lines;
            i = n;
        }
        f.apply({lines0}, arr);
    }

	console.log(ans);

    process.exit(0);
});

var ans = "";

function f(l) {
	ans += `${l > 2 ? (l-1)/2|0 : 0} `;
}

// Sample code to perform I/O:

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

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let testCase = +inputs[0];
    let ways = [];
    for (let index = 1; index <= testCase; index++) {
        const element = +inputs[index];

        if (element > 2) {
            let quotient = element / 2;
            ways.push(quotient % 1 === 0 ? quotient - 1 : Math.trunc(quotient));
        }
        else {
            ways.push(0);
        }

    }

    return ways.join('\n').toString();
}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    for (var i = 0; i < n; i++) {
        let t = parseInt(readLine());
        if (t % 2 == 1) {
            console.log((t + 1) / 2 - 1)
        } else {
            if (t == 0) console.log(0)
            else
                console.log(t / 2 - 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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function solve(x) {
    if (x % 2 === 0) {
        console.log((x/2)-1);
    } else {
        console.log(Math.floor(x/2));
    }
}

function main() {
    let n = parseInt(readline(), 10);

    for (var i = 0; i < n; i++) {
        solve(parseInt(readline()));
    }

}

var numberTestData = +readline();
for (var currentTest = 0; currentTest<numberTestData; currentTest++) {
    var numberCandies = +readline();
    if (numberCandies>2) {
        numberCandies%2===0 ? print(numberCandies/2-1) : print((numberCandies-1)/2);
    } else print(0);
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const n = getInt()
    print(parseInt(n / 2) - ((n % 2) === 0))
  }
}

var n = parseInt(readline());

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

for (var i = 0; i < n; i++) {
    var a = parseInt(readline());
    var res = (a - 1) >> 1;
    write(res+'\n');
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    if(input <=2){
        print(0);
        continue;
    }
    var temp = input%2;
    if(temp === 0){
        temp = (input/2)+1;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

var t = +readline();
while(t--){
    var n = +readline();
    var ans = (n%2==0)?n/2-1:(n-1)/2;
    print(ans);
}

const n = readline();

for (var i = 0; i < n; i++) {
    print(Math.ceil(readline() / 2) - 1);
}

var t = parseInt(readline());

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

    if (n <= 2) {
        print(0);
    } else {
        if (n % 2 === 0) {
            print(n / 2 - 1);
        } else {
            print(Math.floor(n / 2));
        }
    }
}

var candies=readline();
// var candies=prompt();
var candiesNum=[];
for(var i=0;i<candies;i++){
    candiesNum[i]=readline();
    // candiesNum[i]=prompt();
    if(candiesNum[i]<3){
        print(0);
        // console.log("0");
    }
    else{
        if(candiesNum[i]%2===0){
            print((candiesNum[i]/2)-1);
            // console.log((candiesNum[i]/2)-1);
        }
        else{
            print(Math.floor(candiesNum[i]/2));
            // console.log(Math.floor(candiesNum[i]/2));
        }
    }
}

var str = +readline();

for (var i=0; i<str; i++) {
    var x = +readline();
     if (x <= 2) {
        write("0\n");
    } else {
        write(parseInt((x - 1) / 2) + '\n');
    }
}

var t = readline();

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

  if (n % 2) {
    print(~~(n / 2));
  } else {
    print(~~(n / 2) - 1);
  }
}

function data()
{
	  var t=readline();
	  while(t--)
	  {
		  var n=readline();
		  print(parseInt((n-1)/2));
	  }
}
data();

var inputs = readline();

for(var k=0;k<inputs;k++) {
    var candies = readline();

    if(candies < 3) {
        print(0);
    } else {
        if(candies % 2 === 0) {
            print((candies / 2) - 1);
        } else {
            print(Math.floor(candies / 2))
        }
    }

}

'use strict';

const rl = require('readline')
  .createInterface({ input: process.stdin, output: process.stdout });
const write = (...args) => {
  process.stdout.write(args.join(' '));
};

const lines = [];
rl.on('line', line => {
  lines.push(line);
});

rl.on('close', main);

let rli = 0;
function readline() {
  return lines[rli++];
}

function main() {
  const time = parseInt(readline());
  for(let t = 0; t < time; ++t) {
    let number = Math.ceil(parseInt(readline())/2);
    if(number > 0) {
      number = number - 1;
    }
    write(`${number}\n`);
  }
  //write(`${one_line}\n`);
}

// solved by: asmjaime

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var input_lines;
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    input_lines = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function input() {
    return input_lines[currentLine++];
}
function EOF() {
    return currentLine >= input_lines.length;
}
function main() {
    var t = parseInt(input());
    for (var i = 0; i < t; i++) {
        var n = parseInt(input());
        console.log(Math.floor((n - 1) / 2));
    }
}

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

const MOD1 = 1000000007

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

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

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() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const n = readInt()
    if(n <= 2) wr(0)
    else {
      let half = Math.floor(n / 2)
      if((n & 1) === 0) wr(half - 1)
      else wr(half)
    }

  }
}

const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
  for (i = 1; i < lines.length; i++) {
    if (+lines[i] > 2) {
      process.stdout.write(
        +lines[i] % 2 !== 0 ?
          `${Math.floor(+lines[i] / 2)}\n` :
          `${+lines[i] / 2 - 1}\n`
      );
    } else {
      process.stdout.write('0\n');
    }
  }
});

//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 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 N = nextInt();
    if(N < 3){
      output[i] = 0;
    }else{
      if(N % 2 == 1){
        output[i] = Math.floor(N / 2);
      }else{
        output[i] = N / 2 - 1;
      }
    }
  }
  myout(myconv(output, 9));
}

//DISABLE THIS LINE END ENABLE NEXT
//const rl =  require('readline').createInterface({input: require('fs').createReadStream('input.txt')});
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const write = (...args) => {
    process.stdout.write(args.join(' ') );
}
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)

let rli = 0;
function readline() {
    return lines[rli++];
}

function main() {
	var y = +readline()
	while(y > 0) {
		var z = +readline();
		var p1 = z % 2;
		var z_corr = z - p1;
		var res = p1 +  (z_corr/2  - 1) ;
		if (res < 0) { res = 0;}
		if (y > 1) {
			write(res + '\n');
		} else {
			write(res);
		}
		y--;
	}
}

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

  let nr = +d;

  if (nr % 2 === 0) {
    console.log(nr / 2 - 1);
  }
  else {
    console.log(Math.floor(nr / 2));
  }

  c++;
});

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 === 0){
            console.log((+arr[i])/2 - 1);
        } else {
            console.log(Math.floor((+arr[i])/2))
        }
    }
}

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

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

const processData = (input) => {
    console.log(input);
}

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

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

const processData = (input) => {
    let exp = /\s/;
    let arr = input.split(exp);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 == 0){
            console.log(arr[i]/2 - 1);
        } else {
            console.log(Math.floor(arr[i]/2))
        }
    }
}

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

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

const processData = (input) => {
    let exp = /\s/;
    let arr = input.split(exp);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    console.log(arr);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 === 0){
            console.log((+arr[i])/2 - 1);
        } else {
            console.log(Math.floor((+arr[i])/2))
        }
    }
}

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

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

const processData = (input) => {
    let exp = /\s/;
    let arr = input.split(exp);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 == 0){
            console.log((+arr[i])/2 - 1);
        } else {
            console.log(Math.floor((+arr[i])/2))
        }
    }
}

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

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

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

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

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

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input = parseInt(readline());
        if (input % 2 == 0) {
            print((input / 2) - 1)
        }
        else {
            print(input / 2)
        }

    }

}

var data = "";

process.stdin.on("data", x => data += x);

process.on("SIGINT", () => {
// process.stdin.on("end", () => {

    var eol = data.indexOf("\r")+1 ? (data.indexOf("\n")+1 ? "\r\n" : "\r") : "\n";

    var lines = data.split(eol);

	var lines0 = lines.shift();

    var n = lines0;

    if(lines[lines.length-1] == "") lines.pop();

    for(let i = 0; i < n; i++) {

        var arr = [];
        var l = f.length;
        for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);
        if(!l) {
            arr = lines;
            i = n;
        }
        f.apply({lines0}, arr);
    }

	console.log(ans);

    process.exit(0);
});

var ans = "";

function f(l) {
	ans += `${l > 2 ? (l-1)/2|0 : 0} `;
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = readline();
    var temp = input%2;
    if(temp === 0){
        temp++;
    }else{
        temp = Math.ceil(temp);
    }
    print(input-temp)
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    var temp = input%2;
    if(temp === 0){
        temp = input/2;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    if(input <=2){
        print(0);
        continue;
    }
    var temp = input%2;
    if(temp === 0){
        temp = input/2;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    if(input <=2){
        print(0);
        break;
    }
    var temp = input%2;
    if(temp === 0){
        temp = input/2;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

const n = readline();

for (var i = 0; i < n; i++) {
    var num = readline();
    print(Math.ceil(n / 2) - 1);
}

var candies=readline();
// var candies=prompt();
var candiesNum=[];
for(var i=0;i<candies;i++){
    candiesNum[i]=readline();
    // candiesNum[i]=prompt();
    if(candiesNum[i]<3){
        print(0);
        // console.log("0");
    }
    else{
        if(candiesNum[i]%2===0){
            print((candiesNum/2)-1);
            // console.log((candiesNum[i]/2)-1);
        }
        else{
            print(Math.floor(candiesNum[i]/2));
            // console.log(Math.floor(candiesNum[i]/2));
        }
    }
}

var str = +readline();

for (var i=0; i<str; i++) {
var x = +readline();
 if (x <= 2) {
    write("0\n");
} else {
    write(parseInt(x / 2) + '\n');
}
}

function data()
{
	  var t=readline();
	  while(t--)
	  {
		  var n=readline();
		  print((n-1)/2);
	  }
}
data();

function data()
{
	  var t=readline();
	  while(t--)
	  {
		  var n=readline();
		  print(parseInt(n-1)/2);
	  }
}
data();


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let [countD, seq, countR, countL] = [0, 0, 0, 0];

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") {
        if ((i > 0 && str[i - 1] !== "-") || i === 0) seq++;
        countD++;
      } else if (char === ">") countR++;
      else countL++;
    }

    if (str[0] === "-" && str[len - 1] === "-") seq--;

    if (countD === len || countD + countL === len || countD + countR === len || countL === len || countR === len) {
      console.log(len);
    } else {
      if (countD) {
        console.log(countD + seq);
      } else {
        console.log(0);
      }
    }
  }
}

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

function read() {
  return lines[index++];
}

function main(){
 let t = Number(read());
  while (t--) {
    let num = Number(read())
    let line = read().split('');
    let map = {'-': 0, '>': 0, '<': 0};
    line.forEach(key => map[key]++);
    let zeros = Object.values(map).filter(count => count === 0).length;
    if (zeros === 2 || zeros === 1 && map['-'] !== 0) {
      console.log(num)
      continue
    }
    let prev = line[line.length - 1];
    let count = 0;
    for(let i = 0; i < line.length; i++) {
      let curr = line[i];
      if (curr === '-'){
        count += (prev === '-' ? 0 : 1) + 1
      }
      prev = curr
    }
    console.log(count)
  }
}

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

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

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

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

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

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

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

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

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

  let t = +$()
  while (t--) {
    let n = +$(), s = $()
    if (s.includes('<') && s.includes('>')) {
      s += s[0];
      let res = 0;
      For(n, i => {
        if (s[i] == '-' || s[i + 1] == '-') res++;
      })
      log(res)
    } else {
      log(n);
    }
  }
}

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

let lineNum = 0;
let countOfData = null;
let data = [];
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line * 2;
    return;
  }

  data.push(line.split(' '));

  if(lineNum - 1 === countOfData) {
    goToSolution(data);
  }

});

function goToSolution(data) {
  for(let i = 0;i < data.length; i+=2) {
    const rooms = data[i][0];
    const directions = data[i + 1][0];
    let roomsWithReturn = 0;
    let isLeftAvailable = false;
    let isRightAvailable = false;

    if(directions[0] === '-' && directions[directions.length - 1] === '-') roomsWithReturn--;
    for(let j = 0; j < directions.length; j++) {
      const state = directions[j];
      if(state === '-') {
        directions[j - 1] === '-' ? roomsWithReturn++ : roomsWithReturn += 2;
      }
      if(state === '>') {
        isRightAvailable = true;
      }
      if(state === '<') {
        isLeftAvailable = true;
      }
    }

    if((isLeftAvailable && !isRightAvailable) || (!isLeftAvailable && isRightAvailable) || (!isLeftAvailable && !isRightAvailable)) {
      console.log(+rooms)
    } else {
      console.log(roomsWithReturn)
    }
  }

}

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 => string.trim());

    main();
});

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

function main() {
    const numCases = readLine();
    for (let i = 0; i < numCases; i++) {
        const numRooms = readLine();
        let belts = readLine();
        let returnableRooms = 0;

        if (!(belts.includes('<') && belts.includes('>'))) {
            console.log(numRooms);
            continue;
        }

        const lastNonMinus = Math.max(belts.lastIndexOf('<'), belts.lastIndexOf('>'));
        const numMinusAtEnd = belts.length - lastNonMinus - 1;
        if (numMinusAtEnd > 0) {
            belts = '-'.repeat(numMinusAtEnd) + belts.slice(0, lastNonMinus + 1);
        }

        for (let k = 0; k < belts.length; k++) {
            if (belts[k] !== '-') continue;
            let end = k + 1;
            while (end < belts.length && belts[end] === '-') {
                end++;
            }
            returnableRooms += end - k + 1
            k = end;
        }
        console.log(returnableRooms);
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let [countD, countR, countL] = [0, 0, 0];

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") countD++;
      else if (char === ">") countR++;
      else countL++;
    }

    if (countD === len || countD + countL === len || countD + countR === len || countL === len || countR === len) {
      console.log(len);
    } else {
      if (countD) {
        console.log(countD + 1);
      } else {
        console.log(countD);
      }
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let countDash = 0;
    let tmpStr = "";

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") countDash++;
      else tmpStr += char;
    }

    if (str.includes("><") || str.includes("<>") || tmpStr.includes("><")) {
      if (countDash) {
        console.log(countDash + 1);
      } else {
        console.log(countDash);
      }
    } else {
      console.log(len);
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let countDash = 0;

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") countDash++;
    }

    if (str.includes("><") || str.includes("<>")) {
      if (countDash) {
        console.log(countDash + 1);
      } else {
        console.log(countDash);
      }
    } else {
      console.log(len);
    }
  }
}

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

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

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

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

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

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

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

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

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

  let t = +$()
  while (t--) {
    let n = $(), s = $(), a = Arr(n, i => 0);
    For(n, i => {
      let j = i == 0 ? n - 1 : i - 1;
      if ((s[i] == '>' && s[j] == '<') || (s[i] == '<' && s[j] == '>')) a[i] = 1;
    })
    For(n, i => {
      if (a[i] != 1) return;
      let j = (i - 1 + n) % n;
      while (a[j] == 0 && s[j] != '-') {
        a[j] = 1;
        j = (j - 1 + n) % n;
      }
    })
    For(n, i => {
      if (a[i] != 1) return;
      let j = (i + 1) % n;
      while (a[j] == 0 && s[j] != '-') {
        a[j] = 1;
        j = (j + 1) % n;
      }
    })
    // log(a)
    log(n - a.sum());
  }
}

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

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

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

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

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

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

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

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

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

  let t = +$()
  while (t--) {
    let n = $(), s = $()
    s += s[0];
    let res = 0;
    For(n, i => {
      if ((s[i] == '>' && s[i + 1] == '<') || (s[i] == '<' && s[i + 1] == '>')) res++;
    })
    log(n-res);
  }
}


print(function(n, a) {

	if (n % 2 === 1) a.push(0);

	return Math.PI * a.sort(function(a, b) {
		return b - a;
	}).map(function(v) {
		return v * v;
	}).reduce(function(sum, v, i, a) {
		if (i % 2 === 0) return sum + v - a[i + 1];
		return sum;
	}, 0);

}(+readline(), readline().split(' ').map(Number)));

;(function () {
	print(function () {
		var n = +readline(), t = 0,
			a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

		if ((n%2) === 1) a.unshift(0);

		for (var i = a.length - 1; i > 0; i -= 2)
			t += Math.PI * (Math.pow(a[i], 2) - Math.pow(a[i - 1], 2));

		return t;
	}());
}).call(this);

var n = Number(readline());
var radi = readline().split(' ').map(function (e) { return Number(e); });

function compareNumbers(a, b) {
  return a - b;
}

radi.sort(compareNumbers);

var pi = 3.1415926536;
var ans = 0;

for (var i=n - 1; i >= 0; i -= 2) {
	ans += pi * (radi[i] * radi[i]);
	if (i > 0) ans -= pi * (radi[i-1]*radi[i-1]);
}

print(ans);

print(function(n, a) {

	a = a.sort(function(a, b) {
		return a - b;
	}).map(function(v) {
		return v * v;
	});

	var sum = 0;
	for (var i = n; i >= 1; i -= 2) {
		sum += a[i] - a[i - 1];
	}

	return sum * Math.PI;

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

print(function(n, a) {

	a = a.sort(function(a, b) {
		return a - b;
	}).map(function(v) {
		return v * v;
	});

	for (var i = n-2; i >= 0; i--) {
		a[i + 1] -= a[i];
	}

	var s1 = 0,
		s2 = 0;
	for (var i = 0; i < n; i++)
		if (i % 2 === 0) s1 += a[i];
		else s2 += a[i];

	return Math.max(s1, s2) * Math.PI;

}(+readline(), readline().split(' ').map(Number)));

var n = Number(readline());
var radi = readline().split(' ').map(function (e) { return Number(e); });
radi.sort();

var pi = 3.1415926536;
var ans = 0;

for (var i=n - 1; i >= 0; i -= 2) {
	ans += pi * (radi[i] * radi[i]);
	if (i > 0) ans -= pi * (radi[i-1]*radi[i-1]);
}

print(ans);


var n = +readline();

for (var i=0; i<n; i++){
	var q = +readline();
	q = q.toString(2);
	var numown = 0;
		for (var j=0; j<q.length; j++){
			numown += parseInt(q[j]);
		}
	print (Math.pow(2, numown));
}

var length = +readline();
var cnts = [];

for(var i = 0; i < length; i++) {
    var number = +readline();
    var cnt = 1;

    while(number) {
        var rest = number % 2;
        number = Math.round(number / 2) - rest;

        if(rest) cnt *= 2;
    }

    cnts.push(cnt);
}

cnts.forEach(v => print(v));


const solve = (n,arr,k)=>{
     arr = arr.sort((a,b)=>a-b);
     let i=0;j=1,ans = false;
     if(n===1) ans = arr[0]===k;
     else{
          while(i<n && j<n){
               if(arr[i]+k===arr[j]){
                    ans = true;
                    break;
               }
               if(arr[i]+k<=arr[j]) i++;
               else j++;
          }
     }
     return ans?"YES":"NO";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let [n,k] = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(n,arr,k));
  }
}
main();

"use strict";

//..................................import for reading input...................................//
  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() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});
  let ans = isPairSum(line, n, k);
  console.log(ans);
}

function isPairSum (a, n, x) {
  let i = 0;
  let j = 1;
  x = Math.abs(x);
  while (i < n && j < n) {
    if (a[i] + x === a[j]) return "YES";
    else if (a[i] + x < a[j]) i++;
    else j++;
  }
  return "NO";
}

// load('js/subtract_operation.js')

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

const EPS = 1e-6;

function main() {
    let T = +readline();
    while (T--){
      let [n, k] = readline().split(' ').map(a=>+a);
      let arr = readline().split(' ').map(a=>+a);
      let set = new Set();
      let set2 = new Set();
      let yes = false;
      for (let i=0; i<n; i++){
        if (set.has(arr[i]-k) || set2.has(arr[i]))
        {
          yes = true
          break;
        }
        set.add(arr[i])
        set2.add(arr[i]-k)
      }
      print(yes ? 'yes' : 'no')
    }
}

"use strict";

//..................................import for reading input...................................//
  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() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});
  let ans = isPairSum(line, n, k);

  console.log(ans);
}

function isPairSum (a, n, x) {
  let i = 0;
  let j = n-1;

  while (i < j) {
    if (a[j] - a[i] == x) return "YES";
    else if (a[j] - a[i] < x) i++;
    else j--;
  }
  return "NO";
}
// load('js/cf.js')

"use strict";

//..................................import for reading input...................................//
  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() {
  var t = +(readline());
  console.log(t);
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

"use strict";

//..................................import for reading input...................................//
  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() {
  let t = +(readline());
  console.log(t);
  while (t--) {
    solution();
  }
}

function solution() {
  console.log("solution");
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();

"use strict";

//..................................import for reading input...................................//
  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() {
  let t = +(readline());
  console.log("main");
  while (t--) {
    solution();
  }
}

function solution() {
  console.log("solution");
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();
// load('js/cf.js')

"use strict";

//..................................import for reading input...................................//
  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() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  console.log("Solution");
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();

"use strict";

//..................................import for reading input...................................//
  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() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});
  console.log('n : ' + n + ', k :' + k);
  console.log(line);

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();

"use strict";

//..................................import for reading input...................................//
  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() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();
// load('js/cf.js')

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

const EPS = 1e-6;

function main() {
    let T = +readline();
    while (T--){
      let [n, k] = readline().split(' ').map(a=>+a);
      let arr = readline().split(' ').map(a=>+a);
      let set = new Set();
      let yes = false;
      for (let i=0; i<n; i++){
        if (set.has(arr[i]+k))
        {
          yes = true
          break;
        }
        set.add(arr[i])
      }
      print(yes ? 'yes' : 'no')
    }
}

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

const EPS = 1e-6;

function main() {
    let T = +readline();
    while (T--){
      let [n, k] = readline().split(' ').map(a=>+a);
      let arr = readline().split(' ').map(a=>+a);
      let minI = -1, maxI = -1;
      for (let i=0; i<n; i++){
        if (minI==-1 || arr[minI]<arr[i])
          minI = i;
        if (maxI==-1 || arr[maxI]>arr[i])
          maxI = i;
      }
      print(arr[minI]-arr[maxI]==k ? 'yes' : 'no')
    }
}


const readline = require('readline');

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

function f(n123, m) {
  const arr = m.split(' ');
  const n = arr.length;
  const n2 = Math.floor(n / 2);
  for(let i = 0; i < n2; i++) {
    arr[i] -= i;
    arr[n-i-1] -= i;
  }
  if(n % 2) {
    arr[n2] -= n2;
  }
  const obj = arr.reduce((obj, n) => {
    if(!obj[n]) {
      obj[n] = 0;
    }
    obj[n]++;
    return obj;
  }, {});
  const max = Math.max(...Object.entries(obj).filter(([e]) => e > 0).map(e => e[1]));
  return n - max;
}

rl.question('', n => {
  rl.question('', m => {
    console.log(f(n, m));

    rl.close();
    process.stdin.destroy();
  });
});

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

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

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

function main() {
	var n = parseInt(readline()),
		trees = tokenizeIntegers(readline()),
		counts = {}, max = 0,
		increment = 0,
		rise = Math.floor((n-1)/2), fall = Math.floor(n/2);
	for (var i = 0; i < n; ++i) {
		var value = trees[i]-increment;
		if (value > 0) {
			if (counts[value] === undefined) {
				counts[value] = 1;
			} else {
				counts[value] += 1;
			}
			max = Math.max(max, counts[value]);
		}
		if (i < rise) {
			++increment;
		} else if (i >= fall) {
			--increment;
		}
	}
	print(n - max);
}

main();

const readline = require('readline');

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

function f(n123, m) {
  const arr = m.split(' ');
  const n = arr.length;
  const n2 = Math.floor(n / 2);
  for(let i = 0; i < n2; i++) {
    arr[i] -= i;
    arr[n-i-1] -= i;
  }
  if(n % 2) {
    arr[n2] -= n2;
  }
  const obj = arr.reduce((obj, n) => {
    if(!obj[n]) {
      obj[n] = 0;
    }
    obj[n]++;
    return obj;
  }, {});
  const max = Math.max(...Object.values(obj));
  return n - max;
}

rl.question('', n => {
  rl.question('', m => {
    console.log(f(n, m));

    rl.close();
    process.stdin.destroy();
  });
});

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

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

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

function main() {
	var n = parseInt(readline()),
		trees = tokenizeIntegers(readline()),
		counts = {}, max = 0,
		increment = 0,
		rise = Math.floor((n-1)/2), fall = Math.floor(n/2);
	for (var i = 0; i < n; ++i) {
		var value = trees[i]-increment;
		if (counts[value] === undefined) {
			counts[value] = 1;
		} else {
			counts[value] += 1;
		}
		max = Math.max(max, counts[value]);
		if (i < rise) {
			++increment;
		} else if (i >= fall) {
			--increment;
		}
	}
	print(n - max);
}

main();


function myout(t){print(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),1);
  var output = [];
  for(var i = 0; i < N; i++){
      var year = myconv(readline(),0);
      if(parseInt(year) < 10){
          output.push(year);
      }else if(parseInt(year) == 10){
          output.push(9);
      }else{
          var counted = 9 * (year.length-1);
          var one = makeOne(year.length);
          output.push(counted + Math.floor(parseInt(year)/one));
      }
  }
  myout(output.join("\n"));
}

function makeOne(input){
    var ret = 0;
    for(var i = 1; i <= input; i++){
        ret = ret *10 + 1;
    }
    return ret;
}

Main();

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, ''))

  const t = parseInt(arr.shift())

  for(let j = 0; j < t; j++) {
    const n = parseInt(arr[j])
    let s = n.toString()
    let len = s.length
    let sum = 9 * (len - 1)

    let first = s[0]
    if(len == 1) {
      sum = n
      console.log(sum)
      continue
    }
    let i = 1
    for(i = 1; i < len; i++) {
      if(s[i] == s[i - 1]) continue
      else if(s[i] < s[i - 1]) {
        sum += parseInt(s[0]) - 1
        break
      }
      else if(s[i] > s[i - 1] && s[i] != 0) {
        sum += parseInt(s[0])
        break
      }
    }
    if(i == len) {
      sum += parseInt(s[0])
    }

    console.log(sum)

  }
})

'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 readALine() {
    return inputString[currentLine++];
}

function printALine(str) {
    console.log(str);
}

function stringArrayToNumbers(str) {
    var array = str.split(" ");
    var result = [];
    for( var i = 0; i < array.length; i++ ) {
        result.push( parseInt(array[i]) );
    }
    return result;
}

function stringArrayToBigInts(str) {
    var array = str.split(" ");
    var result = [];
    for( var i = 0; i < array.length; i++ ) {
        result.push( BigInt(array[i]) );
    }
    return result;
}

// ======================================================
// A. Happy Birthday, Polycarp!
// https://codeforces.com/problemset/problem/1277/A
// ======================================================

function doIt( num ) {

    var result = 0;
    if( num === 1 ) return 1;

    var divisor = 0;
    for( var i = 0; i < 10; i++ ) {

        divisor += Math.pow(10, i);

        var value = num / divisor;
        //printALine("num = " + num + " divisor=" + divisor + " value = " + value);
        if( value >= 10 ) {
            result += 9;
        } else {
            result += Math.floor( value );
            break;
        }

    }

    return result;

}

function main() {

    var numOfTests = parseInt(readALine());
    for( var i = 0; i < numOfTests; i++ ) {
        var num = parseInt(readALine());
        var result = doIt( num );
        printALine(result);
    }

}

'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 readALine() {
    return inputString[currentLine++];
}

function printALine(str) {
    console.log(str);
}

function stringArrayToNumbers(str) {
    var array = str.split(" ");
    var result = [];
    for( var i = 0; i < array.length; i++ ) {
        result.push( parseInt(array[i]) );
    }
    return result;
}

function stringArrayToBigInts(str) {
    var array = str.split(" ");
    var result = [];
    for( var i = 0; i < array.length; i++ ) {
        result.push( BigInt(array[i]) );
    }
    return result;
}

// ======================================================
// A. Happy Birthday, Polycarp!
// https://codeforces.com/problemset/problem/1277/A
// ======================================================

function doIt( num ) {

    var result = 0;
    if( num === 1 ) return 1;

    var divisor = 0;
    for( var i = 0; i < 10; i++ ) {

        divisor += Math.pow(10, i);

        var value = num / divisor;
        if( value > 10 ) {
            result += 9;
        } else {
            result += Math.floor( value );
            break;
        }

    }

    return result;

}

function main() {

    var numOfTests = parseInt(readALine());
    for( var i = 0; i < numOfTests; i++ ) {
        var num = parseInt(readALine());
        var result = doIt( num );
        printALine(result);
    }

}


var t = parseInt(readline());

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

    var days = 0;
    var coins = 0;
    var ans = Infinity;

    for (var i = 0; i < n; i++) {
        ans = Math.min(ans, days + Math.ceil((c - coins) / a[i]));
        var day = Math.ceil((b[i] - coins) / a[i]);
        days += day + 1;
        coins = coins + day * a[i] - b[i];
    }

    print(ans);
}

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, c] = lines[l++].split(' ').map(Number)
        var a = lines[l++].split(' ').map(Number)
        var b = lines[l++].split(' ').map(Number)
        console.log(solve(n, c, a, b))
    }
});

function solve(n, c, a, b) {
    let min = Infinity
    let cur = 0
    let days = 0
    for (let i = 0; i < n; i++) {
        const d1 = days + Math.ceil((c - cur) / a[i])
        min = Math.min(min, d1)
        if (i === n - 1) break

        // console.log(cur, days)
        const update = Math.ceil(Math.max(0, b[i] - cur) / a[i])
        days += update + 1
        cur += update * a[i] - b[i]
        // console.log('->', cur, days)
    }
    return min
}

'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 maxN = 21
var mod = 1000000007

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const xx = readline();

  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = parseInt(readline());
    var [n, c] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var b = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var ans = c
    var day = 0
    var addDays = 0
    var money = 0

    for (let j = 0; j < n; j++) {
      ans = Math.min(ans, day + Math.ceil((c - money) / a[j]))
      if (j < n - 1) {
        if (money < b[j]) {
          addDays = Math.ceil((b[j] - money) / a[j])
          day = day + addDays
          money = money + addDays * a[j]
        }
        // console.log(addDays)
        day++
        money -= b[j]
      }
      // console.log(day, money, ans)
    }

    console.log(ans)
  })
}