'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    //  printf("n %d m %d mn %d mx %d s %d l %d r %d\n", n, m, mn, mx, s, l, r);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    m--;
    for (let x = n; x >= 1; x--) {
        mn = Math.trunc(m * (m + 1) / 2);
        if (mn + x > s) {
            continue;
        }
        m--;
        s -= x;
        used[x] = 1;
        a.push(x);
    }
    // printf("a: %j\n", a);
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

var maxN = 21
var mod = 1000000007

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

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

  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = parseInt(readline());
    var [n, l, r, s] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    l--
    r--
    var length = r - l + 1
    var lower = n - length + 1
    var ans = new Array(n).fill(false)
    var min = (((r - l + 1) + 1) * (r - l + 1)) / 2
    var max = (lower - 1) * length + ((length + 1) * (r - l + 1)) / 2
    var used = new Array(n + 1).fill(false)
    if (s < min || s > max) return console.log(-1)

    var a = []
    for (let j = 0; j < length; j++) {
      a[j] = j + 1
      s=s-a[j]
    }

    for (let j = length-1; j >=0; j--) {
      while (s>0 && a[j] < n - (length -j-1)){
        s--
        a[j]++
      }
    }
    for (let j = l; j <=r; j++) {
      ans[j] = a[j-l]
      used[ans[j]] = true
    }
    // console.log(ans.join(' '))

    for (let j = 1; j <= n; j++) {
      if (!used[j])
        for (let i = 0; i < n; i++) {
          if (ans[i] === false) {
            ans[i] = j
            break
          }
        }
    }
    console.log(ans.join(' '))

  })
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, l, r, s] = rna();

		const d = r - l + 1;
		const ar = Array.from(Array(d), (_, i) => i + 1);

		let need = s - d*(d+1)/2;
		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const mvs = Math.min(n - d, need);
			ar[i] += mvs;
			need -= mvs;
		}

		for (let i = 0, next = 1; ar.length < n; next++) {
			if (next != ar[i]) {
				ar.push(next);
			} else {
				i++;
			}
		}

		const ans = need == 0 && [...ar.slice(n - l + 1), ...ar].slice(0, n);

		console.log(ans ? ans.join(' ') : -1);
	}
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    //  printf("n %d m %d mn %d mx %d s %d l %d r %d\n", n, m, mn, mx, s, l, r);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    while (s > 0) {
        m--;
        mn = m * (m + 1) / 2;
        let x = Math.min(n, s - mn);
        while (used[x]) {
            x--;
        }
        used[x] = 1;
        a.push(x);
        s -= x;
    }
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    // printf("a: %j\n", a);
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, l, r, s] = rna();

		const d = r - l + 1;

		let need = s;
		const ar = [];
		for (let i = 1; i <= d; i++) {
			ar.push(i);
			need -= i;
		}

		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const chng = Math.min(n - d, need);
			ar[i] += chng;
			need -= chng;
		}

		const ss = new Set(ar);
		const ans = need == 0 && [];
		for (let i = 1; ans && i <= n; i++) {
			if (ans.length == l - 1) ans.push(...ar);
			if (!ss.has(i)) ans.push(i);
		}
		if (ans.length < n) ans.push(...ar);

		console.log(ans ? ans.join(' ') : -1);
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, l, r, s] = rna();

		const d = r - l + 1;

		let need = s;
		const ar = [];
		for (let i = 1; i <= d; i++) {
			ar.push(i);
			need -= i;
		}

		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const chng = Math.min(n - d, need);
			ar[i] += chng;
			need -= chng;
		}

		const ss = new Set(ar);
		const ans = need == 0 && [];
		for (let i = 1; ans && i <= n; i++) {
			if (ans.length == l - 1) {
				ans.push(...ar);
			}
			if (!ss.has(i)) {
				ans.push(i);
			}
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, l, r, s] = rna();

		const d = r - l + 1;

		let need = s;
		const ar = [];
		for (let i = 1; i <= d; i++) {
			ar.push(i);
			need -= i;
		}

		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const chng = Math.min(n - d, need);
			ar[i] += chng;
			need -= chng;
		}

		const ss = new Set(ar);
		const ans = need == 0 && [];
		for (let i = 1; ans && i <= n; i++) {
			if (!ss.has(i)) {
				ans.push(i);
			}
			if (ans.length == l - 1) {
				ans.push(...ar);
			}
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    // printf("m %d n %d mn %d mx %d\n", m, n, mn, mx);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    while (s > 0) {
        m--;
        mn = m * (m + 1) / 2;
        let x = s - mn;
        used[x] = 1;
        a.push(x);
        s -= x;
    }
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    // printf("a: %j\n", a);
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    printf("m %d n %d mn %d mx %d\n", m, n, mn, mx);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    while (s > 0) {
        m--;
        mn = m * (m + 1) / 2;
        let x = s - mn;
        used[x] = 1;
        a.push(x);
        s -= x;
    }
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    // printf("a: %j\n", a);
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}


const getMinOperations = (nums) => {
  var count = 0;

  for (var i = nums.length - 1; i >= 1; i--) {
    count += Math.max(0, nums[i - 1] - nums[i]);
  }

  return count;
};

const main = () => {
  const T = Number(readline());

  for (var _ = 0; _ < T; _++) {
    readline();
    var nums = readline()
      .split(" ")
      .map((i) => Number(i));

    print(getMinOperations(nums));
  }
};

main();

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

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

function main() {
	let t = readLine() >> 0;
	while (t--) {
		let n = readLine() >> 0;
		let arr = readLine()
			.split(' ')
			.map(x => x >> 0);

		let d = [];
		for (let i = 1; i < n; i++) {
			d.push(arr[i] - arr[i - 1]);
		}

		let s = d.reduce((a, c) => (c < 0 ? a + c : a), 0);
		console.log(Math.abs(s));
	}
}

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

    const store = [];

    for (let i = 0; i < len - 1; i++) {
      if (arr[i] - arr[i + 1] > 0) store.push(arr[i] - arr[i + 1]);
    }

    if (store.length) {
      const sum = store.reduce((total, n) => total + n, 0);
      console.log(sum);
    } else {
      console.log(0);
    }
  }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
	const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    let result = 0
    for (let i = 1; i < n; i++) {
      result += Math.max(0, as[i - 1] - as[i])
    }
    console.log(result)
  }
}

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

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

function main() {
	let t = readLine() >> 0;
	while (t--) {
		let n = readLine() >> 0;
		let arr = readLine()
			.split(' ')
			.map(x => x >> 0);

		let v = 0,
			c = arr[0];
		for (let i = 1; i < n; i++) {
			if (arr[i] < c) {
				v = Math.max(v, c - arr[i]);
			} else {
				c = arr[i];
			}
		}
		console.log(v);
	}
}


"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());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
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 sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [rw, rh] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseFloat(cur));
    let [x1, y1, x2, y2] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseFloat(cur));
    let u = rh - y2,
      r = rw - x2,
      l = x1,
      d = y1;
    let [tw, th] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseFloat(cur));
    let ans = Infinity;
    if (l >= tw) ans = 0;
    if (r >= tw - l && tw - l >= 0) ans = Math.min(ans, tw - l);
    if (r >= tw) ans = 0;
    if (l >= tw - r && tw - r >= 0) ans = Math.min(ans, tw - r);
    if (u >= th) ans = 0;
    if (d >= th - u && th - u >= 0) ans = Math.min(ans, th - u);
    if (d >= th) ans = 0;
    if (u >= th - d && th - d >= 0) ans = Math.min(ans, th - d);
    if (ans === Infinity) ans = -1;
    console.log(ans);
  }
};
solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var [W, H] = lines[l++].split(' ').map(Number)
        var [x1, y1, x2, y2] = lines[l++].split(' ').map(Number)
        var [w, h] = lines[l++].split(' ').map(Number)
        console.log(solve(W, H, x1, y1, x2, y2, w, h))
    }
});

function solve(W, H, x1, y1, x2, y2, w, h) {
    const l = x1
    const r = W - x2
    const t = H - y2
    const b = y1
    // console.log(l, r, t, b)
    let d1 = -1
    let d2 = -1
    if (l + r >= w) {
        d1 = h > H ? -1 : Math.max(0, w - Math.max(l, r))
    }
    if (t + b >= h) {
        d2 = w > W ? -1 : Math.max(0, h - Math.max(t, b))
    }

    if (d1 >= 0 && d2 >= 0) {
        return Math.min(d1, d2)
    } else if (d1 >= 0) {
        return d1
    } else if (d2 >= 0) {
        return d2
    }
    return -1
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t, i, s, r, u, d) {
  if (u > e || d > n) return -1
  if (u + (s - t) > e && d + (r - i) > n) return -1
  if (u <= t || u + s <= e) return 0
  if (d <= i || d + r <= n) return 0
  let o = Number.MAX_SAFE_INTEGER
  return (
    u + (s - t) <= e && (o = Math.min(o, u - t, u + s - e)),
    d + (r - i) <= n && (o = Math.min(o, d - i, d + r - n)),
    o
  )
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      [i, s, r, u] = e.readIntegersOfLine(),
      [d, o] = e.readIntegersOfLine(),
      a = solve(n, t, i, s, r, u, d, o)
    e.print(a + '\n')
  }
})

const setTable = (rWH, t1P, t2WH ) => {
    var rW = rWH[0];
    var rH = rWH[1];

    var t1X1 = t1P[0];
    var t1Y1 = t1P[1];
    var t1X2 = t1P[2];
    var t1Y2 = t1P[3];
    var t1W = t1X2 - t1X1;
    var t1H = t1Y2 - t1Y1;

    var t2W = t2WH[0];
    var t2H = t2WH[1];

    if((t1W + t2W > rW) && (t1H + t2H > rH)) {
        return -1;
    }

    var fSW = Math.max(t1X1, rW - t1X2);
    var fSH = Math.max(t1Y1, rH - t1Y2);

    var shift = Math.min(
        t1W + t2W > rW ? Infinity : t2W - fSW,
        t1H + t2H > rH ? Infinity : t2H - fSH
    );

    return shift >= 0 ? shift : 0;
};

const n = +readline();

var roomWH;
var table1Points;
var table2WH;

for(var i = 0; i < n; i++) {
    roomWH = readline().split(" ").map(i => +i);
    table1Points = readline().split(" ").map(i => +i);
    table2WH = readline().split(" ").map(i => +i);
    print(setTable(roomWH, table1Points, table2WH));
}

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

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

let INF = 2e8;
function main () {
	let t = rn();
	while (t--) {
		let [W, H] = rna();
		let [x1, y1, x2, y2] = rna();
		let [w, h] = rna();

		hmx = Math.max(H - y2, y1);
		wmx = Math.max(x1, W - x2);

		if (w < wmx || h < hmx)
			console.log(0);
		else {
			let ans1 = ans2 = INF;
			if (h + (y2 - y1) <= H) {
				ans1 = h - hmx;
			}

			if (w + (x2 - x1) <= W) {
				ans2 = w - wmx;
			}

			console.log((ans1 & ans2) == INF ? -1 : Math.min(ans1, ans2));
		}
	}
}

"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());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
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 sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [rw, rh] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseFloat(cur));
    let [x1, y1, x2, y2] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseFloat(cur));
    let u = rh - y2,
      r = rw - x2,
      l = x1,
      d = y1;
    let [tw, th] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseFloat(cur));
    let ans = Infinity;
    if (l >= tw) ans = 0;
    if (r >= tw - l) ans = Math.min(ans, tw - l);
    if (r >= tw) ans = 0;
    if (l >= tw - r) ans = Math.min(ans, tw - r);
    if (u >= th) ans = 0;
    if (d >= th - u) ans = Math.min(ans, th - u);
    if (d >= th) ans = 0;
    if (u >= th - d) ans = Math.min(ans, th - d);
    if (ans === Infinity) ans = -1;
    console.log(ans);
  }
};
solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var [W, H] = lines[l++].split(' ').map(Number)
        var [x1, y1, x2, y2] = lines[l++].split(' ').map(Number)
        var [w, h] = lines[l++].split(' ').map(Number)
        console.log(solve(W, H, x1, y1, x2, y2, w, h))
    }
});

function solve(W, H, x1, y1, x2, y2, w, h) {
    const l = x1
    const r = W - x2
    const t = H - y2
    const b = y1
    // console.log(l, r, t, b)
    if (l + r >= w) {
        return h > H ? -1 : Math.max(0, w - Math.max(l, r))
    }
    if (t + b >= h) {
        return w > W ? -1 : Math.max(0, h - Math.max(t, b))
    }
    return -1
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
const MAX_N = 100010,
  sum1 = new Array(MAX_N)
function solve(e, n, t) {
  if (e <= 1) return 0
  sum1[0] = n[0]
  for (let t = 1; t < e; ++t) sum1[t] = sum1[t - 1] + n[t]
  const s = e - 1
  let i = sum1[s] - n[0]
  for (let n = 1, r = t[0]; n < e; ++n) {
    const e = Math.max(sum1[s] - sum1[n], r)
    ;(r += t[n]), i > e && (i = e)
  }
  return i
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(
      Number(e.readLine()),
      e.readIntegersOfLine(),
      e.readIntegersOfLine(),
    )
    e.print(n + '\n')
  }
})


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

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

function Arr(a, b, cb) {
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb(i + a));
  return Array(a - b + 1).fill(0).map((v, i) => cb(a - i));
}

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

function max(a, b) {
  if (a > b) return a;
  return b;
}

(async () => {
  await inputPromise;
  let inp = input.split(/\D+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(0, t - 1, i => {
    let [n, x, y] = inp.slice(r, r = r + 3);
    // console.log(n, x, y);
    For(n - 1, 1, i => {
      if ((y - x) % i == 0) {
        let k = (y - x) / i;
        a = Arr(0, i, i => x + i * k);
        while (a.length < n) {
          if (a[0] - k >= 1) a.unshift(a[0] - k);
          else a.push(a[a.length - 1] + k);
        }
        console.log(a.join(' '));
        return 0;
      }
    })
  })
})();

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    var N = one[0];
    var x = one[1];
    var y = one[2];
    if(N == 2){
      output[i] = x + " " + y;
      continue;
    }
    var dlist = getDivisorList(y - x);
    var out = [];
    var max = Math.pow(10,9);
    for(var j = 0; j < dlist.length; j++){
      var tmpmax = y;
      var tmpout = [x];
      var isOK = false;
      for(var k = 1; k <= N; k++){
        if(x + k * dlist[j] > y){
          isOK = true;
          break;
        }
        tmpout.push(x + k * dlist[j]);

      }
      //myerr(tmpout);
      if(isOK && tmpout.length <= N){
        for(var k = 1; k <= N; k++){
          if(tmpout.length == N){
            break;
          }
          if(x - dlist[j] * k < 1){
            break;
          }
          tmpout.unshift(x - dlist[j] * k);

        }
        while(tmpout.length < N){
          tmpout.push(tmpout[tmpout.length - 1] + dlist[j]);
          tmpmax = tmpout[tmpout.length - 1];
        }
        if(max > tmpmax){
          max = tmpmax;
          out = tmpout;
        }
        //myerr(tmpout);
      }else{
        continue;
      }
    }
    output[i] = myconv(out, 8);
  }
  myout(myconv(output, 9));
}
function getDivisorList(val){
  var list = [];
  for(var i = 1; i * i <= val; i++){
    if(val % i == 0){
      list.push(i);
      if(i * i != val){
        list.push(val / i);
      }
    }
  }
  list.sort(function(a,b){ return a - b; });
  return list;
}

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

let input = [];

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

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

  for (let i = 1; i <= t; i++) {
    let [n, x, y] = input[i].split(" ").map((num) => Number(num));

    if (n === 2) {
      console.log([x, y].join(" "));
      continue;
    }

    const diff = y - x;
    const result = [];

    //1. x와 y사이에는 (n-2)개 ~ 0개의 원소가 존재할 수 있다.
    for (let j = n - 1; j >= 0; j--) {
      const equalDiff = diff / j;

      //2. 정수로 나뉘어 떨어지지 않는다면 해당 개수는 불가능
      if (equalDiff !== parseInt(equalDiff)) {
        continue;
      }

      //3. 정수로 나누어 떨어진다면 해당 배열이 답이다
      //3-1. x와 y 넣기
      result.push(x);
      result.push(y);
      n -= 2;

      //3-2. x와 y 사이 넣기
      for (let k = 1; k <= j - 1; k++) {
        n--;
        result.push(x + k * equalDiff);
      }

      //3-3. x 이전 넣기
      for (let k = 1; ; k++) {
        if (n <= 0) break;

        const xBefore = x - k * equalDiff;
        if (xBefore <= 0) break;

        n--;
        result.push(xBefore);
      }

      //3-4. y 이후 넣기
      for (let k = 1; ; k++) {
        if (n <= 0) break;

        const yAfter = y + k * equalDiff;
        n--;
        result.push(yAfter);
      }

      //7. 최댓값이 존재하는 배열을 만들어 출력한다
      console.log(result.join(" "));
      break;
    }
  }
}

/*

  1. 비밀 배열을 복원해야 한다
  2. n개의 서로 다른 양의 정수를 포함하고 있다
  3. 너에게 알려진 x와 y를 포함하고 있는데, x < y
  4. 오름차순으로 정렬 시, 각 인접 원소 간의 diff는 모두 동일

  Q. 가장 큰 원소의 값이 최소가 되는 배열의 원소들을 출력하라

*/

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

let inputString = '';
let currentLine = 0;

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

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

    C();
});

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

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

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

    return a;
}

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

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

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

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

        if(a > b){
            let temp = a;
            a = b;
            b = temp;
            temp = x;
            x = y;
            y = temp;
        }

        if(b - y >= n){
            b -= n;
            console.log(a*b);
        }else{
            n -= (b-y);
            b = y;
            if(a-x >= n){
                a -= n;
            }else{
                a = x;
            }

            console.log(a*b);
        }
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,x,y] = ti(readline().split(' '));

        let min = 99999999999999;
        let res = null;
        for(let i = 1; i <= x; i++){
            for(let j = 0; j <= y-x; j++){
                let inclX = false;
                let inclY = false;
                let op = new Array(n);
                for(let k = 0; k < n; k++){
                    if(k === 0){
                        op[k] = i;
                    }else{
                        op[k] = op[k-1] + j;
                    }

                    if(op[k] === x)
                        inclX = true;

                    if(op[k] === y)
                        inclY = true;
                }

                if(inclX && inclY){
                    if(min > op[n-1]){
                        min = op[n-1];
                        res = op;
                    }
                }
            }
        }

        for(let num of res)
            console.log(num);
    }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const mul = (a, b) => mod(mod(a) * mod(b));

function main() {
  let t = +readLine();
  while (t--) {
    const [len, a, b] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let min = Number.MAX_SAFE_INTEGER;
    let result = [];

    for (let start = 1; start <= 50; start++) {
      for (let diff = 1; diff <= 50; diff++) {
        const arr = [start];
        let [foundA, foundB] = [false, false];
        for (let i = 1; i < len; i++) {
          arr.push(start + diff * i);
        }
        for (let i = 0; i < len; i++) {
          if (arr[i] === a) foundA = true;
          if (arr[i] === b) foundB = true;
        }
        if (foundA && foundB) {
          if (arr[len - 1] < min) {
            min = arr[len - 1];
            result = [...arr];
          }
        }
      }
    }
    console.log(result.join(" "));
  }
}

T = readline()
while (T--) {
  a = readline().split(' ')
  n = +a[0]
  x = +a[1]
  y = +a[2]
  d = y - x
  k = 1
  for (; k < 50; k++) {
    if (d % k)
      continue
    if (d / k + 1 <= n)
      break
  }
  j = n - 1
  while (y - j * k < 1)
    j--
  u = y - j * k
  ans = ''
  for (i = 0; i < n; i++) {
    ans += u.toString() + ' '
    u += k
  }
  print(ans)
}

T = readline()
while (T--) {
  a = readline().split(' ').map(x => +x)
  n = a[0]; x = a[1]; y = a[2]
  d = y - x
  k = 1
  for (; k < 50; k++) {
    if (d % k)
      continue
    if (d / k + 1 <= n)
      break
  }
  j = n - 1
  while (y - j * k < 1)
    j--
  u = y - j * k
  print(Array.from({ length: n }, (v, i) => u + k * i).join(' '));
}

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

let input = [];

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

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

  for (let i = 1; i <= t; i++) {
    let [n, x, y] = input[i].split(" ").map((num) => Number(num));

    if (n === 2) {
      console.log([x, y]);
      continue;
    }

    const diff = y - x;
    const result = [];

    //1. x와 y사이에는 (n-2)개 ~ 0개의 원소가 존재할 수 있다.
    for (let j = n - 1; j >= 0; j--) {
      const equalDiff = diff / j;

      //2. 정수로 나뉘어 떨어지지 않는다면 해당 개수는 불가능
      if (equalDiff !== parseInt(equalDiff)) {
        continue;
      }

      //3. 정수로 나누어 떨어진다면 해당 배열이 답이다
      //3-1. x와 y 넣기
      result.push(x);
      result.push(y);
      n -= 2;

      //3-2. x와 y 사이 넣기
      for (let k = 1; k <= j - 1; k++) {
        n--;
        result.push(x + k * equalDiff);
      }

      //3-3. x 이전 넣기
      for (let k = 1; ; k++) {
        if (n <= 0) break;

        const xBefore = x - k * equalDiff;
        if (xBefore <= 0) break;

        n--;
        result.push(xBefore);
      }

      //3-4. y 이후 넣기
      for (let k = 1; ; k++) {
        if (n <= 0) break;

        const yAfter = y + k * equalDiff;
        n--;
        result.push(yAfter);
      }

      //6. 정렬
      result.sort((n1, n2) => {
        return n1 - n2;
      });

      //7. 최댓값이 존재하는 배열을 만들어 출력한다
      console.log(result);
      break;
    }
  }
}

/*

  1. 비밀 배열을 복원해야 한다
  2. n개의 서로 다른 양의 정수를 포함하고 있다
  3. 너에게 알려진 x와 y를 포함하고 있는데, x < y
  4. 오름차순으로 정렬 시, 각 인접 원소 간의 diff는 모두 동일

  Q. 가장 큰 원소의 값이 최소가 되는 배열의 원소들을 출력하라

*/


const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const e = lines[i*2+2].split(' ').map(x => +x).sort((a, b) => a-b).reduce((r, x, index) => {
      if (index > 0) {
        if (r[r.length - 1][0] === x) {
          r[r.length - 1][1]++
        } else {
          r.push([x, 1])
        }
      } else {
        r.push([x, 1])
      }
      return r
    }, [])
    let sum = 0
    let rest = 0
    for (let j=0; j<e.length; j++) {
      const num =  e[j][0]
      const count = rest + e[j][1]
      if (count >= num) {
        sum += Math.floor(count/num)
        rest = count % num
      } else {
        rest += e[j][1]
      }
    }
    console.log(sum)
    // while(start < e.length) {
    //   start += e[start]
    //   c++
    // }
    // if (start > e.length) {
    //   c--
    // }
    // console.log(c)
  }
}

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

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var t = nextIntArray();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray();
		var map = {};
		for(var j = 0; j < N; j++){
			if(map[list[j]] == null){
				map[list[j]] = 1;
			}else{
				map[list[j]]++;
			}
		}
		var keys = Object.keys(map);
		keys.sort(function(a,b){
			return a - b;
		});
		var count = 0;
		for(var j = 0; j < keys.length; j++){
			var singleCount = Math.floor(map[keys[j]] / keys[j]);
			var nokori = map[keys[j]] % keys[j];
			count += singleCount;
			if(j != keys.length - 1){
				map[keys[j + 1]] += nokori;
			}
		}
		output[i] = count;
	}
	myout(myconv(output,9));
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    6
1
2
3
4
5
6

**/

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

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

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

    for(let r=0;r<range;r++) {
        let n = parseInt(readline())
        let a = readline().split(" ").map(Number);

        a.sort((a, b) => a - b);
        let temp = 0;
        let ans = 0;

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

            if(a[i] <= temp) {
                ans++;
                temp = 0;
            }
        }

        console.log(ans);
    }
}

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var t = nextIntArray();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray();
		var map = {};
		for(var j = 0; j < N; j++){
			if(map[list[j]] == null){
				map[list[j]] = 1;
			}else{
				map[list[j]]++;
			}
		}
		var keys = Object.keys(map);
		keys.sort(function(a,b){
			return a - b;
		});
		var count = 0;
		for(var j = 0; j < keys.length; j++){
			var singleCount = Math.floor(map[keys[j]] / keys[j]);
			var nokori = map[keys[j]] % keys[j];
			count += singleCount;
			map[keys[j] + 1] += nokori;
		}
		output[i] = count;
	}
	myout(myconv(output,9));
}

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const e = lines[i*2+2].split(' ').map(x => +x).sort((a, b) => a-b).reduce((r, x, index) => {
      if (index > 0) {
        if (r[r.length - 1][0] === x) {
          r[r.length - 1][1]++
        } else {
          r.push([x, 1])
        }
      } else {
        r.push([x, 1])
      }
      return r
    }, [])
    let sum = 0
    let rest = 0
    for (let j=0; j<e.length; j++) {
      const num =  e[j][0]
      const count = rest + e[j][1]
      if (count >= num) {
        sum += Math.floor(count/num)
        rest = count % num
      }
    }
    console.log(sum)
    // while(start < e.length) {
    //   start += e[start]
    //   c++
    // }
    // if (start > e.length) {
    //   c--
    // }
    // console.log(c)
  }
}

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

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const e = lines[i*2+2].split(' ').map(x => +x)
    e.sort((a, b) => b - a)
    let start = 0
    let c = 0
    while(start < e.length) {
      start += e[start]
      c++
    }
    console.log(c)
  }
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    6
1
2
3
4
5
6

**/

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

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

let clone = Array.push;

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

    for(let r=0;r<range;r++) {
        let n = parseInt(readline());
        let a = readline().split(" ").map(Number);
        let unique = new Set([...a]);

        if(unique.size === 1) {
            console.log(n);
            continue;
        }

        a = [...unique];
        a.sort((a, b) => a - b);

        let count = 0;
        while(a.length) {
            a.shift();
            a.pop();
            count++
        }

        console.log(count);

    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    6
1
2
3
4
5
6

**/

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

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

let clone = Array.push;

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

    for(let r=0;r<range;r++) {
        let n = parseInt(readline());
        let a = readline().split(" ").map(Number);
        let unique = new Set([...a]);

        if(unique.size === 1) {
            console.log(n);
            continue;
        }

        console.log(n - unique.size);

    }
}


function max(a, b) {
    return (a > b ? a : b);
}

function min(a, b) {
    return (a > b ? b : a);
}

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

for (var i = 0; i < n; i++) {
    var line = readline().split(' ');
    var x = parseInt(line[0]), y = parseInt(line[1]);
    line = readline().split(' ');
    var a = parseInt(line[0]), b = parseInt(line[1]);
    if (max(x, y) == max(a, b) && min(x, y) + min(a, b) == max(x, y)) print("YES");
    else print("NO");
}

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

let tc
let slice1,slice2;
r.on('line', (line) => {
    if (!tc) { tc = line; }
    else if (!slice1) {
        slice1 = line;

    }
    else if (!slice2) {
        slice2 = line;
        let d1 = slice1.split(" ").map(n =>+n);
        let d2 = slice2.split(" ").map(n =>+n);
        console.log(  sq(d1[0],d1[1],d2[0],d2[1]) ?"YES":"NO");
        slice1= slice2= undefined;
    }
    else {
        query = readNums(line);
        console.log(minLength(arr, query[0], query[1]));
    }

});

function sq(a,b,c,d){
    return (a==c && a == (b+d)) || (a==d && a == (b+c)) ||((b==c && b == (a+d))) ||((b==d && b == (a+c)))
}

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var mae = nextIntArray();
		var ato = nextIntArray();
		if(mae[0] == ato[0] || mae[0] == ato[1] || mae[1] == ato[0] || mae[1] == ato[1]){
			if(mae[0] == ato[0]){
				if(mae[1] + ato[1] == mae[0]){
					output[i] = "YES";
				}
			}
			if(mae[0] == ato[1]){
				if(mae[1] + ato[0] == mae[0]){
					output[i] = "YES";
				}
			}
			if(mae[1] == ato[0]){
				if(mae[0] + ato[1] == mae[1]){
					output[i] = "YES";
				}
			}
			if(mae[1] == ato[1]){
				if(mae[0] + ato[0] == mae[1]){
					output[i] = "YES";
				}
			}
			if(output[i] == null){
				output[i] = "NO";
			}
		}else{
			output[i] = "NO";
		}
	}
	myout(myconv(output,9));
}

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

let tc
let slice1, slice2;
r.on('line', (line) => {
  if (!tc) { tc = line; }
  else if (!slice1) {
    slice1 = line;

  }
  else if (!slice2) {
    slice2 = line;
    let d1 = slice1.split(" ").map(n => +n);
    let d2 = slice2.split(" ").map(n => +n);
    console.log(sq(d1[0], d1[1], d2[0], d2[1]) ? "YES" : "NO");
    slice1 = slice2 = undefined;
  }
  else {
    query = readNums(line);
    console.log(minLength(arr, query[0], query[1]));
  }

});

function sq(a, b, c, d) {
  return (a == c && a == (b + d)) || (a == d && a == (b + c)) || ((b == c && b == (a + d))) || ((b == d && b == (a + c)))
}

var t = Number(readline());
while(t--) {
    var v = readline().split(" ");
    var a1 = Number(v[0]);
    var b1 = Number(v[1]);

    v = readline().split(" ");
    var a2 = Number(v[0]);
    var b2 = Number(v[1]);

    if ((a1 == a2 && b1+b2 == a1) || (b1 == b2 && a1+a2 == b1)) print("YES");
    else if ((a1 == b2 && b1+a2 == a1) || (b1 == a2 && a1+b2 == b1)) print("YES");
    else print("NO");
}

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [a, b] = lines[i*2+1].split(' ').map(x => +x).sort((a, b) => b-a)
    const [c, d] = lines[i*2+2].split(' ').map(x => +x).sort((a, b) => b-a)
    if (a === c && b+d === a) {
      console.log('Yes')
    } else {
      console.log('No')
    }
  }
}

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

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

var N = null,
    ab = null

function loop(line) {

    if (line.trim() == "")
        return

    let cd = line.split(" ")
                 .map(x => parseInt(x,10))
                 .sort((x,y) => x-y)

    if (ab == null)
        return ab = cd

    if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])
        console.log("Yes")
    else
        console.log("No")

    ab = --N == 0 ? rl.close() : null

}

rl.question("", line => {
    N = parseInt(line,10)
    rl.on("line", loop)
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    for (var i = 0; i < n; i++) {
        let arr = [];
        arr.push(readLine()
            .split(' ')
            .map(value => parseInt(value))
            .sort((a, b) => b - a)
        );
        arr.push(readLine()
            .split(' ')
            .map(value => parseInt(value))
            .sort((a, b) => b - a)
        );
        if (arr[0][0] == arr[1][0]) {
            if (arr[0][1] + arr[1][1] == arr[0][0]) {
                console.log('YES');
            } else
                console.log('NO')
        } else console.log('NO');
    }
}

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

    main();
});

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

function main() {
    const n = parseInt(readLine(), 10);
    for (let i = 0; i < n; i++) {
        const [a, b] = readLine().split(' ').map(x => parseInt(x));
        const [c, d] = readLine().split(' ').map(x => parseInt(x));
        if ((a == c && (b+d) ==a ) || (a == d && (b + c) == a) || (c == b && (a+d) ==c ) || (b == d && (a+c) ==b ) ){
            console.log('YES')
        } else console.log('NO')
    }
    return;
}

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

    main();
});

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

function main() {
    const n = parseInt(readLine(), 10);
    for (let i = 0; i < n; i++) {
        const [a, b] = readLine().split(' ').map(x => parseInt(x));
        const [c, d] = readLine().split(' ').map(x => parseInt(x));
        if (Math.sqrt((a*b) + (c*d))%1 ==0){
            console.log('YES')
        } else console.log('NO')
    }
    return;
}

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

    main();
});

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

function main() {
    const n = parseInt(readLine(), 10);
    for (let i = 0; i < n; i++) {
        const [a, b] = readLine().split(' ').map(x => parseInt(x));
        const [c, d] = readLine().split(' ').map(x => parseInt(x));
        const totalArea = (a*b) + (c*d);
        if (totalArea > 3 && Math.sqrt(totalArea)%1 ==0){
            console.log('YES')
        } else console.log('NO')
    }
    return;
}

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var mae = nextIntArray();
		var ato = nextIntArray();

		if(mae[0] == ato[0] || mae[0] == ato[1] || mae[1] == ato[0] || mae[1] == ato[1]){
			if(mae[0] == ato[0]){
				if(mae[1] + ato[1] == mae[0]){
					output[i] = "YES";
				}
			}else if(mae[0] == ato[1]){
				if(mae[1] + ato[0] == mae[0]){
					output[i] = "YES";
				}
			}else if(mae[1] == ato[0]){
				if(mae[0] + ato[1] == mae[1]){
					output[i] = "YES";
				}
			}else if(mae[1] == ato[1]){
				if(mae[0] + ato[0] == mae[1]){
					output[i] = "YES";
				}
			}
			if(output[i] == null){
				output[i] = "NO";
			}
		}else{
			output[i] = "NO";
		}
	}
	myout(myconv(output,9));
}

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

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

  if (c % 2) {
    [a1, b1] = d.split(' ').map(Number);
    c++;
    return;
  }

  [a2, b2] = d.split(' ').map(Number);

  if (a1 + a2 === b1 || a1 + b2 === b1) {
    console.log('YES');
  }
  else if (b1 + a2 === a1 || b1 + b2 === a1) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

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

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

  if (c % 2) {
    [a1, b1] = d.split(' ').map(Number);
    c++;
    return;
  }

  [a2, b2] = d.split(' ').map(Number);

  if (a1 === a2 || a1 === b2) {
    if (b1 + a2 === a1 || b1 + b2 === a1) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }
  else if (b1 === a2 || b1 === b2) {
    if (a1 + a2 === b1 || a1 + b2 === b1) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }
  else {
    console.log('NO');
  }

  c++;
});

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

function sq(a, b, c, d) {
  return (a == c && a == (b + d)) || (a == d && a == (b + c)) || ((b == c && b == (a + d))) || ((b == d && b == (a + c)))
}

rl.on('line', (data) => {
  if (count === 0) {
    count++;
    tests = +data;
    return;
  }

  if (count % 2) {
    [a, b] = data.split(' ').map(Number);
    count++;
    return;
  }

  [c, d] = data.split(' ').map(Number);

  console.log(sq(a, b, c, d) ? "YES" : "NO");

  count++;
});

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

rl.on('line', (data) => {
  if (count === 0) {
    count++;
    tests = +data;
    return;
  }

  if (count % 2) {
    [a, b] = data.split(' ').map(Number);
    count++;
    return;
  }

  if (tests === 0) {
    return;
  }

  tests--;
  [c, d] = data.split(' ').map(Number);

  if (a > b) {
    [a, b] = [b, a];
  }

  if (c > d) {
    [c, d] = [d, c];
  }

  if (b === d && a + c === b) {
    console.log('YES');
  }
  else {
    console.log('No');
  }

  count++;
});

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

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

  if (count % 2) {
    [a, b] = data.split(' ').map(Number);
    count++;
    return;
  }

  [c, d] = data.split(' ').map(Number);

  if (a > b) {
    [a, b] = [b, a];
  }

  if (c > d) {
    [c, d] = [d, c];
  }

  if (b === d && a + c === b) {
    console.log('YES');
  }
  else {
    console.log('No');
  }

  count++;
});

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

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

  if (c % 2) {
    [a1, b1] = d.split(' ').map(Number);
    c++;
    return;
  }

  [a2, b2] = d.split(' ').map(Number);

  if (a1 === a2 || a1 === b2) {
    if (b1 + a2 === a1 || b1 + b2 === a1) {
      console.log('YES');
    }
    else if (a1 + b1 === a2 + b2) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }
  else if (b1 === a2 || b1 === b2) {
    if (a1 + a2 === b1 || a1 + b2 === b1) {
      console.log('YES');
    }
    else if (a1 + b1 === a2 + b2) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }
  else {
    console.log('NO');
  }

  c++;
});

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

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

  if (c % 2) {
    [a1, b1] = d.split(' ').map(Number);
    c++;
    return;
  }

  [a2, b2] = d.split(' ').map(Number);

  if (a1 === a2 || a1 === b2) {
    if (b1 + a2 === a1 || b1 + b2 === a1) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }
  else if (b1 === a2 || b1 === b2) {
    if (a1 + a2 === b1 || a1 + b2 === b1) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }
  else {
    if (a1 + b1 === a2 + b2) {
      console.log('YES');
    }
    else {
      console.log('NO');
    }
  }

  c++;
});

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

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

  if (c % 2) {
    arr1 = d.split(' ').map(Number);
    arr1.sort((a, b) => a - b);
    c++;
    return;
  }

  arr2 = d.split(' ').map(Number);
  arr2.sort((a, b) => a - b);

  if (arr1[0] + arr2[0] === arr1[1] && arr1[1] === arr2[1]) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

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

rl.on('line', (d) => {

  c++;
});

rl.on('close', () => {

});

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

function dotest(t) {
    rl.question("", ab => {
        ab = ab.split(" ").map(Number).sort()
        rl.question("", cd => {
            cd = cd.split(" ").map(Number).sort()
            if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1]) {
                console.log("Yes")
            } else {
                console.log("No")
            }
            t == 1 ? rl.close():dotest(t-1)
        })
    })
}

rl.question("", t => dotest(Number(t)))

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

var t = null,
    ab = null

function loop(line) {

    if (t == null) return t = Number(line)

    const cd = line.split(" ").map(Number).sort()

    if (ab == null) {
        ab = cd
    } else {
        if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])
            console.log("Yes")
        else
            console.log("No")
        if (--t == 0)
            rl.close()
        else
            ab = null
    }

}

rl.on("line", line => loop(line))

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

var N = null,
    ab = null

function loop(line) {

    let cd = line.split(" ").map(Number).sort((x,y) => x-y)

    if (ab == null)
        return ab = cd

    if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])
        console.log("Yes")
    else
        console.log("No")

    ab = --N == 0 ? rl.close() : null

}

rl.question("", line => {
    N = parseInt(line,10)
    rl.on("line", line => loop(line))
})

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

function dotest(t) {
    rl.question("", ab => {
        ab = ab.split(" ").map(Number).sort()
        rl.question("", cd => {
            cd = cd.split(" ").map(Number).sort()
            if (ab[1] != cd[1] || ab[0] == ab[1] || cd[0] == cd[1]) {
                console.log("No")
            } else if (ab[0] + cd[0] == ab[1]) {
                console.log("Yes")
            }
            t == 1 ? rl.close():dotest(t-1)
        })
    })
}

rl.question("", t => dotest(Number(t)))

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

function dotest(t) {
    rl.question("", ab => {
        ab = ab.split(" ").map(Number).sort()
        rl.question("", cd => {
            cd = cd.split(" ").map(Number).sort()
            if (ab[0] != ab[1] && cd[0] != cd[1] && ab[1] == cd[1] && (ab[0] + cd[0]) == ab[1]) {
                console.log("Yes")
            } else {
                console.log("No")
            }
            t == 1 ? rl.close():dotest(t-1)
        })
    })
}

rl.question("", t => dotest(Number(t)))

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

function dotest(t) {
    rl.question("", ab => {
        ab = ab.split(" ").map(Number)
        rl.question("", cd => {
            cd = cd.split(" ").map(Number)
            if (ab[0] == ab[1] || cd[0] == cd[1]) {
                console.log("No")
            } else {
            let abcd = ab.concat(cd).sort()
            if (abcd[2] == abcd[3] && abcd[0] + abcd[1] == abcd[2])
                console.log("Yes")
            else
                console.log("No")
            }
            t == 1 ? rl.close():dotest(t-1)
        })
    })
}

rl.question("", t => dotest(Number(t)))

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

function dotest(t) {
    rl.question("", ab => {
        ab = ab.split(" ")//.map(Number).sort()
        a = Number(ab[0])
        b = Number(ab[1])
        rl.question("", cd => {
            cd = cd.split(" ")//.map(Number).sort()
            c = Number(cd[0])
            d = Number(cd[1])
            if ((a==c && b+d==a) || (a==d && b+c==a) || (b==c && a+d==b) || (b==d && a+c==b)) {
                console.log("Yes")
            } else {
                console.log("No")
            }
            t == 1 ? rl.close():dotest(t-1)
        })
    })
}

rl.question("", t => dotest(Number(t)))

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

function dotest(t) {
    rl.question("", ab => {
        ab = ab.split(" ").map(Number).sort()
        rl.question("", cd => {
            cd = cd.split(" ").map(Number).sort()
            if (ab[0] + cd[0] == ab[1] && ab[0] + cd[0] == cd[1]) {
                console.log("Yes")
            } else {
                console.log("No")
            }
            t == 1 ? rl.close():dotest(t-1)
        })
    })
}

rl.question("", t => dotest(Number(t)))

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

var t = null,
    ab = null

function loop(line) {

    if (t == null) return t = Number(line)

    const cd = line.split(" ").map(Number).sort()

    if (ab == null) {
        ab = cd
    } else {
        if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])
            console.log("Yes")
        else
            console.log("No")
        if (--t == 0)
            rl.close()
        else
            ab = null
        console.log(t)
    }

}

rl.on("line", line => loop(line))

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

var N = null,
    ab = null

function loop(line) {

    let cd = line.split(" ")
                 .map(x => parseInt(x,10))
                 .sort((x,y) => x-y)

    if (ab == null)
        return ab = cd

    if (ab[1] == cd[1] && ab[0] + cd[0] == ab[1])
        console.log("Yes")
    else
        console.log("No")

    ab = --N == 0 ? rl.close() : null

}

rl.question("", line => {
    N = parseInt(line,10)
    rl.on("line", loop)
})


"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = parseInt(readline());
var answers = [];

for (var i = 0; i < n; i++) {
  var _readline$getNumArray = readline().getNumArray(),
      _readline$getNumArray2 = _slicedToArray(_readline$getNumArray, 3),
      c = _readline$getNumArray2[0],
      m = _readline$getNumArray2[1],
      l = _readline$getNumArray2[2];

  var mainMin = c < m ? c : m;
  l += Math.abs(c - m);

  if (l >= mainMin) {
    answers.push(mainMin);
  } else {
    var transport = Math.ceil((mainMin - l) / 3);
    answers.push(mainMin - transport);
  }
}

write(answers.join('\n'));

// c, m, x(코더, 수학자, 쩌리)
let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.split(EOL)

  main()
})

function main() {
  const q = lines[0]

  for(let i = 0; i < q; i++) {
    const [ c, m, x ] = lines[i + 1].split(/\s/).map(Number)
    const sum = Math.floor((c + m + x) / 3)
    const min = Math.min(c, m)

    console.log(Math.min(sum, min))
  }
}


var n = +readline();

while (n--) {
	var t = +readline();
	print(2);
	var ans = 1;
	var arrCheck = new Array(t + 1);
	var mid = parseInt(t / 2);
	for (var i = 1; i <= mid; i++) {
		var ans = i;
		while (ans <= t && arrCheck[ans] === undefined) {
			write(ans + " ");
			arrCheck[ans] = 1;
			ans *= 2;
		}
	}
	for (var i = 1; i <= t; i++) {
		if (arrCheck[i] === undefined) write(i, " ");
	}
	print();
}

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
// var inf = 1000000000000;
for(var qe=1;qe<=T;qe++) {
  var n = readline();
  // var [a,b] = readline().split(' ').map((x) => parseInt(x));
  console.log(2);
  var ans = [], c = []
  for(var i=1;i<=n;i++) {
    if(c[i] == undefined) {
      for(var j=i;j<=n;j*=2) {
        ans.push(j);
        c[j] = true;
      }
    }
  }
  console.log(ans.join(" "))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    var tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
        let n = parseInt(readline());
        let hsh = Array(n+1).fill(false);
        let res = [];
        for (let j = 1;j <= n;++j) {
            if (hsh[j]) {
                continue;
            }
            for (let i = j;i <= n;i*=2) {
                hsh[i] = true;
                res.push(i);
            }
        }
        console.log(2);
        console.log(res.join(' ').toString());
    }

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let test = 0; test < N; test++) {
        let n = readline();

        let used = {};
        let smallestNotUsed = 3;
        let arr = [1, 2];
        let i = 1;

        while (arr.length < n) {
            let double = arr[i] * 2;
            if (double <= n) {
                arr[i + 1] = double;
                used[double] = true;
            } else {
                arr[i + 1] = smallestNotUsed;
                used[smallestNotUsed] = true;
                let newSmallest = smallestNotUsed + 1;
                while (used[newSmallest]) {
                    newSmallest++;
                }
                smallestNotUsed = newSmallest;
            }
            i++;
        }

        output(2);
        output(arr.join(' '));
    }
}

'use strict';

function solve(n) {
  const res = [],
        set = new Set();
  for (let i = 1; i <= n; i++) {
    if (set.has(i)) continue;
    for (let j = i; j <= n; j *= 2) {
      res.push(j);
      set.add(j);
    }
  }
  return `${2}\n${res.join(' ')}`;
}

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());
      res[i] = solve(n);
    }
    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);
});

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var arr = "";
process.stdin.on("data", function (chunk) {
  arr += chunk;
});

process.stdin.on("end", function () {
  arr = arr.split("\n");
  const testcases = parseInt(arr.shift());

  for (let t = 0; t < testcases; t++) {
    const n = arr[t].split(" ").map((el) => parseInt(el));

    const d = 2;

    const set = new Set();

    const res = [1];

    for (let i = 2; i <= n; i++) {
      if (!set.has(i)) {
        for (let j = i; j <= n; j *= 2) {
          if (!set.has(j)) {
            res.push(j);
            set.add(j);
          }
        }
      }
    }

    console.log(d);
    console.log(res.join(" "));
  }
});

"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--) {
    let n = parseInt(readline());
    if (n === 2) {
      console.log(2);
      console.log(`${1} ${2}`);
      continue;
    } else {
      let res = [],
        obj = {};
      res[0] = 1;
      for (let i = 2; i <= n; i++) {
        if (!obj[i]) {
          obj[i] = 1;
          res.push(i);
          let k = i * 2;
          while (k <= n) {
            obj[k] = 1;
            res.push(k);
            k = k * 2;
          }
        }
      }
      console.log(2);
      console.log(res.join(" "));
    }
  }
};
solve();

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var arr = "";
process.stdin.on("data", function (chunk) {
  arr += chunk;
});

process.stdin.on("end", function () {
  arr = arr.split("\n");
  const testcases = parseInt(arr.shift());

  for (let t = 0; t < testcases; t++) {
    const n = arr[t].split(" ").map((el) => parseInt(el));

    const d = 2;

    const set = new Set();

    const res = [];

    for (let i = 2; i <= n; i++) {
      if (!set.has(i)) {
        for (let j = i; j <= n; j *= 2) {
          if (!set.has(j)) {
            res.push(j);
            set.add(j);
          }
        }
      }
    }

    console.log(d);
    console.log(res.join(" "));
  }
});

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var arr = "";
process.stdin.on("data", function (chunk) {
  arr += chunk;
});

process.stdin.on("end", function () {
  arr = arr.split("\n");
  const testcases = parseInt(arr.shift());

  for (let t = 0; t < testcases; t++) {
    const n = arr[t].split(" ").map((el) => parseInt(el));

    const d = 2;

    const set = new Set();

    const res = [];

    for (let i = 1; i <= n; i = i * 2) {
      res.push(i);
      set.add(i);
    }

    for (let i = 1; i <= parseInt(n / 2); i++) {
      if (!set.has(i)) {
        res.push(i);
        res.push(i * 2);
        set.add(i);
        set.add(i * 2);
      } else {
        set.add(i * 2);
      }
    }

    for (let i = parseInt(n / 2); i <= n; i++) {
      if (!set.has(i)) res.push(i);
    }

    console.log(d);
    console.log(res.join(" "));
  }
});

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var arr = "";
process.stdin.on("data", function (chunk) {
  arr += chunk;
});

process.stdin.on("end", function () {
  arr = arr.split("\n");
  const testcases = parseInt(arr.shift());

  for (let t = 0; t < testcases; t++) {
    const n = arr[t].split(" ").map((el) => parseInt(el));

    const d = 2;

    const set = new Set();

    const res = [];

    for (let i = 1; i <= n; i = i * 2) {
      res.push(i);
      set.add(i);
    }

    for (let i = 1; i <= n; i++) {
      if (!set.has(i)) res.push(i);
    }

    console.log(d);
    console.log(res.join(" "));
  }
});

"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--) {
    let n = parseInt(readline());
    if (n === 2) {
      console.log(2);
      console.log(`${1} ${2}`);
      continue;
    } else {
      let res = [],
        obj = {};
      res[0] = 1;
      for (let i = 2; i <= n; i++) {
        if (!obj[i]) {
          obj[i] = 1;
          res.push(i);
          if (i * 2 <= n) {
            obj[i * 2] = 1;
            res.push(i * 2);
          }
        }
      }
      console.log(2);
      console.log(res.join(" "));
    }
  }
};
solve();

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
// var inf = 1000000000000;
for(var qe=1;qe<=T;qe++) {
  var n = readline();
  // var [a,b] = readline().split(' ').map((x) => parseInt(x));
  console.log(2);
  var ans = [], c = []
  for(var i=1;i<=n;i*=2) {
    ans.push(i);
    c[i] = true;
  }
  for(var i=3;i<=n;i++) {
    if(c[i] == undefined) ans.push(i)
  }
  console.log(ans.join(" "))
}

var n = +readline();

while (n--) {
	var t = +readline();
	print(2);
	var ans = 1;
	var arrCheck = new Array(t + 1);
	var mid = parseInt(t / 2);
	for (var i = 1; i <= mid; i++) {
		var ans = i;
		while (ans <= t && arrCheck[ans] === undefined) {
			write(ans + " ");
			arrCheck[ans] = 1;
			ans *= 2;
		}
	}
	if (t % 2) write(t + " ");
	print();
}

var n = +readline();

while (n--) {
	var t = +readline();
	print(2);
	var ans = 1;
	var arrCheck = new Array(t + 1);
	while (ans <= t) {
		write(ans + " ");
		arrCheck[ans] = 1;
		ans *= 2;
	}

	for (var i = 3; i <= t; i++) {
		if (arrCheck[i] === undefined) write(i + " ");
	}

	print();
}


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

let inputString = '';
let currentLine = 0;

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

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

    C();
});

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

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

    return a;
}

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

        let solve = (i, k, z) => {
            if(k < 0 || z < 0)
                return 0;

            if(i < 0 || i >= n)
                return 0;

            let right = a[i] + solve(i+1, k-1, z);
            let left = a[i] + solve(i-1, k-1, z-1);

            return Math.max(left, right);
        }

        console.log(solve(0, k, z));
    }
}

function C(){
    let t = parseInt(readline());

    while(t > 0){
        t--;
        let max = 0;
        let s = readline();

        for(let i = 0; i < 10; i++){
            for(let j = i; j < 10; j++){
                let pre = -1;
                let len = 0;
                for(let k = 0; k < s.length; k++){
                    if(i === j){
                        if(parseInt(s.charAt(k)) === i){
                            len += 1;
                        }
                    }else{
                        if(parseInt(s.charAt(k)) === i){
                            if(pre !== i){
                                len += 1;
                                pre = i;
                            }
                        }else if(parseInt(s.charAt(k)) === j){
                            if(pre != j){
                                len += 1;
                                pre = j;
                            }
                        }
                    }
                }

                if(i !== j && len % 2 !== 0)
                    len -= 1;

                max = Math.max(max, len);
            }
        }

        console.log(s.length - max);
    }
}

function main(){
    let [n,k] = ti(readline().split(' '));
    let w = new Array(n);
    let v = new Array(n);

    for(let i = 0; i < n; i++){
        let [x,y] = ti(readline().split(' '));
        w[i] = x;
        v[i] = y;
    }

    let dp = new Array(n);
    for(let i = 0; i < n; i++){
        dp[i] = new Array(100001);
        dp[i].fill(99999999999);
    }

    for(let i = 0; i < n; i++){
        for(let j = 0; j < 100001; j++){
            if(i === 0 || j === 0){
                if(i === 0 && j === 0)
                    dp[i][j] = 0;
                else if(i === 0)
                    dp[i][j] = v[0] === j ? w[0] : 99999999999;
            }else{
                dp[i][j] = dp[i-1][j];
                if(j >= v[i])
                    dp[i][j] = Math.min(dp[i][j], w[i] + dp[i-1][j-v[i]]);
            }
        }
    }

    let max = 0;
    for(let i = 100000; i >= 0; i--){
        if(dp[n-1][i] <= k){
            max = i;
            break;
        }
    }

    console.log(max);
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let ans = 0;
    for (let i = 0; i < 10; i++) {
      for (let j = 0; j < 10; j++) {
        let count = 0;
        for (let k = 0; k < str.length; k++) {
          if (count % 2 === 0 && +str[k] === i) {
            count++;
          } else if (count % 2 !== 0 && +str[k] === j) {
            count++;
          }
        }
        if (i !== j && count % 2 !== 0) {
          count = count - 1;
        }
        ans = Math.max(ans, count);
      }
    }
    console.log(`${str.length - ans}`);
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let ans = 0;
    for (let i = 0; i < 10; i++) {
      for (let j = 0; j < 10; j++) {
        let count = 0;
        for (let k = 0; k < str.length; k++) {
          if (k % 2 === 0 && +str[k] === i) {
            count++;
          } else if (k % 2 !== 0 && +str[k] === j) {
            count++;
          }
        }
        if (i !== j) {
          count -= count % 2;
          ans = Math.max(ans, count);
        }
      }
    }
    console.log(`${str.length - ans}`);
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let ans = 0;
    for (let i = 0; i < 10; i++) {
      for (let j = 0; j < 10; j++) {
        let count = 0;
        for (let k = 0; k < str.length; k++) {
          if (k % 2 === 0 && +str[k] === i) {
            count++;
          } else if (k % 2 !== 0 && +str[k] === j) {
            count++;
          }
        }
        if (i !== j) {
          count -= count % 2;
        }
        ans = Math.max(ans, count);
      }
    }
    console.log(`${str.length - ans}`);
  }
}


const mineAllDays = (miners, diamonds) => {
  let res = 0;
  for (let i = 0; i < miners.length; i++) {
    res += Math.sqrt(miners[i] ** 2 + diamonds[i] ** 2);
  }
  return res;
};

const main = () => {
  let test = readInt();
  while (test--) {
    const miners = [];
    const diamonds = [];
    const n = readInt();
    for (let i = 0; i < 2 * n; i++) {
      const [x, y] = readListInt();
      if (x === 0) miners.push(Math.abs(y));
      else diamonds.push(Math.abs(x));
    }
    miners.sort((a, b) => a - b);
    diamonds.sort((a, b) => a - b);
    console.log(mineAllDays(miners, diamonds));
  }
};

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

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

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

  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    // var a = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })

    var x = []
    var y = []
    for (let i = 0; i < 2 * n; i++) {
      var [xx, yy] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
      })

      if (xx === 0) y.push(yy)
      if (yy === 0) x.push(xx)
    }
    x = x.sort((a, b) => Math.abs(a) - Math.abs(b))
    y = y.sort((a, b) => Math.abs(a) - Math.abs(b))
    // console.log(x)
    // console.log(y)
    var sum = 0
    for (let i = 0; i < n; i++) {
      sum += Math.sqrt(x[i] * x[i] + y[i] * y[i])
    }
    console.log(sum)

  })
}

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

  return gcd(b, a % b);
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var alist = [];
		var blist = [];
		for(var j = 0; j < 2 * N; j++){
			var x = nextInt();
			var y = nextInt();
			if(x != 0){
				blist.push({
					x : x,
					y : y
				});
			}else{
				alist.push({
					x : x,
					y : y
				});
			}
		}
		alist.sort(function(a,b){
			return Math.abs(a.y) - Math.abs(b.y);
		});
		blist.sort(function(a,b){
			return Math.abs(a.x) - Math.abs(b.x);
		});
		var sum = 0;

		for(var j = 0; j < N; j++){
			sum += Math.sqrt(alist[j].y * alist[j].y + blist[j].x * blist[j].x);
		}
		myout(sum);
	}
}

"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 getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let min = [],
      dia = [];
    for (let i = 0; i < n * 2; i++) {
      let k = iInpArr();
      if (k[0] === 0) min.push([k[0], Math.abs(k[1])]);
      else dia.push([Math.abs(k[0]), k[1]]);
    }
    min.sort((a, b) => a[1] - b[1]);
    dia.sort((a, b) => a[0] - b[0]);
    let sum = 0;
    for (let i = 0; i < n; i++) {
      let k = min[i][1] * min[i][1] + dia[i][0] * dia[i][0];
      sum += Math.sqrt(k);
    }
    console.log(sum + "");
  }
};
solve();