On the number line there are $$$m$$$ points, $$$i$$$-th of which has integer coordinate $$$x_i$$$ and integer weight $$$w_i$$$. The coordinates of all points are different, and the points are numbered from $$$1$$$ to $$$m$$$.A sequence of $$$n$$$ segments $$$[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$$$ is called system of nested segments if for each pair $$$i, j$$$ ($$$1 \le i < j \le n$$$) the condition $$$l_i < l_j < r_j < r_i$$$ is satisfied. In other words, the second segment is strictly inside the first one, the third segment is strictly inside the second one, and so on.For a given number $$$n$$$, find a system of nested segments such that:  both ends of each segment are one of $$$m$$$ given points;  the sum of the weights $$$2\cdot n$$$ of the points used as ends of the segments is minimal. For example, let $$$m = 8$$$. The given points are marked in the picture, their weights are marked in red, their coordinates are marked in blue. Make a system of three nested segments:  weight of the first segment: $$$1 + 1 = 2$$$  weight of the second segment: $$$10 + (-1) = 9$$$  weight of the third segment: $$$3 + (-2) = 1$$$  sum of the weights of all the segments in the system: $$$2 + 9 + 1 = 12$$$     System of three nested segments

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of input test cases. An empty line is written before each test case. The first line of each test case contains two positive integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$m$$$ ($$$2 \cdot n \le m \le 2 \cdot 10^5$$$).  The next $$$m$$$ lines contain pairs of integers $$$x_i$$$ ($$$-10^9 \le x_i \le 10^9$$$) and $$$w_i$$$ ($$$-10^4 \le w_i \le 10^4$$$) — coordinate and weight of point number $$$i$$$ ($$$1 \le i \le m$$$) respectively. All $$$x_i$$$ are different. It is guaranteed that the sum of $$$m$$$ values over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output $$$n + 1$$$ lines: in the first of them, output the weight of the composed system, and in the next $$$n$$$ lines output exactly two numbers  — the indices of the points which are the endpoints of the $$$i$$$-th segment ($$$1 \le i \le n$$$). The order in which you output the endpoints of a segment is not important — you can output the index of the left endpoint first and then the number of the right endpoint, or the other way around. If there are several ways to make a system of nested segments with minimal weight, output any of them.

NoteThe first test case coincides with the example from the condition. It can be shown that the weight of the composed system is minimal.The second test case has only $$$6$$$ points, so you need to use each of them to compose $$$3$$$ segments.

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		let points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push({pos: x, wt: w, id: i+1})
		}

		points.sort((x, y) => x.wt - y.wt);
		points = points.slice(0, 2*n);
		points.sort((x, y) => x.pos - y.pos);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i].wt;
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i].id, points[2*n-i-1].id);
		}
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		let points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push([x, w, i+1]);
		}

		points.sort((x, y) => x[1] - y[1]);
		points = points.slice(0, 2*n);

		points.sort((x, y) => x[0] - y[0]);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i][1];
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i][2], points[2*n-i-1][2]);
		}
	}
}

function solve() {
    read();
   var [n, m] = readArray(Number);
   var arr = [];
   for (var i = 0; i < m; i++) {
      var [x, w] = readArray(Number);
      arr.push({
         x,
         w,
         i: i + 1
      });
   }
   arr.sort(f1);
   arr = arr.slice(0, 2 * n);
   arr.sort(f2);
   var sum = 0;
   var ans = [];
   for (var i = 0; i < n; i++) {
      sum += arr[i].w;
      ans.push([arr[i].i]);
   }
   for (var i = 0; i < n; i++) {
      sum += arr[2 * n - i - 1].w;
      ans[i].push(arr[2 * n - i - 1].i);
   }
   write(sum);
   for (var i = 0; i < n; i++) {
      write(ans[i].join(' '));
   }
   write('');
}

function f1(a, b) {
    return a.w - b.w;
}
function f2(a, b) {
    return a.x - b.x;
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    ANS = '';
    MEMORY_INDEX = 0;
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

function solve() {
    read();
   const [n, m] = readArray(Number);
   let arr = [];
   for (let i = 0; i < m; i++) {
      const [x, w] = readArray(Number);
      arr.push({
         x,
         w,
         i: i + 1
      });
   }
   arr.sort((a, b) => a.w - b.w);
   arr = arr.slice(0, 2 * n);
   arr.sort((a, b) => a.x - b.x);
   let sum = 0;
   const ans = [];
   for (let i = 0; i < n; i++) {
      sum += arr[i].w;
      ans.push([arr[i].i]);
   }
   for (let i = 0; i < n; i++) {
      sum += arr[2 * n - i - 1].w;
      ans[i].push(arr[2 * n - i - 1].i);
   }
   write(sum);
   for (let i = 0; i < n; i++) {
      write(ans[i].join(' '));
   }
   write('');
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    ANS = '';
    MEMORY_INDEX = 0;
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

function solve() {
   read();
   const [n, m] = readArray(Number);
   let arr = [];
   for (let i = 0; i < m; i++) {
      const [x, w] = readArray(Number);
      arr.push({
         x,
         w,
         i: i + 1
      });
   }
   arr.sort((a, b) => a.w - b.w);
   arr = arr.slice(0, 2 * n);
   arr.sort((a, b) => a.x - b.x);
   let sum = 0;
   const ans = [];
   for (let i = 0; i < n; i++) {
      sum += arr[i].w;
      ans.push([arr[i].i]);
   }
   for (let i = 0; i < n; i++) {
      sum += arr[2 * n - i - 1].w;
      ans[i].push(arr[2 * n - i - 1].i);
   }
   write(sum);
   for (let i = 0; i < n; i++) {
      write(ans[i].join(' '));
   }
   write('');
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

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

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

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

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

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

const readline = require('readline')

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

function solve(n, m, arr) {
    arr = arr
        // .sort((a, b) => a[0] - b[0])
        .map(([x, w], i) => ({ x, w, i: i + 1}))
        .sort((a, b) => a.w - b.w)
    let ans = 0
    const xs = Array(2 * n)
    for (let i = 0; i < 2 * n; i++) {
        ans += arr[i].w
        xs[i] = arr[i]
    }
    xs.sort((a, b) => a.x - b.x)
    const pairs = Array(n)
    for (let i = 0; i < n; i++) {
        pairs[i] = xs[i].i + ' ' + xs[2 * n - 1 - i].i
    }
    return ans + '\n' + pairs.join('\n')
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    readline();
    let [n, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = [];
    for (let i = 0; i < m; i++) {
      arr.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    for (let i = 0; i < m; i++) {
      let obj = { val: arr[i][0], w: arr[i][1], ind: i };
      arr[i] = obj;
    }
    arr.sort((a,b)=>a.w - b.w);
    let narr = [],total = 0;
    for(let i=0;i<n*2;i++) {
      narr.push(arr[i]);
      total+=arr[i].w;
    }
    narr.sort((a,b)=>a.val - b.val);
    console.log(total);
    let i=0,j = n*2 - 1;
    while(i<n) console.log(`${narr[i++].ind + 1} ${narr[j--].ind + 1}`);

  }
};
solve();

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

module.exports = E;

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

const EPS = 1e-6;

const calc = (n, m, arr)=>{
  arr = arr.map((a, i)=>({w: a[1], x: a[0], i})).sort((a, b)=>a.w-b.w)
  //console.log(n, m, arr)
  let slice = arr.slice(0, 2*n);
  slice.sort((a, b)=>a.x-b.x);
  let ans_arr = [];
  let ans_sum = 0;
  for (let i=0; i<n; i++){
    let beg = slice[i];
    let end = slice[n*2-i-1];
    ans_arr.push((beg.i+1)+' '+(end.i+1));
    ans_sum += beg.w + end.w
  }
  print(ans_sum);
  print(ans_arr.join('\n'));
  print('');

};

function main() {
    let T = +readline()
    while (T--){
      readline()
      let [n, m] = ra();
      let arr = [];
      for (let i=0; i<m; i++)
        arr.push(ra());
      calc(n, m, arr);
    }
}

E.calc = calc;

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		const points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push([w, i+1]);
		}

		points.sort((x, y) => x[0] - y[0]);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i][0];
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i][1], points[2*n-i-1][1]);
		}
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		const points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push([x, w]);
		}

		points.sort((x, y) => x[1] - y[1]);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i][0];
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i][0], points[2*n-i-1][0]);
		}
	}
}

const readline = require('readline')

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

function solve(n, m, arr) {
    arr = arr
        // .sort((a, b) => a[0] - b[0])
        .map(([x, w], i) => ({ x, w, i: i + 1}))
        .sort((a, b) => a.w - b.w)
    let ans = 0
    const xs = Array(2 * n)
    for (let i = 0; i < 2 * n; i++) {
        ans += arr[i].w
        xs[i] = arr[i].i
    }
    xs.sort((a, b) => a - b)
    const pairs = Array(n)
    for (let i = 0; i < n; i++) {
        pairs[i] = xs[i] + ' ' + xs[2 * n - 1 - i]
    }
    return ans + '\n' + pairs.join('\n')
}

const readline = require('readline')

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

function solve(n, m, arr) {
    arr = arr
        .sort((a, b) => a[0] - b[0])
        .map(([x, w], i) => ({ x, w, i: i + 1}))
        .sort((a, b) => a.w - b.w)
    let ans = 0
    const xs = Array(2 * n)
    for (let i = 0; i < 2 * n; i++) {
        ans += arr[i].w
        xs[i] = arr[i].i
    }
    xs.sort((a, b) => a - b)
    const pairs = Array(n)
    for (let i = 0; i < n; i++) {
        pairs[i] = xs[i] + ' ' + xs[2 * n - 1 - i]
    }
    return ans + '\n' + pairs.join('\n')
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    readline();
    let [n, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = [];
    for (let i = 0; i < m; i++) {
      arr.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    for (let i = 0; i < m; i++) {
      let obj = { val: arr[i][0], w: arr[i][1], ind: i };
      arr[i] = obj;
    }
    arr.sort((a, b) => a.val - b.val);
    const r = (start, i, j) => {
      let s1 = 0,
        s = [],
        cnt = 0;
      while (i <= start) {
        if (cnt < n) s1 += arr[i].w;
        else {
          let obj = { w: s1, s: j, e: i - 1 };
          s.push(obj);
          if (i < start) s1 = s1 - arr[j].w + arr[i].w;
          j++;
        }
        i++;
        cnt++;
      }
      return s;
    };
    let s1 = r(m - n, 0, 0);
    let s2 = r(m, n, n);
    let minarr = [];
    let min = s2.length - 1;
    for (let i = s2.length - 1; i >= 0; i--) {
      if (s2[min].w >= s2[i].w) min = i;
      minarr[i] = min;
    }
    let minx = Infinity,
      obj1 = {};
    for (let i = 0; i < s1.length; i++) {
      let k = s1[i].w + s2[minarr[i]].w;
      if (k < minx) {
        obj1 = { v1: s1[i], v2: s2[minarr[i]] };
        minx = k;
      }
    }
    console.log(obj1.v1.w + obj1.v2.w);
    let st1 = obj1.v1.s,
      st2 = obj1.v2.e,
      i = 0;
    while (i < n) {
      console.log(`${arr[st1].ind + 1} ${arr[st2].ind + 1}`);
      st1++;
      st2--;
      i++;
    }
  }
};
solve();


Mike and Joe are playing a game with some stones. Specifically, they have $$$n$$$ piles of stones of sizes $$$a_1, a_2, \ldots, a_n$$$. These piles are arranged in a circle.The game goes as follows. Players take turns removing some positive number of stones from a pile in clockwise order starting from pile $$$1$$$. Formally, if a player removed stones from pile $$$i$$$ on a turn, the other player removes stones from pile $$$((i\bmod n) + 1)$$$ on the next turn.If a player cannot remove any stones on their turn (because the pile is empty), they lose. Mike goes first.If Mike and Joe play optimally, who will win?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$)  — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)  — the size of the piles.

For each test case print the winner of the game, either "Mike" or "Joe" on its own line (without quotes).

NoteIn the first test case, Mike just takes all $$$37$$$ stones on his first turn.In the second test case, Joe can just copy Mike's moves every time. Since Mike went first, he will hit $$$0$$$ on the first pile one move before Joe does so on the second pile.

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

/***
Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round
2022-06-18

B. Circle Game
***/

function main() {
  const t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    const n = parseInt(readline());
    let start = readline();
    start = start.split(" ");
    start = start.map((k) => parseInt(k));

    if (n % 2 == 1) {
      // If n is odd then Mike wins because he can always take the
      // first pile so Joe loses when we loop round.
      console.log("Mike");
    } else {
      let mikeSmallest = 1e10;
      let mikeSmallestLoc;
      let joeSmallest = 1e10;
      let joeSmallestLoc;
      // If n is even, each player wants to conserve their own
      // stones, so they will always take a single stone at a time.
      // So the loser is the one with the smallest pile (first to
      // come across it if tied).
      for (let pile = 0; pile < n; pile += 2) {
        if (start[pile] < mikeSmallest) {
          mikeSmallest = start[pile];
          mikeSmallestLoc = pile;
        }
      }

      for (let pile = 1; pile < n; pile += 2) {
        if (start[pile] < joeSmallest) {
          joeSmallest = start[pile];
          joeSmallestLoc = pile;
        }
      }

      if (mikeSmallest < joeSmallest) {
        console.log("Joe");
      } else if (mikeSmallest > joeSmallest) {
        console.log("Mike");
      } else {
        console.log(mikeSmallestLoc < joeSmallestLoc ? "Joe" : "Mike");
      }
    }
  }
}

'use strict';

function solve(n, a) {
  if (n & 1) return 'Mike';
  let min = Math.min(...a);
  for (let i = 0; i < n; i++) {
    if (a[i] === min) {
      return i & 1 ? 'Mike' : 'Joe';
    }
  }
}

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

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

'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 output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        let piles = parseInt(readline(), 10);
        let sizes = readline().split(' ').map(Number);
        if (piles % 2 === 1) {
            output('Mike');
            continue;
        }

        let mike = Infinity;
        let joe = Infinity;
        for (let j = 0; j < piles; j++) {
            if (j % 2 === 0 && sizes[j] < mike) {
                mike = sizes[j];
            }
            if (j % 2 === 1 && sizes[j] < joe) {
                joe = sizes[j];
            }
        }

        if (mike === joe) {
            const firstMaxIndex = sizes.findIndex(l => l === mike);
            if (firstMaxIndex % 2 === 0) {
                output('Joe');
            } else {
                output('Mike');
            }
            continue;
        }

        output(mike > joe ? 'Mike' : 'Joe');
    }
}

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

/***
Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round
2022-06-18

B. Circle Game
***/

function main() {
  const t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    const n = parseInt(readline());
    let start = readline();
    start = start.split(" ");
    start = start.map((k) => parseInt(k));

    if (n % 2 == 1) {
      // If n is odd then Mike wins because he can always take the
      // first pile so Joe loses when we loop round.
      console.log("Mike");
    } else {
      let mikeSmallest = 1e10;
      let joeSmallest = 1e10;
      // If n is even, each player wants to conserve their own
      // stones, so they will always take a single stone at a time.
      // So the loser is the one with the smallest pile (Mike if
      // tied).
      for (let pile = 0; pile < n; pile += 2) {
        if (start[pile] < mikeSmallest) {
          mikeSmallest = start[pile];
        }
      }

      for (let pile = 1; pile < n; pile += 2) {
        if (start[pile] < joeSmallest) {
          joeSmallest = start[pile];
        }
      }

      if (mikeSmallest < joeSmallest) {
        console.log("Mike");
      } else {
        console.log("Joe");
      }
    }
  }
}

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

/***
Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round
2022-06-18

B. Circle Game
***/

function main() {
  const t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    const n = parseInt(readline());
    let start = readline();
    start = start.split(" ");
    start = start.map((k) => parseInt(k));

    if (n % 2 == 1) {
      // If n is odd then Mike wins because he can always take the
      // first pile so Joe loses when we loop round.
      console.log("Mike");
    } else {
      let mikeSmallest = 1e10;
      let joeSmallest = 1e10;
      // If n is even, each player wants to conserve their own
      // stones, so they will always take a single stone at a time.
      // So the loser is the one with the smallest pile (Mike if
      // tied).
      for (let pile = 0; pile < n; pile += 2) {
        if (start[pile] < mikeSmallest) {
          mikeSmallest = start[pile];
        }
      }

      for (let pile = 1; pile < n; pile += 2) {
        if (start[pile] < joeSmallest) {
          joeSmallest = start[pile];
        }
      }

      if (mikeSmallest <= joeSmallest) {
        console.log("Joe");
      } else {
        console.log("Mike");
      }
    }
  }
}

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

/***
Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round
2022-06-18

B. Circle Game
***/

function main() {
  const t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    const n = parseInt(readline());
    readline();
    // Strategy: The optimal move is always to remove all the stones
    // so the opponent can't play there next time and loses.
    console.log(n % 2 == 0 ? "Joe" : "Mike");
  }
}

'use strict';

function solve(n, a) {
  const res = a.reduce((a, b) => a ^ b, 0);
  return res > 0 ? 'Mike' : 'Joe';
}

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

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

'use strict';

function solve(n, a) {
  const res = a.reduce((a, b) => a ^ b, 0);
  return res & 1 ? 'Mike' : 'Joe';
}

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

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

'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 output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        let piles = parseInt(readline(), 10);
        let sizes = readline().split(' ').map(Number);
        if (piles % 2 === 1) {
            output('Mike');
            continue;
        }

        let mike = Infinity;
        let joe = Infinity;
        for (let j = 0; j < piles; j++) {
            if (j % 2 === 0 && sizes[j] < mike) {
                mike = sizes[j];
            }
            if (j % 2 === 1 && sizes[j] < joe) {
                joe = sizes[j];
            }
        }

        output(mike > joe ? 'Mike' : 'Joe');
    }
}

'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 output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        let piles = readline();
        readline(); // stones array

        output(piles % 2 === 1 ? 'Mike' : 'Joe');
    }
}


Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.Unfortunately, there only are k tables in the restaurant. For each table, we know ri — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≤ ci, pi ≤ 1000) — the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≤ k ≤ 1000) — the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≤ ri ≤ 1000) — the maximum number of people that can sit at each table.

In the first line print two integers: m, s — the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them.

print(function(n){
	var n = +readline();
	var ans = [];
	var a = [];
	for(var i=0; i<n; i++){
		var x = rn();
		x.push(i+1);
		a.push(x);
	}
	a.sort(function(a, b){
		if(a[1]===b[1]) return b[0]-a[0];
		return b[1]-a[1];
	});

	var k = +readline();
	var r = rn();
	r = r.map(function(v, i){
		return [v, i+1, true];
	});
	r.sort(function(a, b){ return a[0]-b[0];});
	var sum = 0;
	for(var i=0; i<n; i++){
		for(var j=0; j<k; j++){
			if(r[j][2] && r[j][0]>=a[i][0]){
				r[j][2] = false;
				ans.push(a[i][2]+' '+r[j][1]);
				sum += a[i][1];
				break;
			}
		}
	}
	if(ans.length==0) return ans.length+' '+sum;
	return ans.length+' '+sum+'\n'+ans.join('\n');
}());
function rn() { return readline().split(' ').map(Number); }

print(function(n) {
     var n=+readline();
     var ans=[];
     var a=[];
     for(var i=0; i<n; ++i) {
          var x=rn();
          x.push(i+1);
          a.push(x);
     }
     a.sort(function(a, b) {
          if(a[1]===b[1]) return b[0]-a[0];
          return b[1]-a[1];
     });
     var k= +readline();
     var r=rn();
     r=r.map(function(v, i) {
          return [v, i+1, true];
     });
     r.sort(function(a, b) {return a[0]-b[0];});
     var sum=0;
     for(var i=0; i<n; ++i) {
          for(var j=0; j<k; ++j) {
               if(r[j][2]&&r[j][0]>=a[i][0]) {
                    r[j][2]=false;
                    ans.push(a[i][2]+ ' '+r[j][1]);
                    sum+=a[i][1];
                    break;
               }
          }
     }
     if(ans.length==0) return ans.length+' '+sum;
     return ans.length+ ' ' + sum + '\n' + ans.join('\n');
}());
function rn() {
     return readline().split(' ').map(Number);
}

print(function() {
     var n=+readline();
     var ans=[];
     var a=[];
     for(var i=0; i<n; ++i) {
          var x=rn();
          x.push(i+1);
          a.push(x);
     }
     a.sort(function(a, b) {
          if(a[1]===b[1]) return b[0]-a[0];
          return b[1]-a[1];
     });
     var k= +readline();
     var r=rn();
     r=r.map(function(v, i) {
          return [v, i+1, true];
     });
     r.sort(function(a, b) {return a[0]-b[0];});
     var sum=0;
     for(var i=0; i<n; ++i) {
          for(var j=0; j<k; ++j) {
               if(r[j][2]&&r[j][0]>=a[i][0]) {
                    r[j][2]=false;
                    ans.push(a[i][2]+ ' '+r[j][1]);
                    sum+=a[i][1];
                    break;
               }
          }
     }
     if(ans.length==0) return ans.length+' '+sum;
     return ans.length+ ' ' + sum + '\n' + ans.join('\n');
}());
function rn() {
     return readline().split(' ').map(Number);
}

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a,b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k=+readline();
    var r=rn();
    r=r.map(function(v, i) {
        return [v,i+1,true];
    });
    r.sort(function(a, b) {return a[0]-b[0];});
    var sum=0;
     for(var i=0; i<n; ++i) {
          for(var j=0; j<k; ++j) {
               if(r[j][2]&&r[j][0]>=a[i][0]) {
                    r[j][2]=false;
                    ans.push(a[i][2]+ ' '+r[j][1]);
                    sum+=a[i][1];
                    break;
               }
          }
     }
    if(ans.length==0) return ans.length+' '+sum;
    return ans.length+' '+sum+'\n' +ans.join('\n');
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a,b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k=+readline();
    var r=rn();
    r=r.map(function(v, i) {
        return [v,i+1,true];
    });
    r.sort(function(a, b) {return a[0]-b[0];});
    var sum=0;
    for(var i=0; i<n; ++i) {
        for(var j=0; j<k; ++j) {
            if(r[j][2]&&r[j][0]>=a[i][0]) {
                r[j][2]=false;
                ans.push(a[i][2]+ ' ' + r[j][1]);
                sum+=a[i][1];
                break;
            }
        }
    }
    if(ans.length==0) return ans.length+' '+sum;
    return ans.length+' '+sum+'\n' +ans.join('\n');
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a, b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k= +readline();
    var r=rn();
    r=r.map(function(v, i) {
        return [v, i+1, true];
    });
    r.sort(function(a, b) {return a[0]-b[0];});
    var sum=0;
for(var i=0; i<n; i++){
        for(var j=0; j<k; j++){
            if(r[j][2] && r[j][0]>=a[i][0]){
                r[j][2] = false;
                ans.push(a[i][2]+' '+r[j][1]);
                sum += a[i][1];
                break;
            }
        }
    }
    if(ans.length==0) return ans.length+' '+sum;
    return ans.length+ ' ' + sum + '\n' + ans.join('\n');
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a,b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k=+readline();
    var r=rn();
    r=r.map(function(v, i) {
        return [v,i+1,true];
    });
    r.sort(function(a, b) {return a[0]-b[0];});
     var sum=0;
     for(var i=0; i<n; ++i) {
          for(var j=0; j<k; ++j) {
               if(r[j][2]&&r[j][0]>=a[i][0]) {
                    r[j][2]=false;
                    ans.push(a[i][2]+ ' '+r[j][1]);
                    sum+=a[i][1];
                    break;
               }
          }
     }
     if(ans.length==0) return ans.length+' '+sum;
     return ans.length+ ' ' + sum + '\n' + ans.join('\n');
}());
function rn() {
     return readline().split(' ').map(Number);
}

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a, b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k = +readline();
    var r = rn();
    r = r.map(function(v, i){
        return [v, i+1, true];
    });
    r.sort(function(a, b){ return a[0]-b[0];});
    var sum = 0;
    for(var i=0; i<n; i++){
        for(var j=0; j<k; j++){
            if(r[j][2] && r[j][0]>=a[i][0]){
                r[j][2] = false;
                ans.push(a[i][2]+' '+r[j][1]);
                sum += a[i][1];
                break;
            }
        }
    }
    if(ans.length==0) return ans.length+' '+sum;
    return ans.length+' '+sum+'\n'+ans.join('\n');
}());
function rn() { return readline().split(' ').map(Number); }

// Generated by CoffeeScript 1.7.1
(function() {
  var find, found, i, m, money, n, people, request, requests, seat, seats, tables, totalMoney, _i, _j, _k, _len, _len1, _ref;

  n = Number(readline());

  requests = [];

  for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {
    _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];
    requests.push({
      people: people,
      money: money,
      number: i
    });
  }

  m = Number(readline());

  tables = readline().split(' ').map(function(x, i) {
    return {
      size: Number(x),
      number: i + 1,
      taken: false
    };
  });

  requests.sort(function(a, b) {
    if (a.money > b.money) {
      return -1;
    } else {
      return 1;
    }
  });

  tables.sort(function(a, b) {
    if (a.size > b.size) {
      return 1;
    } else {
      return -1;
    }
  });

  find = function(array, el, a, b) {
    var c, _ref1, _ref2;
    if (a == null) {
      a = 0;
    }
    if (b == null) {
      b = array.length - 1;
    }
    if (a === b) {
      while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {
        a++;
      }
      if (a >= array.length) {
        return null;
      }
      if (array[a].size >= el) {
        array[a].taken = true;
        return array[a];
      }
    } else {
      if (el <= array[c = Math.floor((a + b) / 2)].size) {
        return find(array, el, a, c);
      } else if (el >= array[c = Math.ceil((a + b) / 2)].size) {
        return find(array, el, c, b);
      } else {
        while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {
          c++;
        }
        if (c >= array.length) {
          return null;
        }
        array[c].taken = true;
        return array[c];
      }
    }
  };

  seats = [];

  totalMoney = 0;

  for (_j = 0, _len = requests.length; _j < _len; _j++) {
    request = requests[_j];
    found = find(tables, request.people);
    if (found != null) {
      seats.push({
        table: found.number,
        request: request.number
      });
      totalMoney += request.money;
    }
  }

  print(seats.length + ' ' + totalMoney);

  for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {
    seat = seats[_k];
    print(seat.request + ' ' + seat.table);
  }

}).call(this);

print(function(n){
	var n = +readline();
	var ans = [];
	var a = [];
	for(var i=0; i<n; i++){
		var x = rn();
		x.push(i+1);
		a.push(x);
	}
	a.sort(function(a, b){return a[1]<b[1];});

	var k = +readline();
	var r = rn();
	r = r.map(function(v, i){
		return [v, i+1, true];
	});
	r.sort(function(a, b){ return a[0]>b[0];});
	var sum = 0;
	for(var i=0; i<n; i++){
		for(var j=0; j<k; j++){
			if(r[j][2] && r[j][0]>=a[i][0]){
				r[j][2] = false;
				ans.push(a[i][2]+' '+r[j][1]);
				sum += a[i][1];
				break;
			}
		}
	}
	if(ans.length==0) return ans.length+' '+sum;
	return ans.length+' '+sum+'\n'+ans.join('\n');
}());
function rn() { return readline().split(' ').map(Number); }

print(function(n){
	var n = +readline();
	var ans = [];
	var a = [];
	for(var i=0; i<n; i++){
		var x = rn();
		x.push(i+1);
		a.push(x);
	}
	a.sort(function(a, b){return a[1]<b[1];});

	var k = +readline();
	var r = rn();
	r = r.map(function(v, i){
		return [v, i+1, true];
	});
	r.sort(function(a, b){ return a[0]>b[0];});
	var sum = 0;
	for(var i=0; i<n; i++){
		for(var j=0; j<k; j++){
			if(r[j][2] && r[j][0]>=a[i][0]){
				r[j][2] = false;
				ans.push(a[i][2]+' '+r[j][1]);
				sum += a[i][1];
				break;
			}
		}
	}
	return ans.length+' '+sum+'\n'+ans.join('\n');
}());
function rn() { return readline().split(' ').map(Number); }

print(function(n){
	var n = +readline();
	var ans = [];
	var a = [];
	for(var i=0; i<n; i++){
		var x = rn();
		x.push(i+1);
		a.push(x);
	}
	a.sort(function(a, b){return a[0]<b[0];});

	var k = +readline();
	var r = rn();
	r = r.map(function(v, i){
		return [v, i+1, true];
	});
	r.sort(function(a, b){ return a[0]>b[0];});
	var sum = 0;
	for(var i=0; i<n; i++){
		for(var j=0; j<k; j++){
			if(r[j][2] && r[j][0]>=a[i][0]){
				r[j][2] = false;
				ans.push(a[i][2]+' '+r[j][1]);
				sum += a[i][1];
				break;
			}
		}
	}
	if(ans.length==0) return ans.length+' '+sum;
	return ans.length+' '+sum+'\n'+ans.join('\n');
}());
function rn() { return readline().split(' ').map(Number); }

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a,b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k=+readline();
    var r=rn();
    r=r.map(function(v, i) {
        return [v,i+1,true];
    });
    r.sort(function(a, b) {return a[0]-b[0];});
    var sum=0;
    for(var i=0; i<n; ++i) {
        for(var j=0; j<k; ++j) {
            if(r[j][2]&&r[j][0]>=a[i][0]) {
                r[j][2]=false;
                ans.push(a[j][2]+ ' ' + r[j][1]);
                sum+=a[i][1];
                break;
            }
        }
    }
    if(ans.length==0) return ans.length+' '+sum;
    return ans.length+' '+sum+'\n' +ans.join('\n');
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function(n) {
    var n=+readline();
    var ans=[];
    var a=[];
    for(var i=0; i<n; ++i) {
        var x=rn();
        x.push(i+1);
        a.push(x);
    }
    a.sort(function(a, b) {
        if(a[1]===b[1]) return b[0]-a[0];
        return b[1]-a[1];
    });
    var k= +readline();
    var r=rn();
    r=r.map(function(v, i) {
        return [v, i+1, true];
    });
    r.sort(function(a, b) {return a[0]-b[0];});
    var sum=0;
    for(var i=0; i<n; ++i) {
        for(var j=0; j<k; ++j) {
            if(r[j][2]&&r[j][0]>=a[i][0]) {
                r[j][2]=true;
                ans.push(a[i][2]+ ' '+r[j][1]);
                sum+=a[i][1];
                break;
            }
        }
    }
    if(ans.length==0) return ans.length+' '+sum;
    return ans.length+ ' ' + sum + '\n' + ans.join('\n');
}());
function rn() {
    return readline().split(' ').map(Number);
}

// Generated by CoffeeScript 1.7.1
(function() {
  var find, found, i, m, money, n, people, request, requests, seat, seats, tables, test_array, totalMoney, _i, _j, _k, _len, _len1, _ref;

  n = Number(readline());

  requests = [];

  for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {
    _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];
    requests.push({
      people: people,
      money: money,
      number: i
    });
  }

  m = Number(readline());

  tables = readline().split(' ').map(function(x, i) {
    return {
      size: Number(x),
      number: i + 1,
      taken: false
    };
  });

  requests.sort(function(a, b) {
    if (a.money > b.money) {
      return -1;
    } else {
      return 1;
    }
  });

  tables.sort(function(a, b) {
    if (a.size > b.size) {
      return 1;
    } else {
      return -1;
    }
  });

  find = function(array, el, a, b) {
    var c, _ref1, _ref2;
    if (a == null) {
      a = 0;
    }
    if (b == null) {
      b = array.length - 1;
    }
    if (a === b) {
      while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {
        a--;
      }
      if (a < 0) {
        return null;
      }
      array[a].taken = true;
      if (array[a].size > el) {
        return array[0];
      }
    } else {
      if (el < array[c = Math.floor((a + b) / 2)].size) {
        return find(array, el, a, c);
      } else if (el > array[c = Math.ceil((a + b) / 2)].size) {
        return find(array, el, c, b);
      } else {
        while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {
          c--;
        }
        if (c < 0) {
          return null;
        }
        array[c].taken = true;
        return array[c];
      }
    }
  };

  test_array = (function() {
    var _j, _results;
    _results = [];
    for (i = _j = 1; _j <= 100; i = _j += 5) {
      _results.push({
        size: i,
        number: i
      });
    }
    return _results;
  })();

  seats = [];

  totalMoney = 0;

  for (_j = 0, _len = requests.length; _j < _len; _j++) {
    request = requests[_j];
    found = find(tables, request.people);
    if (found != null) {
      seats.push({
        table: found.number,
        request: request.number
      });
      totalMoney += request.money;
    }
  }

  print(seats.length + ' ' + totalMoney);

  for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {
    seat = seats[_k];
    print(seat.request + ' ' + seat.table);
  }

}).call(this);

// Generated by CoffeeScript 1.7.1
(function() {
  var find, found, i, m, money, n, people, request, requests, seat, seats, tables, test_array, totalMoney, _i, _j, _k, _len, _len1, _ref;

  n = Number(readline());

  requests = [];

  for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {
    _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];
    requests.push({
      people: people,
      money: money,
      number: i
    });
  }

  m = Number(readline());

  tables = readline().split(' ').map(function(x, i) {
    return {
      size: Number(x),
      number: i + 1,
      taken: false
    };
  });

  requests.sort(function(a, b) {
    if (a.money > b.money) {
      return -1;
    } else {
      return 1;
    }
  });

  tables.sort(function(a, b) {
    if (a.size > b.size) {
      return 1;
    } else {
      return -1;
    }
  });

  find = function(array, el, a, b) {
    var c, _ref1, _ref2;
    if (a == null) {
      a = 0;
    }
    if (b == null) {
      b = array.length - 1;
    }
    if (a === b) {
      while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {
        a--;
      }
      if (a < 0) {
        return null;
      }
      array[a].taken = true;
      if (array[a].size >= el) {
        return array[0];
      }
    } else {
      if (el < array[c = Math.floor((a + b) / 2)].size) {
        return find(array, el, a, c);
      } else if (el > array[c = Math.ceil((a + b) / 2)].size) {
        return find(array, el, c, b);
      } else {
        while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {
          c--;
        }
        if (c < 0) {
          return null;
        }
        array[c].taken = true;
        return array[c];
      }
    }
  };

  test_array = (function() {
    var _j, _results;
    _results = [];
    for (i = _j = 1; _j <= 100; i = _j += 5) {
      _results.push({
        size: i,
        number: i
      });
    }
    return _results;
  })();

  seats = [];

  totalMoney = 0;

  for (_j = 0, _len = requests.length; _j < _len; _j++) {
    request = requests[_j];
    found = find(tables, request.people);
    if (found != null) {
      seats.push({
        table: found.number,
        request: request.number
      });
      totalMoney += request.money;
    }
  }

  print(seats.length + ' ' + totalMoney);

  for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {
    seat = seats[_k];
    print(seat.request + ' ' + seat.table);
  }

}).call(this);

// Generated by CoffeeScript 1.7.1
(function() {
  var find, found, i, m, money, n, people, request, requests, seat, seats, tables, totalMoney, _i, _j, _k, _len, _len1, _ref;

  n = Number(readline());

  requests = [];

  for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {
    _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];
    requests.push({
      people: people,
      money: money,
      number: i
    });
  }

  m = Number(readline());

  tables = readline().split(' ').map(function(x, i) {
    return {
      size: Number(x),
      number: i + 1,
      taken: false
    };
  });

  requests.sort(function(a, b) {
    if (a.money > b.money) {
      return -1;
    } else {
      return 1;
    }
  });

  tables.sort(function(a, b) {
    if (a.size > b.size) {
      return 1;
    } else {
      return -1;
    }
  });

  find = function(array, el, a, b) {
    var c, _ref1, _ref2;
    if (a == null) {
      a = 0;
    }
    if (b == null) {
      b = array.length - 1;
    }
    if (a === b) {
      while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {
        a++;
      }
      if (a >= array.length) {
        return null;
      }
      if (array[a].size >= el) {
        array[a].taken = true;
        return array[a];
      }
    } else {
      if (el >= array[c = Math.ceil((a + b) / 2)].size) {
        return find(array, el, c, b);
      } else if (el <= array[c = Math.floor((a + b) / 2)].size) {
        return find(array, el, a, c);
      } else {
        while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {
          c++;
        }
        if (c >= array.length) {
          return null;
        }
        array[c].taken = true;
        return array[c];
      }
    }
  };

  seats = [];

  totalMoney = 0;

  for (_j = 0, _len = requests.length; _j < _len; _j++) {
    request = requests[_j];
    found = find(tables, request.people);
    if (found != null) {
      seats.push({
        table: found.number,
        request: request.number
      });
      totalMoney += request.money;
    }
  }

  print(seats.length + ' ' + totalMoney);

  for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {
    seat = seats[_k];
    print(seat.request + ' ' + seat.table);
  }

}).call(this);

// Generated by CoffeeScript 1.7.1
(function() {
  var find, found, i, m, money, n, people, request, requests, seat, seats, tables, totalMoney, _i, _j, _k, _len, _len1, _ref;

  n = Number(readline());

  requests = [];

  for (i = _i = 1; 1 <= n ? _i <= n : _i >= n; i = 1 <= n ? ++_i : --_i) {
    _ref = readline().split(' ').map(Number), people = _ref[0], money = _ref[1];
    requests.push({
      people: people,
      money: money,
      number: i
    });
  }

  m = Number(readline());

  tables = readline().split(' ').map(function(x, i) {
    return {
      size: Number(x),
      number: i + 1,
      taken: false
    };
  });

  requests.sort(function(a, b) {
    if (a.money > b.money) {
      return -1;
    } else {
      return 1;
    }
  });

  tables.sort(function(a, b) {
    if (a.size > b.size) {
      return 1;
    } else {
      return -1;
    }
  });

  find = function(array, el, a, b) {
    var c, _ref1, _ref2;
    if (a == null) {
      a = 0;
    }
    if (b == null) {
      b = array.length - 1;
    }
    if (a === b) {
      while ((_ref1 = array[a]) != null ? _ref1.taken : void 0) {
        a--;
      }
      if (a < 0) {
        return null;
      }
      if (array[a].size >= el) {
        array[a].taken = true;
        return array[0];
      }
    } else {
      if (el <= array[c = Math.floor((a + b) / 2)].size) {
        return find(array, el, a, c);
      } else if (el >= array[c = Math.ceil((a + b) / 2)].size) {
        return find(array, el, c, b);
      } else {
        while ((_ref2 = array[c]) != null ? _ref2.taken : void 0) {
          c--;
        }
        if (c < 0) {
          return null;
        }
        array[c].taken = true;
        return array[c];
      }
    }
  };

  seats = [];

  totalMoney = 0;

  for (_j = 0, _len = requests.length; _j < _len; _j++) {
    request = requests[_j];
    found = find(tables, request.people);
    if (found != null) {
      seats.push({
        table: found.number,
        request: request.number
      });
      totalMoney += request.money;
    }
  }

  print(seats.length + ' ' + totalMoney);

  for (_k = 0, _len1 = seats.length; _k < _len1; _k++) {
    seat = seats[_k];
    print(seat.request + ' ' + seat.table);
  }

}).call(this);


A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.Let's try to make a new task. Firstly we will use the following task. There are n people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are n people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation p?More formally, if we denote the handle of the i-th person as hi, then the following condition must hold: .

The first line contains an integer n (1 ≤ n ≤ 105) — the number of people. The next n lines each contains two strings. The i-th line contains strings fi and si (1 ≤ |fi|, |si| ≤ 50) — the first name and last name of the i-th person. Each string consists only of lowercase English letters. All of the given 2n strings will be distinct. The next line contains n distinct integers: p1, p2, ..., pn (1 ≤ pi ≤ n).

If it is possible, output "YES", otherwise output "NO".

3
gennady korotkevich
petr mitrichev
gaoyuan chen
1 2 3

3
gennady korotkevich
petr mitrichev
gaoyuan chen
3 1 2

2
galileo galilei
nicolaus copernicus
2 1

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
1 2 3 4 5 6 7 8 9 10

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
2 4 9 6 5 7 1 3 8 10

NoteIn example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.

(function() {
    print(function() {
        var e = +readline(),
            t = [];
        while (e--) {
            t.push(readline().split(" "));
        }
        e = t.length;
        var n = [];
        readline().split(" ").forEach(function(e) {
            return n.push(t[+e - 1])
        });
        var r = n[0][0] < n[0][1] ? n[0][0] : n[0][1];
        for (var i = 1; i < e; i++) {
            var s = [];
            n[i].forEach(function(e) {
                if (e >= r) s.push(e)
            });
            switch (s.length) {
                case 2:
                    r = s.sort()[0];
                    break;
                case 1:
                    r = s[0];
                    break;
                case 0:
                    return "NO"
            }
        }
        return "YES"
    }())
}).call(this)

(function(){print(function(){var e=+readline(),t=[];while(e--){t.push(readline().split(" "));}e=t.length;var n=[];readline().split(" ").forEach(function(e){return n.push(t[+e-1])});var r=n[0][0]<n[0][1]?n[0][0]:n[0][1];for(var i=1;i<e;i++){var s=[];n[i].forEach(function(e){if(e>=r)s.push(e)});switch(s.length){case 2:r=s.sort()[0];break;case 1:r=s[0];break;case 0:return"NO"}}return"YES"}())}).call(this)

function ProblemSolver() {

    this.getLexicographicallySmallest = function( prev , x , y ) {
        var l1 , l2 , l3 , res , i;
        res = "Invalid";
        l1 = prev.length;
        l2 = x.length;
        l3 = y.length;
        for( i = 0 ; i < Math.min( l2 , l3 ) ; i++ ) {
            if( x.charCodeAt( i ) == y.charCodeAt( i ) ) {
                continue;
            }
            else {
                if( x.charCodeAt( i ) < y.charCodeAt( i ) ) {
                    res = x;
                }
                else {
                    res = y;
                }
                break;
            }
        }
        if( res == "Invalid" ) {
            if( l2 < l3 ) {
                res = x ;
            }
            else {
                res = y ;
            }
        }

        if( l1 > 0 && prev.localeCompare( res ) >= 0 ) {
            if( res == x ) {
                if( prev.localeCompare( y ) < 0 ) {
                    res = y ;
                }
                else {
                    res = "Invalid";
                }
            }
            else {
                if( prev.localeCompare( x ) < 0 ) {
                    res = x ;
                }
                else {
                    res = "Invalid";
                }
            }
        }
        return res;
    };

    this.solveCase = function() {
        var res , i , j , a , b , c , prev , x , y;
        res = "YES";
        for( i = 0 ; i < this.n ; i++ ) {
            a = this.arr[ i ];
            this.brr[ a ] = i;
        }
        prev = "";
        for( i = 0 ; i < this.n ; i++ ) {
            a = this.arr[ i ];
            x = this.srr[ a - 1 ];
            y = this.trr[ a - 1 ];
            //print( "..." + this.srr[ a - 1 ] + "...." + this.trr[ a - 1 ] ) ;
            prev = this.getLexicographicallySmallest( prev , x , y );
            if( prev == "Invalid" ) {
                res = "NO";
                break;
            }
        }
        print( res );
    };

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

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.brr = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        //this.clearArraysPerCase() ;
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

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

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

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

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

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

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

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

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

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

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

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

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

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

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

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

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

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

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var pos;
var str1 = [];
var shag=0;
var result = true;
for (i = 0;i<p.length;i++){
	pos = p[i]-1;
	var str3 = str[pos];
	var str2 = str3.split(" ");
	str1[i+shag] = str2[0];
	str1[i+shag+1] = str2[1];
	shag=shag+1;
}
var sravn = [str1[0],str1[1],0];
var sra = 2;
for (i = 2;i<=str1.length-2;i=i+2){
	if (sra == 2){
	if ((sravn[0]<str1[i]||sravn[1]<str1[i])&&(sravn[0]<str1[i+1]||sravn[1]<str1[i+1])){
		sravn[0]=str1[i];
		sravn[1]=str1[i+1];
		sra = 2;}
	else if(sravn[0]<str1[i]||sravn[1]<str1[i]) {sravn[3]=str1[i]; sra=1;}
			else if (sravn[0]<str1[i+1]||sravn[1]<str1[i+1]) {sravn[3]=str1[i+1];sra = 1;}
				else {result = false;break}
	}
	else if (sravn[3]<str[i]&&sravn[3]<str[i+1]) {
			sravn[0]=str1[i];
			sravn[1]=str1[i+1];
			sra = 2;}
		else if(sravn[3]<str1[i]) {sravn[3]=str1[i]; sra=1;}
				else if (sravn[3]<str1[i+1]) {sravn[3]=str1[i+1]; sra=1;}
				else {result = false;break};
}
if(result) print("YES");
else print("NO");

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var aa = readline().split(' ');
	a[i]=new Array();
	if(aa[0]>aa[1])
	{
	    a[i][0]=aa[1];
		a[i][1]=aa[0];
	}
	else
	{
	    a[i][0]=aa[0];
		a[i][1]=aa[1];
	}
}
var result ='YES';
var str = '';
var b = readline().split(' ');
for(var i=0;i<b.length;i++)
{
    var pos = parseInt(b[i])-1;
	if(a[pos][0]>str)
	{
	    str = a[pos][0];
	}
	else if(a[pos][1]>str)
	{
	    str = a[pos][1];
	}
	else
	{
	    result = 'NO';
		break;
	}
}
print(result);

;(function () {

	print(function () {

		var n = +readline(), people = [];

		while (n--) {
			people.push(readline().split(' ').map(function (e) {
				return e.toLowerCase();
			} ));
		} n = people.length;

		people = readline().split(' ').map(function (e) {
			return people[+e - 1];
		});

		for (var i = 1; i < n; i++) {
			if (
				people[i - 1][0] > people[i][0] &&
				people[i - 1][0] > people[i][1] &&
				people[i - 1][1] > people[i][0] &&
				people[i - 1][1] > people[i][1]
			) return 'NO';
		}

		return 'YES';

	}());

}.call(this));

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	str1[i+shag] = str[i];
	str1[i+shag+1] = str[i+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print("NO");result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i];
	str1[i+shag] = str[pos];
	str1[i+shag+1] = str[pos+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print("NO");result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i]*2-2;
	str1[i+shag] = str[pos];
	str1[i+shag+1] = str[pos+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print(str1);result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
print (str);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i]*2-2;
	str1[i+shag] = str[pos];
	str1[i+shag+1] = str[pos+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print("NO");result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i]*2-2;
	str1[i+shag] = str[pos];
	str1[i+shag+1] = str[pos+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print(p);result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var pos;
var str1 = [];
var shag=0;
var result = true;
for (i = 0;i<p.length;i++){
	pos = p[i]-1;
	var str3 = str[pos];
	var str2 = str3.split(" ");
	str1[i+shag] = str2[0];
	str1[i+shag+1] = str2[1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print("NO");result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
print (str.lenght);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
print (str.length);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var pos;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i]-1;
	var str3 = str[pos];
	var str2 = str3.split(" ");
	str1[i+shag] = str2[0];
	str1[i+shag+1] = str2[1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print("NO");result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
print (str[2])

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var pos;
var str1 = [];
var shag=0;
var result = true;
for (i = 0;i<p.length;i++){
	pos = p[i]-1;
	var str3 = str[pos];
	var str2 = str3.split(" ");
	str1[i+shag] = str2[0];
	str1[i+shag+1] = str2[1];
	shag=shag+1;
}
var sravn = [str1[0],str1[1],0];
var sra = 2;
for (i = 2;i<=str1.length-2;i=i+2){
	if (sra = 2){
	if ((sravn[0]<str1[i]||sravn[1]<str1[i])&&(sravn[0]<str1[i+1]||sravn[1]<str1[i+1])){
		sravn[0]=str1[i];
		sravn[1]=str1[i+1];
		sra = 2;}
	else if(sravn[0]<str1[i]||sravn[1]<str1[i]) {sravn[3]=str1[i]; sra=1;}
			else if (sravn[0]<str1[i+1]||sravn[1]<str1[i+1]) {sravn[3]=str1[i+1];sra = 1;}
				else {result = false;break}
	}
	else if (sravn[3]<str[i]&&sravn[3]<str[i+1]) {
			sravn[0]=str1[i];
			sravn[1]=str1[i+1];
			sra = 2;}
		else if(sravn[3]<str1[i]) {sravn[3]=str1[i]; sra=1;}
				else if (sravn[3]<str1[i+1]) {sravn[3]=str1[i+1]; sra=1;}
				else {result = false;break};
}
if(result) print("YES");
else print("NO");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var pos;
var str1 = [];
var shag=0;
var result = true;
for (i = 0;i<p.length;i++){
	pos = p[i]-1;
	var str3 = str[pos];
	var str2 = str3.split(" ");
	str1[i+shag] = str2[0];
	str1[i+shag+1] = str2[1];
	shag=shag+1;
}
var sravn = [str1[0],str1[1],0];
var sra = 2;
for (i = 2;i<str1.length-2;i=i+2){
	if (sra = 2){
	if ((sravn[0]<str1[i]||sravn[1]<str1[i])&&(sravn[0]<str1[i+1]||sravn[1]<str1[i+1])){
		sravn[0]=str1[i];
		sravn[1]=str1[i+1];
		sra = 2;}
	else if(sravn[0]<str1[i]||sravn[1]<str1[i]) {sravn[3]=str1[i]; sra=1;}
			else if (sravn[0]<str1[i+1]||sravn[1]<str1[i+1]) {sravn[3]=str1[i+1];sra = 1;}
				else {result = false;break}
	}
	else if (sravn[3]<str[i]&&sravn[3]<str[i+1]) {
			sravn[0]=str1[i];
			sravn[1]=str1[i+1];
			sra = 2;}
		else if(sravn[3]<str1[i]) {sravn[3]=str1[i]; sra=1;}
				else if (sravn[3]<str1[i+1]) {sravn[3]=str1[i+1]; sra=1;}
				else {result = false;break};
}
if(result) print("YES");
else print("NO");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i]*2-2;
	str1[i+shag] = str[pos];
	str1[i+shag+1] = str[pos+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print(p.length);result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
    pos = p[i]*2-2;
    str1[i+shag] = str[pos];
    str1[i+shag+1] = str[pos+1];
    shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
    if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
        result = true;
    else {print(str.length);result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split("/\s/"));
var p = readline().split(" ");
print (str.length);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
    pos = p[i]*2-2;
    str1[i+shag] = str[pos];
    str1[i+shag+1] = str[pos+1];
    shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
    if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
        result = true;
    else {print("No");result = false;break};
}
if(result) print("Yes");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
	pos = p[i]*2-2;
	str1[i+shag] = str[pos];
	str1[i+shag+1] = str[pos+1];
	shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
	if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
		result = true;
	else {print(str1.length);result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
print (str);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split("\s"));
var p = readline().split(" ");
print (str.length);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline().split(" "));
var p = readline().split(" ");
var pos;
var pos2;
var str1 = [];
var shag=0;
var result;
for (i = 0;i<p.length;i++){
    pos = p[i]*2-2;
    str1[i+shag] = str[pos];
    str1[i+shag+1] = str[pos+1];
    shag=shag+1;
}
for (i = 0;i<str1.length-2;i=i+2){
    if (str1[i]<str1[i+2]||str1[i]<str1[i+3]||str1[i+1]<str1[i+2]||str1[i+1]<str1[i+3])
        result = true;
    else {print(str);result = false;break};
}
if(result) print("YES");

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var x = str.lenght;
print (x);

var n =readline();
var str = [];
for (i=1;i<=n;i++) str.push(readline());
var p = readline().split(" ");
var pos;
var str1 = [];
var shag=0;
var result = true;
for (i = 0;i<p.length;i++){
	pos = p[i]-1;
	var str3 = str[pos];
	var str2 = str3.split(" ");
	str1[i+shag] = str2[0];
	str1[i+shag+1] = str2[1];
	shag=shag+1;
}
var sravn = [str1[0],str1[1],0];
var sra = 2;
for (i = 2;i<str1.length-2;i=i+2){
	if (sra = 2){
	if ((sravn[0]<str[i]||sravn[1]<str[i])&&(sravn[0]<str[i+1]||sravn[1]<str[i+1])){
		sravn[0]=str[i];
		sravn[1]=str[i+1];
		sra = 2;}
	else if(sravn[0]<str[i]||sravn[1]<str[i]) {sravn[3]=str[i]; sra=1;}
			else if (sravn[0]<str[i+1]||sravn[1]<str[i+1]) {sravn[3]=str[i+1];sra = 1;}
				else {result = false;break}
	}
	else if (sravn[3]<str[i]&&sravn[3]<str[i+1]) {
			sravn[0]=str[i];
			sravn[1]=str[i+1];
			sra = 2;}
		else if(sravn[3]<str[i]) {sravn[3]=str[i]; sra=1;}
				else if (sravn[3]<str[i+1]) {sravn[3]=str[i+1]; sra=1;}
				else {result = false;break};

			}
if(result) print("YES");
else print("NO");


Your working week consists of $$$n$$$ days numbered from $$$1$$$ to $$$n$$$, after day $$$n$$$ goes day $$$1$$$ again. And $$$3$$$ of them are days off. One of the days off is the last day, day $$$n$$$. You have to decide when the other two are.Choosing days off, you pursue two goals:   No two days should go one after the other. Note that you can't make day $$$1$$$ a day off because it follows day $$$n$$$.  Working segments framed by days off should be as dissimilar as possible in duration. More specifically, if the segments are of size $$$l_1$$$, $$$l_2$$$, and $$$l_3$$$ days long, you want to maximize $$$\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$$$. Output the maximum value of $$$\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$$$ that can be obtained.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains the integer $$$n$$$ ($$$6 \le n \le 10^9$$$).

For each test case, output one integer — the maximum possible obtained value.

NoteIn the image below you can see the example solutions for the first two test cases. Chosen days off are shown in purple. Working segments are underlined in green.In test case $$$1$$$, the only options for days off are days $$$2$$$, $$$3$$$, and $$$4$$$ (because $$$1$$$ and $$$5$$$ are next to day $$$n$$$). So the only way to place them without selecting neighboring days is to choose days $$$2$$$ and $$$4$$$. Thus, $$$l_1 = l_2 = l_3 = 1$$$, and the answer $$$\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|) = 0$$$.   For test case $$$2$$$, one possible way to choose days off is shown. The working segments have the lengths of $$$2$$$, $$$1$$$, and $$$4$$$ days. So the minimum difference is $$$1 = \min(1, 3, 2) = \min(|2 - 1|, |1 - 4|, |4 - 2|)$$$. It can be shown that there is no way to make it larger.

// Common Template Starts //
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = ""
let currentLine = 0

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

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

const readline = () => inputString[currentLine++]
// Common Template Ends //

// Driver Function Starts //
const main = () => {
    let t = parseInt(readline())
    while (t--) {
        let n = parseInt(readline())
        console.log(solve(n))
    }
}
// Driver Function Ends //

// MAIN LOGIC
const solve = (n) => {
    if( n == 6 ) return 0

    while( n%3 != 0 ){
        n--
    }

    n = n/3

    return n - 2
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        n-=6;
        console.log(Math.floor(n/3));
    }
})

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

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    console.log(Math.floor((n-3)/3)-1);
  }
};
solve();

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

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

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

function myFunc(n){

    n = n-3;

    return parseInt(n/3)-1;

}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

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

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

'use strict';

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

let processIn = '';
let processCurr = 0;

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

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

    JS();
});

function readLine() {
    return processIn[processCurr++];
}
function mergeSort(a) {
    let r = a.length;
    let l = 0;
    let m = Math.round((r - l) / 2);
    if (r === 1) {
        return;   // returns recursively
    }
    let L = [];   // left half of current a
    let R = [];   // right half of current a
    for (let i = l; i < m; i++) {
        L.push(a[i]);
    }
    for (let j = m; j < r; j++) {
        R.push(a[j]);
    }
    mergeSort(L);
    mergeSort(R);
    let i = 0, j = 0, k = 0;
    // Merging part
    while (i < L.length && j < R.length) {
        if (L[i] < R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < L.length) {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < R.length) {
        a[k] = R[j];
        j++;
        k++;
    }
}

function JS() {
    /*

    */
    let tt = parseInt(readLine());
    // let tt = 1;
    for(let t=0;t<tt;++t){
        let n = parseInt(readLine());
        // let a = readLine().trim().split(' ').map(string => { return parseInt(string.trim()); });
        console.log(Math.floor(n/3) - 2);
    }
}

var n = +readline();
for (var i = 0; i < n; i++) {
  var val = +readline();
  print(Math.floor((val - 6) / 3));
}