This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.Paul and Mary have a favorite string $$$s$$$ which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met:  each letter of the string is either painted in exactly one color (red or green) or isn't painted;  each two letters which are painted in the same color are different;  the number of letters painted in red is equal to the number of letters painted in green;  the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions. E. g. consider a string $$$s$$$ equal to "kzaaa". One of the wonderful colorings of the string is shown in the figure.    The example of a wonderful coloring of the string "kzaaa". Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find $$$k$$$ — the number of red (or green, these numbers are equal) letters in a wonderful coloring.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one non-empty string $$$s$$$ which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed $$$50$$$.

For each test case, output a separate line containing one non-negative integer $$$k$$$ — the number of letters which will be painted in red in a wonderful coloring.

NoteThe first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing $$$3$$$ or more red letters because the total number of painted symbols will exceed the string's length.The string from the second test case can be painted as follows. Let's paint the first occurrence of each of the letters "c", "o", "e" in red and the second ones in green. Let's paint the letters "d", "f" in red and "r", "s" in green. So every letter will be painted in red or green, hence the answer better than $$$5$$$ doesn't exist.The third test case contains the string of distinct letters, so you can paint any set of characters in red, as long as the size of this set doesn't exceed half of the size of the string and is the maximum possible.The fourth test case contains a single letter which cannot be painted in red because there will be no letter able to be painted in green.The fifth test case contains a string of identical letters, so there's no way to paint more than one letter in red.

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var repeted = new Map();
        var nrepeted = new Map();
        var ans = 0;
        var a = 0;
        var k = lines[i].split('');
        for(j = 0; j < k.length; j++){
            if(nrepeted.get(k[j]) == 1){
                ans++;
                nrepeted.set(k[j], 0);
                a++;
                repeted.set(k[j], 1);
            }else if(repeted.get(k[j]) === undefined){
                nrepeted.set(k[j], 1);
            }
        }
        ans += Math.floor((nrepeted.size - a) / 2);
        console.log(ans);
    }
});

"use strict";

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

let _inputString = '';
let _currentLine = 0;

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

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

const readLine = () => _inputString[_currentLine++];

const nextIntArray = () => readLine.split(" ").map(x => parseInt(x));
const nextFloatArray = () => readLine.split(" ").map(x => parseFloat(x));
const nextInt = () => parseInt(readLine());

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

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

function solve() {
    let string = readLine();
    let cnt = {}
    for (let i = 0; i < string.length; i++) {
        let char = string[i];
        if (!(char in cnt)) {
            cnt[char] = 0;
        }
        cnt[char]++;
    }
    let c = 0, ones = 0;
    for (let char in cnt) {
        if (cnt[char] >= 2) {
            c++;
        } else if (cnt[char] === 1) {
            ones++;
        }
    }
    print(c + Math.floor(ones / 2));
}

function main() {
    let testCases = 1;
    testCases = parseInt(readLine());
    for (let i = 0; i < testCases; i++) {
        solve();
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let str = readLine();
    let map = new Map();
    if (str.length == 1) return 0;
    for (let i = 0; i < str.length; i++) {
        const element = str[i];
        if (map.has(element)) map.set(element, map.get(element) + 1)
        else map.set(element, 1)
    }
    let res = Array.from(map.values()).reduce((acc, cur) => {
        if (cur > 1)
            return acc + 2;
        return acc + 1;

    }, 0)
    return parseInt(res / 2);
}

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let a = nl.line().split('');
		let r = new Array(26);
		a.forEach((e) => {
			let x = e.charCodeAt(0) - 'a'.charCodeAt(0);
			if (r[x]) {
				r[x]++;
			} else {
				r[x] = 1;
			}
		});
		let cnt = r.reduce((ac, e) => ac + (e?(e>2?2:e):0), 0);
		ans.push(Math.floor(cnt / 2));
	}
	console.log(ans.join('\n'));
};

process.stdin.on('end', sol);

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 a = rl();
		const n = a.length;
		const k = 2;

		const mp = new Map();
		for (let i = 0; i < n; i++) {
			if (mp.has(a[i]))
				mp.get(a[i]).push(i);
			else
				mp.set(a[i], [i]);
		}

		const avl = [];
		for (const [elm, indxs] of mp) {
			for (let i = 0 ; i < indxs.length && i < k; i++) {
				avl.push(indxs[i]);
			}
		}

		const cnt = Math.floor(avl.length/k)*k/2;

		console.log(cnt);
	}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let str = input[z++].trim().split('');
        let obj = {};
        let result = 0;
        let oneCount = 0;
        for (let i = 0; i < str.length; i++) {
            if(!obj[str[i]]){
                obj[str[i]] = 1;
            }
            else obj[str[i]]++;
        }

        for (const key in obj) {
            if(obj[key] == 1) oneCount++;
            else if(obj[key] > 1) result++;
        }
        result += Math.floor(oneCount / 2);
        //console.log(obj);
        console.log(result);
    }
}

const fs = require('fs');

const input = String(fs.readFileSync(0))
  .split('\n')
  .filter(Boolean)
  .map((str) => str.trim());

for (let i = 1; i < input.length; i += 1) {
  const str = input[i];

  console.log(solve(str));
}

function solve(str) {
  let rcount = 0;
  const counts = {};

  str.split('').forEach((ch) => {
    if (!counts[ch]) {
      counts[ch] = 1;
    } else {
      counts[ch] += 1;
    }
  });

  let lonerCount = 0;

  Object.values(counts).forEach((count) => {
    if (count === 1) {
      lonerCount += 1;
    } else {
      rcount += 1;
    }
  });

  return rcount + Math.floor(lonerCount / 2);
}

let i = ''
let lines;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    lines = i.split('\r\n'); // your input text, split by lines
    main();
});

function main() {
  let t = parseInt(lines.shift());

  while (t > 0) {
    let a = lines.shift().split('');

    if (a.length === 1) {
      console.log(0);
    } else if (new Set(a).size === a.length) {
      console.log(Math.floor(a.length / 2));
    } else {
      const repeat = new Set();
      let unique = 0;
      for (letter of a) {
        const occurr = a.reduce((prev, curr) => (curr === letter ? prev + 1 : prev), 0);
        if (occurr > 1) {
          repeat.add(letter);
        } else {
          unique++;
        }
      }
      console.log(repeat.size + Math.floor(unique / 2));
    }

    t--;
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL);

  // iter lines
  const cases = lines[0] - 0;
  const ans = [];

  for (let i = 1; i <= cases; i++) {
    const map = {};
    // read line and split by '' and count each char as map
    lines[i].split('').map(c => (map[c] = (map[c] || 0) + 1));
    // print map
    // console.log(map);
    // count number of chars that have appear more than once and remove that char from map
    const mores = Object.keys(map).filter(c => map[c] >= 2).length;
    const less = Object.keys(map).filter(c => map[c] < 2);
    // console.log(mores);
    // less div 2 floor
    // console.log(Math.floor(less.length / 2));
    ans.push(mores + Math.floor(less.length / 2));
  }

  // console.log(ans);
  // print ans each line
  for (let i = 0; i < ans.length; i++) {
    console.log(ans[i]);
  }

})

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 07/23/21 morning
 * https://codeforces.com/contest/1551/problem/B
 */
const solve = (s) => {
    // pr(s)
    let m = counter(s);
    // pr(m);
    let used = new Set();
    let red = green = 0;
    for (const [c, occ] of m) {
        if (used.has(c)) continue;
        if (occ >= 2) {
            red++;
            green++;
            m.delete(c);
        }
        used.add(c);
    }
    // pr(red, green);
    // pr(m);
    let n = m.size;
    let rest = n & 1 ? (n - 1) / 2: n / 2;
    pr(red + rest)
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i]);
            i++;
        }
    });
};

main()

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 l = 0
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        var str = lines[l++]
        console.log(solve(str))
    }
});

function solve(str) {
    const map = {}
    for (let i = 0; i < str.length; i++) {
        const ch = str[i]
        map[ch] = (map[ch] || 0) + 1
    }

    let a = 0
    let b = 0
    for (let k in map) {
        const count = map[k]
        if (count > 1) {
            a++
        } else {
            b++
        }
    }
    return a + Math.floor(b / 2)
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    var aCode = 'a'.charCodeAt(0);
    for (var i = 0; i < str.length; i++)
        letters[str.charCodeAt(i) - aCode]++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(k);
}

const readNum = () => +readline();
const readStr = () => readline();
const readNumArr = () => readline().split(' ').map(item => +item);
const createEmptyArr = (number) => new Array(number).fill(0);

function wonderfulColoring(str) {
  var l = createEmptyArr(26);

  for(var j = 0; j < str.length; j++) {
    l[str[j].charCodeAt(0)-'a'.charCodeAt(0)]++;
  }

  var c1 = 0, c2 = 0;

  for(var j = 0; j < l.length; j++) {
    if(!l[j]) {
      continue;
    }
    if(l[j] > 1) {
      c1++;
      continue;
    }
    c2++;
  }

  return Math.floor(c1 + c2 / 2);
}

const n = readNum();

for(var i = 0; i < n; i++) {
  print(wonderfulColoring(readStr()));
}

const readNum = () => +readline();
const readStr = () => readline();
const readNumArr = () => readline().split(' ').map(item => +item);

const n = readNum();

for(var i = 0; i < n; i++) {
  var str = readStr();
  var l = [];

  for(var j=0; j<26; j++) {
    l[j]=0;
  }

  for(var j = 0; j < str.length; j++) {
    l[str[j].charCodeAt(0)-'a'.charCodeAt(0)]++;
  }

  var c1 = 0, c2 = 0;

  for(var j = 0; j < l.length; j++) {
    if(!l[j]) {
      continue;
    }
    if(l[j] > 1) {
      c1++;
      continue;
    }
    c2++;
  }

  print(Math.floor(c1 + c2 / 2));
}

const readNum = () => +readline();
const readStr = () => readline();
const readNumArr = () => readline().split(' ').map(item => +item);

const n = readNum();

for(var i = 0; i < n; i++) {
  var str = readStr();
  var l = {};

  for(var j = 0; j < str.length; j++) {
    l[str[j]] = l[str[j]] ? l[str[j]] + 1 : 1;
  }

  var keys = Object.keys(l);

  var c1 = 0, c2 = 0;

  for(var j = 0; j < keys.length; j++) {
    if(l[keys[j]] > 1) {
      c1++;
      continue;
    }
    c2++;
    if(c2 === 2) {
      c2 = 0;
      c1++;
    }
  }

  print(c1);
}

const readNum = () => +readline();
const readStr = () => readline();
const readNumArr = () => readline().split(' ').map(item => +item);

const n = readNum();

for(var i = 0; i < n; i++) {
  var str = readStr();
  var l = {};

  for(var j = 0; j < str.length; j++) {
    l[str[j]] = l[str[j]] ? l[str[j]] + 1 : 1;
  }

  var keys = Object.keys(l);

  var c1 = 0, c2 = 0;

  for(var j = 0; j < keys.length; j++) {
    if(l[keys[j]] > 1) {
      c1++;
      continue;
    }
    c2++;
  }

  print(Math.floor(c1 + c2 / 2));
}

var t = readline();
while(t--)
{
    var s = readline();
    var arr = new Array(26);
    for(var i=0;i<26;i++)
    {
        arr[i]=0;
    }
    for(var i=0;i<s.length;i++)
    {
        arr[s[i].charCodeAt(0)-'a'.charCodeAt(0)]++;
    }
    var res=0,temp=0;
    arr.forEach(x => {
        if(x>1)
        {
            res++;
        }
        else if(x==1)
        {
            temp++;
            if(temp==2)
            {
                res++;
                temp=0;
            }
        }
    });
    print(res);
}

var input = readline();
for(var i  = 0; i < input; i ++) {
    var arr = readline().split('').sort();
    var sum = 1;
    var len =arr.length;
    for(var j = 1; j < arr.length ; j ++) {
       if(arr[j] === arr[j - 1]) sum ++;
       else {
           if(sum > 2) len -= sum - 2;
           sum = 1;
       }
    }
    if(sum > 2) len -= sum - 2;
    print(Math.floor(len / 2));
}

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*/
    var n = lines[0];
    var a = 0;
    for(var l = 1; l <= n; l++){
        var k = lines[l].split('');
        for(var j = 1; j <= n; j++){
            if(k[j] == j[j-1]){
                a++;
            }
        }
        if(Number(a) == Number(k.length)){
            console.log(1);
        }else{
            console.log(Math.floor(k.length / 2));
        }
    }
});

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*/
    var n = lines[0];
    var a = 0;
    for(var l = 1; l <= n; l++){
        var k = lines[l].split('');
        for(var j = 1; j <= n; j++){
            if(k[j] == j[j-1]){
                a++;
            }
        }
        if(a == k.length){
            console.log(1);
        }else{
            console.log(Math.floor(k.length / 2));
        }
    }
});

"use strict";

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

let _inputString = '';
let _currentLine = 0;

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

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

const readLine = () => _inputString[_currentLine++];

const nextIntArray = () => readLine.split(" ").map(x => parseInt(x));
const nextFloatArray = () => readLine.split(" ").map(x => parseFloat(x));
const nextInt = () => parseInt(readLine());

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

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

function solve() {
    let string = readLine();
    let cnt = {}
    for (let i = 0; i < string.length; i++) {
        cnt[string[i]] = 0;
    }
    for (let i = 0; i < string.length; i++) {
        let char = string[i];
        cnt[char]++;
    }
    let c = 0;
    for (let char in cnt) {
        if (cnt[char] >= 2) {
            c++;
        }
    }
    print(c);
}

function main() {
    let testCases = 1;
    testCases = parseInt(readLine());
    for (let i = 0; i < testCases; i++) {
        solve();
    }
}

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

const readLine = () => _inputString[_currentLine++];

const nextIntArray = () => readLine.split(" ").map(x => parseInt(x));
const nextFloatArray = () => readLine.split(" ").map(x => parseFloat(x));
const nextInt = () => parseInt(readLine());

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

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

function solve() {
    let string = readLine();
    let cnt = {}
    for (let i = 0; i < string.length; i++) {
        let char = string[i];
        cnt[char]++;
    }
    let c = 0;
    for (let char in cnt) {
        if (cnt[char] >= 2) {
            c++;
        }
    }
    print(c);
}

function main() {
    let testCases = 1;
    testCases = parseInt(readLine());
    for (let i = 0; i < testCases; i++) {
        solve();
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let str = readLine();
    let mid = parseInt(str.length / 2);
    let map = new Map();
    if (str.length == 1) return 0;
    map.set(1, new Set());
    map.set(0, new Set());
    for (let i = 0; i < str.length; i++) {
        const element = str[i];
        if (map.get(1).size != mid && !map.get(1).has(element)) {
            map.get(1).add(element);
        } else if (map.get(0) != mid && !map.get(0).has(element)) {
            map.get(0).add(element);
        }
    }
    return map.get(1).size;
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    var aCode = 'a'.charCodeAt(0);
    for (var i = 0; i < str.length; i++)
        letters[str.charCodeAt(i) - aCode]++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(str.charCodeAt(0) - aCode);
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    var aCode = 'a'.charCodeAt(0);
    for (var i = 0; i < str.length; i++)
        letters[str.charCodeAt(i) - aCode]++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(str.charCodeAt(i) - aCode);
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    for (var i = 0; i < str.length; i++)
        letters[str[i] - 'a']++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(str[0]);
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    for (var i = 0; i < str.length; i++)
        letters[str[i] - 'a']++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(str[0] - 'a');
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    for (var i = 0; i < str.length; i++)
        letters[str[i] - 'a']++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(letters.length);
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    for (var i = 0; i < str.length; i++)
        letters[str[i] - 'a']++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(k);
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = [new Array(26)];
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    for (var i = 0; i < str.length; i++)
        letters[str[i] - 'a']++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.min(2, letters[i]);

    k = Math.floor(k / 2);

    print(k);
}

var n = readline();
for (var r = 0; r < n; r++) {
    var str = readline();
    var letters = new Array(26);
    for (var i = 0; i < 26; i++)
        letters[i] = 0;

    for (var i = 0; i < str.length; i++)
        letters[str[i] - 'a']++;

    var k = 0;
    for (var i = 0; i < letters.length; i++)
        k += Math.max(2, letters[i]);

    k = Math.floor(k / 2);

    print(k);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    var letters = {};
    var redCount = 0;
    var greenCount = 0;
    for (var x = 0; x < str.length; x++) {
        if (!letters[str[x]])
            letters[str[x]] = [];

        if (redCount > greenCount) {
            if (!letters[str[x]].includes('g')) {
                greenCount++;
                letters[str[x]].push('g')
            } else if (!letters[str[x]].includes('r')) {
                redCount++;
                letters[str[x]].push('r')
            }
        } else {
            if (!letters[str[x]].includes('r')) {
                redCount++;
                letters[str[x]].push('r')
            } else if (!letters[str[x]].includes('g')) {
                greenCount++;
                letters[str[x]].push('g')
            }
        }
    }
    if (redCount > greenCount) redCount--;
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    var letters = {};
    var redCount = 0;
    var greenCount = 0;
    for (var x = 0; x < str.length; x++) {
        if (!letters[str[x]])
            letters[str[x]] = [];

        if (redCount > greenCount) {
            if (!letters[str[x]].includes('g')) {
                greenCount++;
                letters[str[x]].push('g')
            } else if (!letters[str[x]].includes('r')) {
                redCount++;
                letters[str[x]].push('r')
            }
        } else {
            if (!letters[str[x]].includes('r')) {
                redCount++;
                letters[str[x]].push('r')
            } else if (!letters[str[x]].includes('g')) {
                greenCount++;
                letters[str[x]].push('g')
            }
        }
    }
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    //var letters = Array.from({ length: 26 }, 0);
    var letters = {};
    var redCount = 0;
    for (var x = 0; x < str.length; x++) {
        if (!letters[str[x]])
            letters[str[x]] = 0;
        if (letters[str[x]] === 0) {
            redCount++;
            letters[str[x]]++;
        } else if (letters[str[x]] === 1) {
            letters[str[x]]++;
        }
    }
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    //var letters = Array.from({ length: 26 }, 0);
    var letters = {};
    var redCount = 0;
    for (var x = 0; x < str.length; x++) {
        // var index = str[x] - 'a';
        if (!letters[str[x]])
            letters[str[x]] = 0;
        print(letters[str[x]])
        if (letters[str[x]] === 0) {
            redCount++;
            letters[str[x]]++;
        } else if (letters[str[x]] === 1) {
            letters[str[x]]++;
        }
    }
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    //var letters = Array.from({ length: 26 }, 0);
    var letters = {};
    var redCount = 0;
    for (var x = 0; x < str.length; x++) {
        // var index = str[x] - 'a';
        if (letters[str[x]])
            letters[str[x]] = 0;
        print(str[x])
        if (letters[str[x]] === 0) {
            redCount++;
            letters[str[x]]++;
        } else if (letters[str[x]] === 1) {
            letters[str[x]]++;
        }
    }
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    //var letters = Array.from({ length: 26 }, 0);
    var letters = {};
    var redCount = 0;
    for (var x = 0; x < str.length; x++) {
        // var index = str[x] - 'a';
        if (letters[str[x]])
            letters[str[x]] = 0;
        print(letters['k'])
        if (letters[str[x]] === 0) {
            redCount++;
            letters[str[x]]++;
        } else if (letters[str[x]] === 1) {
            letters[str[x]]++;
        }
    }
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    //var letters = Array.from({ length: 26 }, 0);
    var letters = {};
    var redCount = 0;
    for (var x = 0; x < str.length; x++) {
        // var index = str[x] - 'a';
        if (letters[str[x]])
            letters[str[x]] = 0;
        print(letters)
        if (letters[str[x]] === 0) {
            redCount++;
            letters[str[x]]++;
        } else if (letters[str[x]] === 1) {
            letters[str[x]]++;
        }
    }
    print(redCount);
}

var n = readline();
for (var i = 0; i < n; i++) {
    var str = readline();
    //var letters = Array.from({ length: 26 }, 0);
    var redCount = 2;
    // for (var x = 0; x < str.length; x++) {
    //     var index = str[x] - 'a';
    //     if (letters[index] === 0) {
    //         redCount++;
    //         letters[index]++;
    //     } else if (letters[index] === 1) {
    //         letters[index]++;
    //     }
    // }
    print(redCount);
}

var t = readline();
while(t--)
{
    var s = readline();
    var arr = new Array(26);
    for(var i=0;i<s.length;i++)
    {
        arr[s[i].charCodeAt(0)-'a'.charCodeAt(0)]++;
    }
    var res=0,temp=0;
    arr.forEach(x => {
        if(x>1) res++;
        else if(temp==2)
        {
            res++;
            temp=0;
        }
        else temp++;
    });
    print(res);
}

var input = readline();
for(var i  = 0; i < input; i ++) {
    var arr = readline().split('').sort();
    var sum = 1;
    var len =arr.length;
    for(var j = 1; j < arr.length ; j ++) {
       if(arr[j] === arr[j - 1]) sum ++;
       else {
           if(sum > 2) len -= sum - 2;
           sum = 0;
       }
    }
    if(sum > 2) len -= sum - 2;
    print(Math.floor(len / 2));
}


Eugene likes working with arrays. And today he needs your help in solving one challenging task.An array $$$c$$$ is a subarray of an array $$$b$$$ if $$$c$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.Let's call a nonempty array good if for every nonempty subarray of this array, sum of the elements of this subarray is nonzero. For example, array $$$[-1, 2, -3]$$$ is good, as all arrays $$$[-1]$$$, $$$[-1, 2]$$$, $$$[-1, 2, -3]$$$, $$$[2]$$$, $$$[2, -3]$$$, $$$[-3]$$$ have nonzero sums of elements. However, array $$$[-1, 2, -1, -3]$$$ isn't good, as his subarray $$$[-1, 2, -1]$$$ has sum of elements equal to $$$0$$$.Help Eugene to calculate the number of nonempty good subarrays of a given array $$$a$$$.

The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 2 \times 10^5$$$)  — the length of array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$)  — the elements of $$$a$$$.

Output a single integer  — the number of good subarrays of $$$a$$$.

NoteIn the first sample, the following subarrays are good: $$$[1]$$$, $$$[1, 2]$$$, $$$[2]$$$, $$$[2, -3]$$$, $$$[-3]$$$. However, the subarray $$$[1, 2, -3]$$$ isn't good, as its subarray $$$[1, 2, -3]$$$ has sum of elements equal to $$$0$$$.In the second sample, three subarrays of size 1 are the only good subarrays. At the same time, the subarray $$$[41, -41, 41]$$$ isn't good, as its subarray $$$[41, -41]$$$ has sum of elements equal to $$$0$$$.

const ascending = (x, y) => x - y;
const descending = (x, y) => y - x;
const log = console.log;

function solve(input) {
    input = input.toString().split(/\r?\n/);

    let inputRow = 0;
    let n = +input[inputRow++];
    let a = input[inputRow++].split(' ').map(x => +x);

    let ans = 0;
    let d = {};
    let offset = 0;
    let lpos = -1;
    for (let i = 0; i < n; i++) {

        let pos = d[-a[i] - offset];
        if (a[i] == 0) {
            lpos = i;
        } else if (typeof(pos) !== 'undefined') {
            // log('pos = ' + pos);
            lpos = Math.max(lpos, pos);
        }
        ans += i - lpos;

        d[-offset] = i;
        offset += a[i];
        // log(d, offset, ans);

    }

    let res = [];
    res.push(ans);
    return res.join('\n');
}

async function main() {

    try {

        let input = await new Promise(resolve => {

            let _input = '';
            process.stdin.resume();
            process.stdin.setEncoding('utf-8');
            process.stdin.on('data', (buf) => {
                _input += buf;
            });
            process.stdin.on('end', () => {
                resolve(_input);
            });

        });
        let output = solve(input);

        console.log(output);

    } catch (err) {
        console.error(err);
    }
}

main();

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

function solve(n, a) {
  let sum = 0;
  let myMap = new Map([[0, -1]]);
  let count = 0;
  let limit = -2;
  a.forEach((val, i) => {
    sum += val;
    if (myMap.has(sum)) {
      const begin = myMap.get(sum);
      limit = Math.max(limit, begin);
    }
    count += i - limit - 1;
    myMap.set(sum, i);
  })
  return count;
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const n = readLine()[0];
  const a = readLine();
  console.log(solve(n, a));
}

const ascending = (x, y) => x - y;
const descending = (x, y) => y - x;
const log = console.log;

function solve(input) {
    input = input.toString().split(/\r?\n/);

    let inputRow = 0;
    let n = +input[inputRow++];
    let a = input[inputRow++].split(' ').map(x => +x);

    let ans = 0;
    let d = {};
    let offset = 0;
    for (let i = 0; i < n; i++) {

        let pos = d[-a[i] - offset];
        if (typeof(pos) !== 'undefined') {
            // log('pos = ' + pos);
            ans += i - pos;
        } else {
            ans += i + 1;
        }

        d[-offset] = i;
        offset += a[i];
        // log(d, offset, ans);

    }

    let res = [];
    res.push(ans);
    return res.join('\n');
}

async function main() {

    try {

        let input = await new Promise(resolve => {

            let _input = '';
            process.stdin.resume();
            process.stdin.setEncoding('utf-8');
            process.stdin.on('data', (buf) => {
                _input += buf;
            });
            process.stdin.on('end', () => {
                resolve(_input);
            });

        });
        let output = solve(input);

        console.log(output);

    } catch (err) {
        console.error(err);
    }
}

main();

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

function solve(n, a) {
  let sum = 0;
  let myMap = new Map([[0, -1]]);
  let count = 0;
  a.forEach((val, i) => {
    sum += val;
    if (myMap.has(sum)) {
      const begin = myMap.get(sum);
      count += i - begin - 1;
    }
    else count += i + 1;
    myMap.set(sum, i);
  })
  return count;
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const n = readLine()[0];
  const a = readLine();
  console.log(solve(n, a));
}


A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:  ai ≥ ai - 1 for all even i,  ai ≤ ai - 1 for all odd i > 1. For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted.Can you make the array z-sorted?

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array a. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.

If it's possible to make the array a z-sorted print n space separated integers ai — the elements after z-sort. Otherwise print the only word "Impossible".

 //var arr = [1,3, 2, 2 ,5,34];
//var n = [6];

var n = Number(readline());
var arr = readline().split(' ').map(Number);
var impossible = 'impossible';

arr.sort(function(a,b){return a-b;});

var res = [];

while(arr.length){
   res.push(arr.shift());
   res.push(arr.pop());
}

if(n % 2){
   res = res.slice(0,n);
}

res.map(function(i){print(i)+' ';});

//console.log(res);

var n = readline();
var arr = readline().split(" ");
arr.sort(function(a,b){
	return a-b;
});
var res = [];
var q = n-1;
var p = 0;

for(var i = 0; i < n; i++){
	if(i&1) res.push(arr[q--]);
	else res.push(arr[p++]);
}
print(res.join(' '));

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));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let ok = true;
  const result = [];

  arr.sort((a, b) => a - b);

  for (let i = 1, j = len - 1; i < len; i += 2) {
    result[i] = arr[j--];
  }

  for (let i = 0, j = 0; i < len; i += 2) {
    result[i] = arr[j++];
  }

  for (let i = 1; i < len; i++) {
    if (i % 2 === 1) {
      if (result[i] < result[i - 1]) {
        ok = false;
        break;
      }
    } else {
      if (result[i] > result[i - 1]) {
        ok = false;
        break;
      }
    }
  }

  if (ok) {
    console.log(result.join(" "));
  } else {
    console.log("Impossible");
  }
}

var n = readline();
var arr = readline().split(" ");

arr.sort();
var res = [];
var q = n-1;
var p = 0;
for(var i = 0; i < n; i++){
	if(i&1) res.push(arr[q--]);
	else res.push(arr[p++]);
}
print(res.join(' '));

var n = readline();
var arr = readline().split(" ");

arr.sort();
var res = [];
var q = n-1;
var p = 0;
for(var i = 0; i < n; i++){
	if(i&1) res.push(arr[p++]);
	else res.push(arr[q--]);
}
print(res.join(' '));

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));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));

  arr.sort((a, b) => a - b);
  const odds = arr.filter((num, i) => i % 2 !== 0);

  for (let i = 0; i < len; i++) {
    if (i % 2 !== 0) {
      arr[i] = odds.pop();
    }
  }

  console.log(arr.join(" "));
}

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));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let ok = true;

  arr.sort((a, b) => a - b);

  for (let i = 1, j = len - 1; i <= len; i++) {
    if (i % 2 === 0) {
      [arr[i - 1], arr[j]] = [arr[j], arr[i - 1]];
      j--;
    }
  }

  for (let i = 1; i < len; i++) {
    if (i % 2 === 1) {
      if (arr[i] < arr[i - 1]) {
        ok = false;
        break;
      }
    } else {
      if (arr[i] > arr[i - 1]) {
        ok = false;
        break;
      }
    }
  }

  if (ok) {
    console.log(arr.join(" "));
  } else {
    console.log(arr.join("Impossible"));
  }
}


You are given an array $$$a$$$ of length $$$n$$$ consisting of integers. You can apply the following operation, consisting of several steps, on the array $$$a$$$ zero or more times:   you select two different numbers in the array $$$a_i$$$ and $$$a_j$$$;  you remove $$$i$$$-th and $$$j$$$-th elements from the array. For example, if $$$n=6$$$ and $$$a=[1, 6, 1, 1, 4, 4]$$$, then you can perform the following sequence of operations:   select $$$i=1, j=5$$$. The array $$$a$$$ becomes equal to $$$[6, 1, 1, 4]$$$;  select $$$i=1, j=2$$$. The array $$$a$$$ becomes equal to $$$[1, 4]$$$. What can be the minimum size of the array after applying some sequence of operations to it?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) is length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output the minimum possible size of the array after applying some sequence of operations to it.

function getInt( num ) {
    return parseInt( num, 10 );
}

var t = parseInt( readline(), 10 );

for ( var i = 0; i < t; i++ ) {
    var line1 = readline();
    var line2 = readline().split(' ').map(getInt);
    var sol = solution(line2)
    print( sol );
}
function solution( arr) {
    var n = arr.length;

    var mapCount = {};
    var max = 0;
    arr.forEach(function(num){
        mapCount[num] = (mapCount[num] || 0) + 1;
        if(mapCount[num] > max){
            max = mapCount[num];
        }
    })
    if(max > n/2){
        var rest = n - max;
        return n - rest * 2;
    }
    return n % 2

}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function j(arr) {
   while(arr[arr.length - 1] === 0) {
      arr.pop();
   }
}

function add(heap, elem) {
   var i = heap.length;
   heap.push(elem);
   while(i > 0) {
      var nextI = (i - 1) >> 1;
      if (heap[i] <= heap[nextI]) {
         break;
      }
      var t = heap[i];
      heap[i] = heap[nextI];
      heap[nextI] = t;
      i = nextI;
   }
}

function extract(heap) {
   var result = heap[0];
   var i = 0;
   while (heap[i]) {
      var il = (i + 1) << 1;
      var ir = il - 1;
      if (heap[il]) {
         if (heap[ir]) {
            if (heap[il] > heap[ir]) {
               heap[i] = heap[il];
               i = il;
            } else {
               heap[i] = heap[ir];
               i = ir;
            }
         } else {
            heap[i] = heap[il];
            i = il;
         }
      } else {
         if (heap[ir]) {
            heap[i] = heap[ir];
            i = ir;
         } else {
            heap[i] = 0;
         }
      }
   }
   j(heap);
   return result;
}

function solve() {
   read();
   var o = {};
   readArray(Number).forEach(number => {
      if (o[number]) {
         o[number]++;
      } else {
         o[number] = 1;
      }
   });
   var heapArr = [];
   Object.values(o).forEach(x => add(heapArr, x));
   while(true) {
      var n1 = extract(heapArr);
      var n2 = extract(heapArr);
      if (!n2) {
         write(n1 || 0);
         return;
      }
      if (n1 > 1) {
         add(heapArr, n1 - 1);
      }
      if (n2 > 1) {
         add(heapArr, n2 - 1);
      }
   }
}

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

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function add(heap, elem) {
   var i = heap.length;
   heap.push(elem);
   while(i > 0) {
      var nextI = (i - 1) >> 1;
      if (heap[i] <= heap[nextI]) {
         break;
      }
      var t = heap[i];
      heap[i] = heap[nextI];
      heap[nextI] = t;
      i = nextI;
   }
}

function extract(heap) {
   var result = heap[0];
   var i = 0;
   while (heap[i]) {
      var il = (i + 1) << 1;
      var ir = il - 1;
      if (heap[il]) {
         if (heap[ir]) {
            if (heap[il] > heap[ir]) {
               heap[i] = heap[il];
               i = il;
            } else {
               heap[i] = heap[ir];
               i = ir;
            }
         } else {
            heap[i] = heap[il];
            i = il;
         }
      } else {
         if (heap[ir]) {
            heap[i] = heap[ir];
            i = ir;
         } else {
            heap[i] = 0;
         }
      }
   }
   return result;
}

function solve() {
   read();
   var o = {};
   readArray(Number).forEach(number => {
      if (o[number]) {
         o[number]++;
      } else {
         o[number] = 1;
      }
   });
   var heapArr = [];
   Object.values(o).forEach(x => add(heapArr, x));
   while(true) {
      var n1 = extract(heapArr);
      var n2 = extract(heapArr);
      if (!n2) {
         write(n1);
         return;
      }
      if (n1 > 1) {
         add(heapArr, n1 - 1);
      }
      if (n2 > 1) {
         add(heapArr, n2 - 1);
      }
   }
}

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

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

const solve = (a) => {
  const count = {};
  let maxCount = 0;
  for (const item of a) {
    if (!count.hasOwnProperty(item)) count[item] = 0;
    count[item]++;
    maxCount = Math.max(maxCount, count[item]);
  }
  if (Object.keys(count).length === 1) return a.length;
  const diff = 2 * maxCount - a.length;
  if (diff > 0) return diff;
  return a.length % 2;
};

const main = () => {
  let t = readInt();
  while (t--) {
    const n = readInt();
    const a = readListInt();
    console.log(solve(a));
  }
};

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

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    let j = 1;
    for (let i = 1; i <= t; i++) {
        var n = Number(input[j]);
        j++;
        var arr = input[j].split(" ").map((i) => {
            return Number(i);
        });
        j++;
        function minTransform(n, arr) {
            var map = new Map();
            var max = 0;
            for (var i = 0; i < arr.length; i++) {
                if (map.has(arr[i])) {
                    map.set(arr[i], map.get(arr[i]) + 1);
                } else {
                    map.set(arr[i], 1);
                }
                max = Math.max(max, map.get(arr[i]));
            }
            if (2 * max <= n) {
                return n % 2;
            }
            return max - (n - max);
        }
        console.log(minTransform(n, arr));
    }
})

'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 = 998244353n
var maxN = 10e6 + 1

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

    for (let i = 0; i < n; i++) {
      if (!object[a[i]]) object[a[i]] = 0
      object[a[i]]++
    }
    var max = 0
    Object.keys(object).map(key => {
      key = parseInt(key)
      max =Math.max(object[key], max)
    })
var value = max - (n-max)
    if(value>0) {
      return console.log(value)
    } else {
      console.log(n% 2)
    }
    // console.log(object)
    // console.log(max, Math.floor(n/2))
    // console.log()
  })
}

function longestCommonSubstring(string1, string2) {
  // Convert strings to arrays to treat unicode symbols length correctly.
  // For example:
  // '𐌵'.length === 2
  // [...'𐌵'].length === 1
  const s1 = [...string1];
  const s2 = [...string2];

  // Init the matrix of all substring lengths to use Dynamic Programming approach.
  const substringMatrix = Array(s2.length + 1).fill(null).map(() => {
    return Array(s1.length + 1).fill(null);
  });

  // Fill the first row and first column with zeros to provide initial values.
  for (let columnIndex = 0; columnIndex <= s1.length; columnIndex += 1) {
    substringMatrix[0][columnIndex] = 0;
  }

  for (let rowIndex = 0; rowIndex <= s2.length; rowIndex += 1) {
    substringMatrix[rowIndex][0] = 0;
  }

  // Build the matrix of all substring lengths to use Dynamic Programming approach.
  let longestSubstringLength = 0;
  let longestSubstringColumn = 0;
  let longestSubstringRow = 0;

  for (let rowIndex = 1; rowIndex <= s2.length; rowIndex += 1) {
    for (let columnIndex = 1; columnIndex <= s1.length; columnIndex += 1) {
      if (s1[columnIndex - 1] === s2[rowIndex - 1]) {
        substringMatrix[rowIndex][columnIndex] = substringMatrix[rowIndex - 1][columnIndex - 1] + 1;
      } else {
        substringMatrix[rowIndex][columnIndex] = 0;
      }

      // Try to find the biggest length of all common substring lengths
      // and to memorize its last character position (indices)
      if (substringMatrix[rowIndex][columnIndex] > longestSubstringLength) {
        longestSubstringLength = substringMatrix[rowIndex][columnIndex];
        longestSubstringColumn = columnIndex;
        longestSubstringRow = rowIndex;
      }
    }
  }

  if (longestSubstringLength === 0) {
    // Longest common substring has not been found.
    return '';
  }

  // Detect the longest substring from the matrix.
  let longestSubstring = '';

  while (substringMatrix[longestSubstringRow][longestSubstringColumn] > 0) {
    longestSubstring = s1[longestSubstringColumn - 1] + longestSubstring;
    longestSubstringRow -= 1;
    longestSubstringColumn -= 1;
  }

  return longestSubstring;
}

// PriorityQueue implementated using array based binary heap
// PriorityQueue methods
//  push(...values)
// 	peek()
//  pop()
//  size()
//  replace(value)

class PriorityQueue {

	constructor(comparator = (a, b) => a > b) {
		this.top = 0;
		this._heap = [];
		this._comparator = comparator;
	}
	size() {
		return this._heap.length;
	}
	isEmpty() {
		return this.size() == 0;
	}
	peek() {
		return this._heap[this.top];
	}
	push(...values) {
		values.forEach(value => {
				this._heap.push(value);
				this._siftUp();
				});
		return this.size();
	}
	pop() {
		const poppedValue = this.peek();
		const bottom = this.size() - 1;
		if (bottom > this.top) {
			this._swap(this.top, bottom);
		}
		this._heap.pop();
		this._siftDown();
		return poppedValue;
	}
	replace(value) {
		const replacedValue = this.peek();
		this._heap[this.top] = value;
		this._siftDown();
		return replacedValue;
	}
	_greater(i, j) {
		return this._comparator(this._heap[i], this._heap[j]);
	}
	_swap(i, j) {
		[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
	}
	_siftUp() {
		const parent = i => ((i + 1) >>> 1) - 1;
		let node = this.size() - 1;
		while (node > this.top && this._greater(node, parent(node))) {
			this._swap(node, parent(node));
			node = parent(node);
		}
	}
	_siftDown() {
		const left = i => (i << 1) + 1;
		const right = i => (i + 1) << 1;
		let node = this.top;
		while (
				(left(node) < this.size() && this._greater(left(node), node)) ||
				(right(node) < this.size() && this._greater(right(node), node))
			  ) {
			let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
			this._swap(node, maxChild);
			node = maxChild;
		}
	}
}

// demo
arr = [4,2,53,21,6,88,2,1,4];
n = arr.length;
leftmin = [];
const minq = new PriorityQueue((a, b) => a < b);
for (a of arr) {
	minq.push(a);
	leftmin.push(minq.peek());
}

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 = rn();
		const a = rna();

		const cnt = new Map();
		for (const elm of a) {
			cnt.set(elm, cnt.has(elm) ? cnt.get(elm) + 1 : 1);
		}

		const q = new PriorityQueue((a, b) => a > b);
		for (const vl of cnt.values()) {
			q.push(vl);
		}

		while (q.size() > 1) {
			let first = q.pop() - 1;
			let second = q.pop() - 1;

			if (first)
				q.push(first);
			if (second)
				q.push(second);
		}

		console.log(q.size() ? q.pop() : 0);
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function j(arr) {
   while(arr[arr.length - 1] === 0) {
      arr.pop();
   }
}

function add(heap, elem) {
   var i = heap.length;
   heap.push(elem);
   while(i > 0) {
      var nextI = (i - 1) >> 1;
      if (heap[i] <= heap[nextI]) {
         break;
      }
      var t = heap[i];
      heap[i] = heap[nextI];
      heap[nextI] = t;
      i = nextI;
   }
}

function extract(heap) {
   var result = heap[0];
   var i = 0;
   while (heap[i]) {
      var il = (i + 1) << 1;
      var ir = il - 1;
      if (heap[il]) {
         if (heap[ir]) {
            if (heap[il] > heap[ir]) {
               heap[i] = heap[il];
               i = il;
            } else {
               heap[i] = heap[ir];
               i = ir;
            }
         } else {
            heap[i] = heap[il];
            i = il;
         }
      } else {
         if (heap[ir]) {
            heap[i] = heap[ir];
            i = ir;
         } else {
            heap[i] = 0;
         }
      }
   }
   j(heap);
   return result;
}

function solve() {
   read();
   var o = {};
   readArray(Number).forEach(number => {
      if (o[number]) {
         o[number]++;
      } else {
         o[number] = 1;
      }
   });
   var heapArr = [];
   Object.values(o).forEach(x => add(heapArr, x));
   while(true) {
      var n1 = extract(heapArr);
      var n2 = extract(heapArr);
      if (!n2) {
         write(n1);
         return;
      }
      if (n1 > 1) {
         add(heapArr, n1 - 1);
      }
      if (n2 > 1) {
         add(heapArr, n2 - 1);
      }
   }
}

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

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

const solve = (a) => {
  const count = {};
  let maxCount = 0;
  for (const item of a) {
    if (!count.hasOwnProperty(item)) count[item] = 0;
    count[item]++;
    maxCount = Math.max(maxCount, count[item]);
  }
  if (Object.keys(count).length === 1) return a.length;
  return Math.max(2 * maxCount - a.length, 0);
};

const main = () => {
  let t = readInt();
  while (t--) {
    const n = readInt();
    const a = readListInt();
    console.log(solve(a));
  }
};

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

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    let j = 1;
    for (let i = 1; i <= t; i++) {
        var n = Number(input[j]);
        j++;
        var arr = input[j].split(" ").map((i) => {
            return Number(i);
        });
        j++;
        function minTransform(n, arr) {
            var map = new Map();
            var max = 0;
            for (var i = 0; i < arr.length; i++) {
                if (map.has(arr[i])) {
                    map.set(arr[i], map.get(arr[i]) + 1);
                } else {
                    map.set(arr[i], 1);
                }
                max = Math.max(max, map.get(arr[i]));
            }
            if (2 * max <= n) {
                return 0;
            }
            return max - (n - max);
        }
        console.log(minTransform(n, arr));
    }
})

'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 = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var allEqual = true
    for (let i = 0; i < n - 1; i++) {
      if (a[i] !== a[i + 1]) allEqual = false
    }
    if (allEqual) return console.log(n)
    if (n % 2 ===1) return console.log(1)
    console.log(0)
  })
}

function longestCommonSubstring(string1, string2) {
  // Convert strings to arrays to treat unicode symbols length correctly.
  // For example:
  // '𐌵'.length === 2
  // [...'𐌵'].length === 1
  const s1 = [...string1];
  const s2 = [...string2];

  // Init the matrix of all substring lengths to use Dynamic Programming approach.
  const substringMatrix = Array(s2.length + 1).fill(null).map(() => {
    return Array(s1.length + 1).fill(null);
  });

  // Fill the first row and first column with zeros to provide initial values.
  for (let columnIndex = 0; columnIndex <= s1.length; columnIndex += 1) {
    substringMatrix[0][columnIndex] = 0;
  }

  for (let rowIndex = 0; rowIndex <= s2.length; rowIndex += 1) {
    substringMatrix[rowIndex][0] = 0;
  }

  // Build the matrix of all substring lengths to use Dynamic Programming approach.
  let longestSubstringLength = 0;
  let longestSubstringColumn = 0;
  let longestSubstringRow = 0;

  for (let rowIndex = 1; rowIndex <= s2.length; rowIndex += 1) {
    for (let columnIndex = 1; columnIndex <= s1.length; columnIndex += 1) {
      if (s1[columnIndex - 1] === s2[rowIndex - 1]) {
        substringMatrix[rowIndex][columnIndex] = substringMatrix[rowIndex - 1][columnIndex - 1] + 1;
      } else {
        substringMatrix[rowIndex][columnIndex] = 0;
      }

      // Try to find the biggest length of all common substring lengths
      // and to memorize its last character position (indices)
      if (substringMatrix[rowIndex][columnIndex] > longestSubstringLength) {
        longestSubstringLength = substringMatrix[rowIndex][columnIndex];
        longestSubstringColumn = columnIndex;
        longestSubstringRow = rowIndex;
      }
    }
  }

  if (longestSubstringLength === 0) {
    // Longest common substring has not been found.
    return '';
  }

  // Detect the longest substring from the matrix.
  let longestSubstring = '';

  while (substringMatrix[longestSubstringRow][longestSubstringColumn] > 0) {
    longestSubstring = s1[longestSubstringColumn - 1] + longestSubstring;
    longestSubstringRow -= 1;
    longestSubstringColumn -= 1;
  }

  return longestSubstring;
}


Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 ≤ a ≤ b ≤ n - k + 1, b - a ≥ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.

The first line contains two integers n and k (2 ≤ n ≤ 2·105, 0 < 2k ≤ n) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn — the absurdity of each law (1 ≤ xi ≤ 109).

Print two integers a, b — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.

NoteIn the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.

print(function(n, k) {
	var x = readline().split(' ').map(Number);
	var i, a, sum = 0;
	for (i = 0; i < k; i++)
		sum += x[i];

	a = [sum];
	for (i = k; i < n; i++)
		a.push(sum = sum + x[i] - x[i - k]);

	var low, high, _low,
		y = 0,
		max = 0;
	for (i = k; i <= n - k; i++) {

		if (a[i - k] > y) {
			y = a[i - k];
			_low = i - k;
		}

		if (y + a[i] > max) {
			max = y + a[i];
			high = i;
			low = _low;
		}
	}

	low++;
	high++;
	return low + ' ' + high;

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

var k = readline().split( ' ' )[1] - '',
    arr = readline().split( ' ' );

var block = [],
    sum = 0,
    anss = 0,
    ansi,
    ds = [],
    di = [];

arr.forEach( function(item, index) {
    item -= '';

    sum += item;
    block.push( item );
    while (block.length > k) {
        sum -= block.shift();
    }

    if (index >= 2*k-1 && sum + ds[index-k] > anss) {
        anss = sum + ds[index-k];
        ansi = (di[index-k]-k+1+1) + ' ' + (index-k+1+1);
    }

    if (index < k || sum > ds[index-1]) {
        ds[index] = sum;
        di[index] = index;
    } else {
        ds[index] = ds[index-1];
        di[index] = di[index-1];
    }
} );

print( ansi );

print(function(n, k) {
	var x = readline().split(' ').map(Number);
	var i, a, sum = 0;
	for (i = 0; i < k; i++)
		sum += x[i];

	a = [sum];
	for (i = k; i < n; i++)
		a.push(sum = sum + x[i] - x[i - k]);

	var low, high,
		y = 0,
		max = 0;
	for (i = k; i <= n - k; i++) {
		if (a[i - k] > y) {
			y = a[i - k];
			low = i - k;
		}
		if (y + a[k] > max) {
			max = y + a[k];
			high = i;
		}
	}

	low++;
	high++;
	return low + ' ' + high;

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

print(function(n, k) {
	var x = readline().split(' ').map(Number);
	var i, a, sum = 0;
	for (i = 0; i < k; i++)
		sum += x[i];

	a = [sum];
	for (i = k; i < n; i++)
		a.push(sum = sum + x[i] - x[i - k]);

	var low, high,
		y = 0,
		max = 0;
	for (i = k; i <= n - k; i++) {

		if (a[i - k] > y) {
			y = a[i - k];
			low = i - k;
		}

		if (y + a[i] > max) {
			max = y + a[i];
			high = i;
		}
	}

	low++;
	high++;
	return low + ' ' + high;

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

var k = +readline();
var s = readline();
var aa =[];
aa[0] = 0;
for(var i=1; i<=1e6; i++){
	aa[i]=aa[i-1]+i;
}

if(k===0){
	print( s.split(/1+/g).map(function(v){
		return aa[v.length];
	}).reduce(function(a, b){ return a+b;}) );
	quit();
}

var low = 0;
var high = 0;
var c = 0;
var ans = 0;
// while(true){
	for(; high<s.length; high++){
		if(s[high]==='1'){
			c++;
		}
		if(c===k){
			var x1=1;
			while(s[low]==='0'){
				x1++;
				low++;
			}
			var x2=1
			while(s[high+1]==='0'){
				x2++;
				high++;
			}
			ans += x1*x2;
			low++;
			c--;
		}
	}
// }

print(ans);


Two players play a game.Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, then players alternate turns.The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.You want to know what number will be left on the board after $$$n - 1$$$ turns if both players make optimal moves.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$).

Print one number that will be left on the board.

NoteIn the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.In the second sample, $$$2$$$ is left on the board regardless of the actions of the players.

//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 N = nextInt();
	var list = nextIntArray();
	list.sort(function(a,b){
		return a - b;
	});
	myerr(list);
	for(var i = 0; i < N - 1; i++){
		if(i % 2 == 1){
			list.shift();
		}else{
			list.pop();
		}
	}
	myout(list[list.length - 1]);
}

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

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

  const arr = d.split(' ').map(Number).sort((a, b) => a - b);
  console.log(arr[Math.floor((arr.length - 1) / 2)]);

  c++;
});

let input = [];

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

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

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

    if(data.length % 2 == 0)
        console.log(data[data.length/2-1]);
    else
        console.log(data[ (data.length+1) / 2 -1]);
});

var n = readline();
var nums = readline().split(" ").map(function(x) { return parseInt(x); });
n = parseInt(n);
nums = nums.sort(function(a, b){
 return a - b;
});
var idx = Math.floor(n / 2);
if(n % 2 === 0 )
	idx--;
print(nums[idx]);

var n = parseInt(readline());
var vals = readline().split(" ").map(function(val) {
  return parseInt(val);
}).sort(function(a,b) {
  return a - b;
});

print(vals[Math.ceil(vals.length / 2) - 1]);

readline();
var inputs = readline().split(' ').map(Number);
var sorted = inputs.sort(function(a, b){ return a > b ? 1 : -1 }).reverse();
print((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2]);

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  a = a.sort(function(a, b) {
    return a - b;
  });

  var turn = 1;
  var res = -1;

  while(a.length > 0) {
    if(turn === 0) {
      res = a.shift();
    } else {
      res = a.pop();
    }
    turn ^= 1;
  }

  print(res);

//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 N = nextInt();
	var list = nextIntArray();
	list.sort(function(a,b){
		return a - b;
	});
	for(var i = 0; i < N - 1; i++){
		if(i % 2 == 0){
			list.shift();
		}else{
			list.pop();
		}
	}
	myout(list[list.length - 1]);
}

var n = readline();
var nums = readline().split(" ").map(function(x) { return parseInt(x); });
n = parseInt(n);
nums.sort(function(a, b){
 return a - b;
});
var idx = (n / 2);
if(n % 2 === 0 )
	idx--;

print(nums[idx]);

var n = readline();
n = parseInt(n);
var nums = readline().split(" ").map(function(x) { return parseInt(x); });
nums.sort(function(a, b){
 return a - b;
});
var idx = n / 2 - (n % 2 === 0 ? 1 : 0);

print(nums[idx]);

var n = readline();
var nums = readline().split(" ").map(function(x) { return parseInt(x); });
n = parseInt(n);
nums = nums.sort(function(a, b){
 return a - b;
});
var idx = (n / 2);
if(n % 2 === 0 )
	idx--;
print(idx);
print(nums[idx]);

readline();
var inputs = readline().split(' ').map(Number);
var sorted = inputs.sort(function(a, b){ return a > b ? 1 : -1 });
print((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2]);

readline();
var inputs = readline().split(' ').map(Number);
var sorted = inputs.sort();
print((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2 - 1]);

readline();
var inputs = readline().split(' ').map(Number);
var sorted = inputs.sort();
print((sorted.length % 2) ? sorted[Math.floor(sorted.length / 2)] : sorted[sorted.length / 2]);

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  a = a.sort(function(a, b) {
    return a > b;
  });

  var turn = 1;
  var res = -1;

  while(a.length > 0) {
    if(turn === 1) {
      res = a.shift();
    } else {
      res = a.pop();
    }
    turn ^= 1;
  }

  print(res);

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  a = a.sort(function(a, b) {
    return a > b;
  });

  var turn = 1;
  var res = -1;

  while(a.length > 0) {
    if(turn === 0) {
      res = a.shift();
    } else {
      res = a.pop();
    }
    turn ^= 1;
  }

  print(res);


"You must lift the dam. With a lever. I will give it to you.You must block the canal. With a rock. I will not give the rock to you." Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them.Hermit Lizard agreed to give Danik the lever. But to get a stone, Danik needs to solve the following task.You are given a positive integer $$$n$$$, and an array $$$a$$$ of positive integers. The task is to calculate the number of such pairs $$$(i,j)$$$ that $$$i<j$$$ and $$$a_i$$$ $$$\&$$$ $$$a_j \ge a_i \oplus a_j$$$, where $$$\&$$$ denotes the bitwise AND operation, and $$$\oplus$$$ denotes the bitwise XOR operation.Danik has solved this task. But can you solve it?

Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10$$$) denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For every test case print one non-negative integer — the answer to the problem.

NoteIn the first test case there is only one pair: $$$(4,7)$$$: for it $$$4$$$ $$$\&$$$ $$$7 = 4$$$, and $$$4 \oplus 7 = 3$$$.In the second test case all pairs are good.In the third test case there are two pairs: $$$(6,5)$$$ and $$$(2,3)$$$.In the fourth test case there are no good pairs.

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    const map = {};
    let count = 0;

    for (let value of arr) {
      const hob = highestOneBit(value);
      if (map[hob]) {
        count += map[hob];
        map[hob]++;
      } else map[hob] = 1;
    }

    console.log(count);
  }
}

//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 N = nextInt();
    var list = nextIntArray();
    var map = {};
    for(var j = 0; j < N; j++){
      var count = 0;
      while(list[j] > 0){
        list[j] = Math.floor(list[j] / 2);
        count++;
      }
      if(map[count] == null){
        map[count] = 0;
      }else{
        map[count]++;
      }

    }
    var all = 0;
    var key = Object.keys(map);
    for(var j = 0; j < key.length; j++){
      var c = map[key[j]];
      all += c * (c + 1) / 2;
    }
    output[i] = all;
  }
  myout(myconv(output, 9));
}

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, fn) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = fn(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = fn(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, fn, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => fn ? (p = fn(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => fn ? (p = fn(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

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

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/).map(v => +v); r = 0;
  let t = inp[r++];
  while (t--) {
    let n = inp[r++];
    let a = inp.slice(r, r = r + n);
    console.log(Arr(0, 30, i => {
      let d = 1 << i;
      let c = a.filter(v => (v & d) > 0 && v < d * 2).length;
      return c * (c - 1) / 2;
    }).sum());
  }
})();


Mainak has two positive integers $$$n$$$ and $$$m$$$.Mainak finds a sequence $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers interesting, if for all integers $$$i$$$ ($$$1 \le i \le n$$$), the bitwise XOR of all elements in $$$a$$$ which are strictly less than $$$a_i$$$ is $$$0$$$. Formally if $$$p_i$$$ is the bitwise XOR of all elements in $$$a$$$ which are strictly less than $$$a_i$$$, then $$$a$$$ is an interesting sequence if $$$p_1 = p_2 = \ldots = p_n = 0$$$.For example, sequences $$$[1,3,2,3,1,2,3]$$$, $$$[4,4,4,4]$$$, $$$[25]$$$ are interesting, whereas $$$[1,2,3,4]$$$ ($$$p_2 = 1 \ne 0$$$), $$$[4,1,1,2,4]$$$ ($$$p_1 = 1 \oplus 1 \oplus 2 = 2 \ne 0$$$), $$$[29,30,30]$$$ ($$$p_2 = 29 \ne 0$$$) aren't interesting.Here $$$a \oplus b$$$ denotes bitwise XOR of integers $$$a$$$ and $$$b$$$.Find any interesting sequence $$$a_1, a_2, \ldots, a_n$$$ (or report that there exists no such sequence) such that the sum of the elements in the sequence $$$a$$$ is equal to $$$m$$$, i.e. $$$a_1 + a_2 \ldots + a_n = m$$$.As a reminder, the bitwise XOR of an empty sequence is considered to be $$$0$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line and the only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le m \le 10^9$$$) — the length of the sequence and the sum of the elements. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, if there exists some interesting sequence, output "Yes" on the first line, otherwise output "No". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). If the answer is "Yes", output $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i \ge 1$$$), forming an interesting sequence such that $$$a_1 + a_2 \ldots + a_n = m$$$. If there are multiple solutions, output any.

Note In the first test case, $$$[3]$$$ is the only interesting sequence of length $$$1$$$ having sum $$$3$$$. In the third test case, there is no sequence of length $$$2$$$ having sum of elements equal to $$$1$$$, so there is no such interesting sequence. In the fourth test case, $$$p_1 = p_2 = p_3 = 0$$$, because bitwise XOR of an empty sequence is $$$0$$$.

;
var inp = [];
var lines;
var lineCounter = 0;
var readline = function () { return lines[lineCounter++]; };
process.stdin.on('data', function (c) { return inp.push(c); });
process.stdin.on('end', function () {
    lines = inp.join('').split('\n');
    myMain();
});
function myMain() {
    var ntest = +readline();
    var out = [];
    for (var testcount = 0; testcount < ntest; ++testcount) {
        var _a = readline().split(' ').map(function (x) { return +x; }), n = _a[0], m = _a[1];
        if (m < n) {
            out.push("NO");
            continue;
        }
        if (n % 2 == 1) {
            out.push("YES");
            out.push("".concat(m - (n - 1)).concat(' 1'.repeat(n - 1)));
            continue;
        }
        if (m % 2 == 1) {
            out.push("NO");
            continue;
        }
        if ((m - (n - 2)) <= 0) {
            out.push("NO");
            continue;
        }
        out.push("YES");
        var t = ((m - (n - 2)) / 2) >> 0;
        out.push("".concat(t, " ").concat(t).concat(' 1'.repeat(n - 2)));
    }
    console.log(out.join('\n'));
}

'use strict';

var readline = require('readline');

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

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

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  if (n === 1) return `YES\n${m}`;
  if (m < n) return 'NO';
  if (n & 1) {
    const res = [];
    for (let i = 0; i < n - 1; i++) {
      res.push(1);
    }
    res.push(m - (n - 1));
    return `YES\n${res.join(' ')}`;
  } else {
    if (m & 1) return 'NO';
    const res = [];
    for (let i = 0; i < n / 2 - 1; i++) {
      res.push(1, 1);
    }
    const a = m - (n - 2);
    res.push(a / 2, a / 2);
    return `YES\n${res.join(' ')}`;
  }
}

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

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