var stZag, stText, stt;
var mask = new Array(300);

function r() {
    stZag = readline();
    stText = readline();
};

+function main() {
    for (var i = 0; i < 300; i++) {
        mask[i] = false;
    }

    r();
    stt = "";
    for (var i = 0; i < stText.length; ++i) {
        if (stText.charAt(i) != ' ' && stText.charAt(i) != '	') {
            stt += stText.charAt(i);
        }
    }

    stText = "";

    for (var i = 0; i < stt.length; ++i) {
        stText += stt.charAt(i);
    }

    stt = "";

    for (var i = 0; i < stZag.length ; ++i) {
        if (stZag.charAt(i) != ' ' && stZag.charAt(i) != '	') {
            stt += stZag.charAt(i);
        }
    }

    stZag = "";
    for (var i = 0; i < stt.length ; ++i) {
        stZag += stt.charAt(i);
    }
    stt = "";

    for (var i = 0; i < stText.length; ++i) {
        var tek = stText.charAt(i);

        for (var j = 0; j < stZag.length; ++j) {
            if (mask[j] != true) {
                if (tek == stZag.charAt(j)) {
                    mask[j] = true;
                    break;
                }
            }

            if (j == stZag.length - 1) {
                print("NO\n");
                // cout << "NO" << endl;
                return 0;
            }
        }
    }

    print("YES\n");
    return 0;
}();

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

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

function main() {
  const str1 = readLine();
  const str2 = readLine().split(" ").join("").trim();
  const map = {};
  let ok = true;

  for (let i = 0; i < str1.length; i++) {
    const char = str1[i];
    if ((char >= "a" && char <= "z") || (char >= "A" && char <= "Z")) {
      map[char] = (map[char] || 0) + 1;
    }
  }

  for (let i = 0; i < str2.length; i++) {
    const char = str2[i];
    if (!map[char] || map[char] === 0) {
      console.log("NO");
      ok = false;
      break;
    }
    map[char]--;
  }

  ok && console.log("YES");
}

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

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

function main() {
	let h = readLine().split('');
	let str = readLine().split('');

	let c = 0;

	for (let i = 0, l = str.length; i < l; i++) {
		let index = h.indexOf(str[i]);
		if (index > -1) {
			c++;
			if (str[i] !== ' ') h.splice(index, 1);
		}
	}

	if (c === str.length) console.log('YES');
	else console.log('NO');
}

var s = readline().trim().split(' ').filter((_s)=>_s!='').join('');
var t = readline().trim().split(' ').filter((_s)=>_s!='').join('');

var ss = {};
for(var i=0;i<s.length;i++){
    if(ss[s[i]]==undefined)
        ss[s[i]] = 0;

    ss[s[i]]++;
}
var tt = {};
for(var i=0;i<t.length;i++){
    if(tt[t[i]]==undefined)
        tt[t[i]] = 0;

     tt[t[i]]++;
}

var can = true;
for(var i in tt){
    if(tt[i]>(ss[i]==undefined?0:ss[i])){
        can = false;
        break;
    }
}

print(can?'YES':'NO')

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

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

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

var whitespaceGlobalRegex = /\s+/g;

function removeWhitespace(s) {
	return s.replace(whitespaceGlobalRegex, "");
}

function main() {
	var sourceText = removeWhitespace(readline()),
		targetText = removeWhitespace(readline());

	var characterCounts = {};
	for (var characterIndex = sourceText.length-1; characterIndex >= 0; --characterIndex) {
		var character = sourceText.charAt(characterIndex);
		if (characterCounts[character] === undefined) {
			characterCounts[character] = 1;
		}
		else {
			characterCounts[character] += 1;
		}
	}

	for (var characterIndex = targetText.length-1; characterIndex >= 0; --characterIndex) {
		var character = targetText.charAt(characterIndex);
		if (characterCounts[character] === undefined || characterCounts[character] == 0) {
			print("NO");
			return;
		}
		characterCounts[character] -= 1;
	}

	print("YES");
}

main();

'use strict'

let s1 = readline()
let s2 = readline()

let ls = {}

for (let i = 0; i < s1.length; i++) {
  let l = s1[i]
  if (l == ' ') continue
  ls[l] = ls[l] || 0
  ls[l]++
}
let r = true
for (let i = 0; i < s2.length; i++) {
  let l = s2[i]
  if (l == ' ') continue
  if (!ls[l]) {
    r = false
    break
  }
  ls[l]--
}

print(r ? 'YES' : 'NO')

function checkAnonymousLetter (title, letter) {
  var index = {},
      canMakeLetter = true;

  debugger

  title.replace(/\s/g, "").split("").forEach(function (item) {
    if (index[item] === undefined) {
      index[item] = 1;
    } else {
      index[item]++;
    }
  });

  letter.replace(/\s/g, "").split("").forEach(function (item) {
    if (index[item] && canMakeLetter) {
      if (index[item] === 0) {
        canMakeLetter = false;
      } else {
        index[item]--;
      }
    } else {
      canMakeLetter = false;
    }
  });

  return canMakeLetter;
}

var title = readline(),
    letter = readline();

var output = checkAnonymousLetter.call(null, title, letter) ? "YES" : "NO";

write(output);

var header = readline().replace(/ /g,'');
var text = readline().replace(/ /g,'');
var hash = {};

for (var i = 0; i < header.length; i++) {
	if (hash.hasOwnProperty(header[i])) {
		hash[header[i]]++;
	} else {
		hash[header[i]] = 1;
	}
}

function isPossible() {
	for (var j = 0; j < text.length; j++) {
		if (hash[text[j]]) {
			hash[text[j]]--;
		} else {
			return 'NO';
		}
	}
	return 'YES';
}

print(isPossible());

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

var ans = "YES", indicator = 0, myMap = {};

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

    if (indicator == 0) {
        /*
        input.forEach(element => {
            if (element != ' ') {

                if (element in myMap)
                    myMap[element]++;
                else myMap[element] = 1;
            }
        });*/
        for (let i = 0; i < input.length; i++) {
            if (input[i] == ' ')
                continue;

            if (input[i] in myMap)
                myMap[input[i]]++;
            else myMap[input[i]] = 1;

        }
        indicator++;
    }
    else {

        for (let i = 0; i < input.length; i++) {
            if (input[i] == ' ')
                continue;
            if (myMap[input[i]] > 0)
                myMap[input[i]]--;
            else {
                ans = "NO";
                break;
            }
        }
        console.log(ans);
        rl.close();
    }
});

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

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

function main() {
	let h = readLine().split('');
	let str = readLine().split('');

	let c = 0;

	for (let i = 0, l = str.length; i < l; i++) {
		let index = h.indexOf(str[i]);
		if (index > -1) {
			c++;
			h.splice(index, 1);
		}
	}

	if (c === str.length) console.log('YES');
	else console.log('NO');
}

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

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

function main() {
	let h = readLine().split('');
	let str = readLine().split('');

	let c = 0;

	for (let i = 0, l = str.length; i < l; i++) {
		if (h.indexOf(str[i]) > -1) c++;
	}

	if (c === str.length) console.log('YES');
	else console.log('NO');
}

var stZag, stText, stt;
var mask = new Array(300);

function r() {
    stZag = readline();
    stText = readline();
};

+function main() {
    for (var i = 0; i < 300; i++) {
        mask[i] = false;
    }

    r();
    stt = "";
    for (var i = 0; i < stText.length; ++i) {
        if (stText.charAt(i) != ' ' && stText.charAt(i) != '	') {
            stt += stText.charAt(i);
        }
    }

    stText = "";

    for (var i = 0; i < stt.length; ++i) {
        stText += stt.charAt(i);
    }

    stt = "";

    for (var i = 0; i < stZag.length ; ++i) {
        if (stZag.charAt(i) != ' ' && stZag.charAt(i) != '	') {
            stt += stZag.charAt(i);
        }
    }

    stZag = "";
    for (var i = 0; i < stt.length ; ++i) {
        stZag += stt.charAt(i);
    }
    stt = "";

    print(stZag);
    print(stText);

    for (var i = 0; i < stText.length; ++i) {
        var tek = stText.charAt(i);

        for (var j = 0; j < stZag.length; ++j) {
            if (mask[j] != true) {
                if (tek == stZag.charAt(j)) {
                    mask[j] = true;
                    break;
                }
            }

            if (j == stZag.length - 1) {
                print("NO\n");
                // cout << "NO" << endl;
                return 0;
            }
        }
    }

    print("YES\n");
    return 0;
}();


var limit = parseInt(readline());
    for (var i = 0; i < limit; i++) {
        var caseConstraints = readline().split(" ");
        var guestLength = parseInt(caseConstraints[0]);
        var giftLength = parseInt(caseConstraints[1]);
        var guestArray = readline().split(" ");
        var giftArray = readline().split(" ");
        var guestIntArray = new Array();
        for (var _i = 0, guestArray_1 = guestArray; _i < guestArray_1.length; _i++) {
            var element = guestArray_1[_i];
            guestIntArray.push(parseInt(element));
        }
        guestIntArray.sort(function (a, b) { return b - a; });
        var total = 0;
        var flag = true;
        for (var j = 0; j < guestLength; j++) {
            if (j < giftLength) {
                if (guestIntArray[j] - 1 < giftLength) {
                    if (parseInt(giftArray[guestIntArray[j] - 1]) < parseInt(giftArray[j])) {
                        flag = false;
                    }
                }
                total += (flag) ? parseInt(giftArray[j]) : parseInt(giftArray[guestIntArray[j] - 1]);
            }
            else {
                total += parseInt(giftArray[guestIntArray[j] - 1]);
            }
        }
        print(total);
    }

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var [n, m] = readline().split(' ').map(x => Number(x));
        var sum = 0
        var sum2 = 0
        var array2 = []
        var k = readline().split(' ').map(x => {
            return Number(x) - 1
        });
        var c = readline().split(' ').map(x => {
            return Number(x)
        });
        k = k.sort((a, b) => b - a)
        var sum = 0
        var j = 0
        k.map((x, i) => {
            if (c[j] < c[x]) {
                sum += c[j]
                j++
            } else {
                sum += c[x]
            }

            // console.log(sum)

        })

        console.log(sum)

    })

}

let i = '';

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

    const t = parseInt(lines[0]);

    for (let i = 1; i <= t * 3; i += 3) {
        let split = lines[i].split(' ');
        const n = parseInt(split[0]);
        const m = parseInt(split[1]);

        const k = lines[i + 1].split(' ').map(num => parseInt(num));
        const c = lines[i + 2].split(' ').map(num => parseInt(num));

        const result = solve(n, m, k, c);

        console.log(result);
    }
});

function solve(n, m, k, c) {
    let sum = 0;

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

    let j = 1;

    for (let i = 0; i < n; i++) {
        if (j < k[i]) {
            sum += c[j - 1];
            j++;
        } else {
            sum += c[k[i] - 1];
        }
    }

    return sum;
}

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, m] = rna();
		const k = rna();
		const c = rna();

		k.sort((x, y) => y - x);

		let ans = 0, l = 0;
		for (const i of k) {
			if (c[l] < c[i-1]) {
				ans += c[l]; l++;
			} else {
				ans += c[i-1];
			}
		}

		console.log(ans);
	}
}

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, m] = rna();
		const k = rna();
		const c = rna();

		k.sort((x, y) => y - x);

		let ans = 0;
		const st = c.slice().reverse();
		for (let i = 0; i < n; i++) {
			if (st.length && st[st.length-1] < c[k[i]-1]) {
				ans += st.pop();
			} else {
				ans += c[k[i]-1];
			}
		}

		console.log(ans);
	}
}

/*
 * File Created: Wednesday, 6th January 2021 9:38:39 pm
 * Author: Lukas Rimkus
 */

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(readLine(), 10);

    while(testCases--) {

        const [n, m ] = readLine().split(' ').map(Number);

        const k = readLine().split(' ').map(Number);

        const c = readLine().split(' ').map(Number);

        const res = a(n,m,k,c);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,m,guests,c){
    let count = 0;
    guests.sort((a,b) => b - a);
    for(let i = 0; i < guests.length; i++){
        const gift = c[guests[i] - 1];
        const money = c[i];
        count += Math.min(gift, money ? money : gift);
        // console.log('gift = ', gift, 'money = ', money, 'count = ', count);
    }
    return count;
}

module.exports =  a;


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

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

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


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


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

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

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


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

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

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


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, _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)));

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


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

//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 = 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]);

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


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


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

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