const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
const res = []
let pr, cur = 0, m, n;

const pers = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

/**
 * I have used a split and map together which time complexity is O(n)
 *
 * The sum of characters of every word will
 * always be the length of the sentance.
 * The complexity is O(sum of all words'
 * character lengths), and instead of estimating
 * both character length and amount of words at
 * the worst case, we notice this is simply O(n).
 *
 * As sequential chaining of a constant amount
 * of O(n) operations is still O(n),
 * we get the above mentioned overall complexity
 * of O(n), where n is the amount of characters.
 *
 * used a simple for loop inside of a while loop
 * the complexity of while loop is O(n^2)
 *
 * The total complexity of the program is O(n^2) = O(n) + O(n^2)
*/

rl.on("line", (line) => {
  input.push(line);
  if (input.length === 2) {
    [n, m] = input[0].split(' ').map(e => +e) // O(n)
    let s = input[1]
    pr = Array.from({ length: 6 }, () => Array(n + 1).fill(0))
    do { // O(n^2)
      for (let i = 0; i < n; ++i) { // O(n)
        pr[cur][i + 1] = pr[cur][i] + (s[i] !== pers[cur][i % 3]);
      }
      ++cur;
    } while(cur < 6)
  }

  if (input.length > 2) {
    const [l, r] = input.pop().split(' ').map(e => +e)
    let ans = n;
    for (let i = 0; i < 6; ++i)
      ans = Math.min(ans, pr[i][r] - pr[i][l - 1]);
    res.push(ans)
  }

});
rl.on("close", () => {
  res.forEach(e => console.log(e))
});

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
const res = []
let pr, cur = 0, m, n
const pers = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
rl.on("line", (line) => {
  input.push(line);
  if (input.length === 2) {
    [n, m] = input[0].split(' ').map(e => +e)
    let s = input[1]
    pr = Array.from({ length: 6 }, () => Array(n + 1).fill(0))
    do {
      for (let i = 0; i < n; ++i) {
        pr[cur][i + 1] = pr[cur][i] + (s[i] !== pers[cur][i % 3]);
      }
      ++cur;
    } while(cur < 6)
  }
  if (input.length > 2) {
    const [l, r] = input.pop().split(' ').map(e => +e)
    let ans = n;
    for (let i = 0; i < 6; ++i) ans = Math.min(ans, pr[i][r] - pr[i][l - 1]);
    res.push(ans)
  }

});
rl.on("close", () => {
  res.forEach(e => console.log(e))
});

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    // var t = parseInt(lines[0]);
    var l = 0;
    var [n, m] = lines[l++].trim().split(' ').map(Number)
    var str = lines[l++]
    var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))
    l += m
    console.log(solve(n, m, str, arr))
    // for (var i = 0; i < t; i++) {
    //     var n = +lines[l++]
    //     var a = lines[l++].trim().split(' ').map(Number)
    //     var b = lines[l++].trim().split(' ').map(Number)
    // }
});

function solve(n, m, str, arr) {
    const d = [];
    ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'].forEach((p, i) => {
        d[i] = []
        for (let j = 0; j < n; j++) {
            const ch = p[j % 3]
            d[i][j] = str[j] === ch ? 0 : 1
        }
    })

    const prefix = []
    for (let i = 0; i < d.length; i++) {
        prefix[i] = []
        for (let j = 0; j < d[i].length; j++) {
            prefix[i][j] = j ? d[i][j] + prefix[i][j - 1] : d[i][j]
        }
    }

    return arr.map(([l, r]) => {
        l--
        r--
        const ds = prefix.map(p => p[r] - (l ? p[l - 1] : 0))
        return Math.min(...ds)
    }).join('\n')
}

'use strict';

function solve(n, m, s, a) {
  const sums = [],
        strs = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];
  for (let str of strs) {
    let sum = new Array(n);
    for (let i = 0; i < n; i++) {
      var _sum;
      sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + (s[i] === str[i % 3] ? 0 : 1);
    }
    sums.push(sum);
  }
  let res = new Array(m);
  for (let [i, [l, r]] of a.entries()) {
    let min = Infinity;
    for (let i = 0; i < 6; i++) {
      var _sums$i;
      min = Math.min(min, sums[i][r] - ((_sums$i = sums[i][l - 1]) !== null && _sums$i !== void 0 ? _sums$i : 0));
    }
    res[i] = min;
  }
  return res.join('\n');
}

async function main(read) {
  try {
    let res = [];
    const [n, m] = (await read()).split(' ').map(Number);
    const s = await read();
    const a = [];
    let tmp = m;
    while (tmp--) {
      a.push((await read()).split(' ').map(str => Number(str) - 1));
    }
    res.push(solve(n, m, s, a));
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

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

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let [n, m] = rna();
	const s = rl();

	const cost = Array.from(Array(6), _ => []);
	const perm = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];

	for (let i = 0; i < n; i++) {
		for (let j = 0; j < perm.length; j++) {
			cost[j][i] = cost[j][i-1] || 0;
			if (s[i] != perm[j][i%3]) cost[j][i]++;
		}
	}

	while (m--) {
		let [l, r] = rna(); l--, r--;
		let ans = 1e9;
		for (let i = 0; i < cost.length; i++) {
			ans = Math.min(ans, cost[i][r] - (cost[i][l-1] || 0));
		}
		console.log(ans);
	}
}

'use strict'
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
const MAX_N = 200010,
  a = new Array(MAX_N),
  b = new Array(MAX_N),
  c = new Array(MAX_N),
  a2 = new Array(MAX_N),
  b2 = new Array(MAX_N),
  c2 = new Array(MAX_N)
__main__(function (e) {
  const [n, t] = e.readIntegersOfLine(),
    i = e.readLine().trim()
  ;(a[0] = b[0] = c[0] = 0), (a2[0] = b2[0] = c2[0] = 0)
  for (let e = 0; e < i.length; ++e) {
    const n = i[e]
    ;(a[e + 1] = c[e] + ('a' === n ? 0 : 1)),
      (b[e + 1] = a[e] + ('b' === n ? 0 : 1)),
      (c[e + 1] = b[e] + ('c' === n ? 0 : 1)),
      (a2[e + 1] = b2[e] + ('a' === n ? 0 : 1)),
      (b2[e + 1] = c2[e] + ('b' === n ? 0 : 1)),
      (c2[e + 1] = a2[e] + ('c' === n ? 0 : 1))
  }
  for (let i = 0; i < t; ++i) {
    let [t, i] = e.readIntegersOfLine()
    t -= 1
    let s = n
    switch ((i - t + 1) % 3) {
      case 0:
        s = Math.min(
          c[i] - a[t],
          a[i] - b[t],
          b[i] - c[t],
          b2[i] - a2[t],
          c2[i] - b2[t],
          a2[i] - c2[t],
        )
        break
      case 1:
        s = Math.min(
          a[i] - a[t],
          b[i] - b[t],
          c[i] - c[t],
          a2[i] - a2[t],
          b2[i] - b2[t],
          c2[i] - c2[t],
        )
        break
      case 2:
        s = Math.min(
          b[i] - a[t],
          c[i] - b[t],
          a[i] - c[t],
          c2[i] - a2[t],
          a2[i] - b2[t],
          b2[i] - c2[t],
        )
    }
    e.print(s + '\n')
  }
})

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/r/g, '').split('\n');
    const [len, total] = input[0].split(' ').map((ele) => +ele);
    const str = input[1];
    const tree = new Tree(str);
    for (let i = 0; i < total; i++) {
        solve(tree, input[2 + i]);
    }

    process.exit();
});

function solve(tree, range) {
    const [L, R] = range.split(' ').map((ele) => ele - 1);
    const result = tree.findEntry(L, R);
    console.log(Math.min(...result));
}

class Tree {

    constructor(str) {
        this.mays = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];
        this.root = this.build(str, 0, str.length - 1);
    }

    build(str, l, r) {
        if (l === r) {
            const ary = new Array(18);
            for (let i = 0; i < 6; i++) {
                const compare = this.mays[i];
                ary[i * 3] = str[l] === compare[l % 3] ? 0 : 1;
                ary[i * 3 + 1] = str[l] === compare[(l + 1) % 3] ? 0 : 1;
                ary[i * 3 + 2] = str[l] === compare[(l + 2) % 3] ? 0 : 1;
            }
            return {
                l,
                r,
                ary
            };
        } else {
            const mid = (l + r) >> 1;
            const left = this.build(str, l, mid);
            const right = this.build(str, mid + 1, r);
            const ary = new Array(18);
            for (let i = 0; i < 18; i++) {
                ary[i] = left.ary[i] + right.ary[i];
            }
            return {
                l,
                r,
                ary,
                left,
                right
            }
        }
    }

    findEntry(l, r) {
        const result = new Array(18).fill(0);
        this.find(this.root, l, r, result);
        return result;
    }

    find(root, l, r, result) {
        if (root.l === l && root.r === r) {
            for (let i = 0; i < 18; i++) {
                result[i] += root.ary[i];
            }
            return;
        } else {
            root.left.r >= l && this.find(root.left, l, root.left.r, result);
            root.right.l <= r && this.find(root.right, root.right.l, r, result);
        }
    }
}

var readline = require('readline');

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

var g = main();
g.next()
rl.on('line', (input) => {
    g.next(input)
    // console.log('read', input)
    // input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    input = yield 1
    var t = +input
    for (var i = 0; i < t; i++) {
        input = yield 1
        const [n, k] = input.split(' ').map(Number)
        if (i === 400) {
            process.exit(n)
        }
        yield* solve(n, k)
    }
    process.exit(0)
}

function* solve(n, k) {
    let guess = 0
    let sum = 0
    while (guess < n) {
        const next = xor(guess, sum, k)
        console.log(next)

        const ans = yield 1
        if (ans !== '0') break

        sum = xor(sum, next, k)
        guess++
    }
}

function xor(a, b, k) {
    return a ^ b
    if (a > b) return xor(b, a, k)

    a = toBits(a, k)
    b = toBits(b, k)
    const r = a.map((x, i) => (a[i] + b[i]) % k)
    for (let i = a.length; i < b.length; i++) {
        r.push(b[i])
    }

    return toVal(r, k)
}
function toBits(n, k) {
    const r = []
    while (n) {
        r.push(n % k)
        n = Math.floor(n / k)
    }
    return r
}
function toVal(arr, k) {
    let b = 1
    return arr.reduce((s, x) => {
        s = s + x * b
        b *= k
        return s
    }, 0)
}


function main() {
  var testCasesNum = +readline();
  var testCases = [];
  for (var i = 0; i < testCasesNum * 2; i += 2) {
    (function (i) {
      testCases[i] = readline();
      testCases[i + 1] = readline();

      checkPoem(testCases[i], testCases[i + 1]);
    })(i)
  }
}

function checkPoem(ns, poem) {
  var nsArr = ns.split(' ').map(Number);
  var n = nsArr[0];
  var s = nsArr[1];
  var poemArr = poem.split(' ').map(Number);

  var poemSum = 0;
  var j = 0;
  var maxJ = 0;

  while (poemSum <= s && j < n) {
    poemSum += poemArr[j];
    if (j == n - 1 && poemSum <= s) {
      print(0);
      return;
    }
    if (poemArr[j] > poemArr[maxJ]) {
      maxJ = j;
    }
    j++;
  }
  print(maxJ + 1)
}

main();

let input = "";
const { EOL } = require("os");
process.stdin.on("data", i => (input += i));

process.stdin.on("end", func);

async function func() {
  const [t, ...queries] = input.split(EOL);
  for (let i = 0; i < t; i++) {
    let res = 0;
    const [n, s] = queries.shift().split(" ").map(a => parseInt(a));
    const verses = queries.shift().split(" ").map(a => parseInt(a));
    const totalTime = verses.reduce((acc, curr) => acc + curr);
    if (totalTime > s) {
      verses.reduce((acc, curr, index) => {
        if (res > 0)
          return;
        if (acc + curr > s) {
          const prevVerses = verses.slice(0, index + 1);
          res = verses.indexOf(Math.max(...prevVerses)) + 1;
        } else {
          return acc + curr;
        }
      })
    }
    console.log(res);
  }
}

module.exports = func;

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        let [n, s] = lines[i].split(' ').map(Number);
        let a = lines[i + 1].split(' ').map(Number);

        let sum = 0;
        let skipIndex = 0;
        let skipValue = a[0];
        let j = 1;
        while (sum <= s && j < a.length) {
            // console.log('--', sum, skipValue);
            if (sum + a[j] <= s || sum + skipValue <= s) {
                if (a[j] > skipValue) {
                    skipIndex = j;
                    sum += skipValue;
                    skipValue = a[j];
                } else {
                    sum += a[j];
                }
            }
            j++;
        }
        // console.log(s, a, sum, skipValue);
        if (sum + skipValue <= s) {
            console.log(0);
        } else {
            console.log(skipIndex + 1);
        }
    }
});

let input = "";
const { EOL } = require("os");
process.stdin.on("data", i => (input += i));

process.stdin.on("end", func);

async function func() {
  const [t, ...queries] = input.split(EOL);
  for (let i = 0; i < t; i++) {
    let res = 0;
    const [n, s] = queries.shift().split(" ").map(a => parseInt(a));
    const verses = queries.shift().split(" ").map(a => parseInt(a));
    const totalTime = verses.reduce((acc, curr) => acc + curr);
    if (totalTime > s) {
      verses.reduce((acc, curr, index) => {
        if (res > 0)
          return;
        if (acc + curr > s) {
          const prevVerses = verses.slice(0, index);
          res = verses.indexOf(Math.max(...prevVerses)) + 1;
        } else {
          return acc + curr;
        }
      })
    }
    console.log(res);
  }
}

module.exports = func;

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        let [n, s] = lines[i].split(' ').map(Number);
        let a = lines[i + 1].split(' ').map(Number);

        let sum = 0;
        let skipIndex = 0;
        let skipValue = a[0];
        let j = 1;
        while (sum <= s && j < a.length) {
            // console.log('--', sum, skipValue);
            if (sum + a[j] <= s) {
                if (a[j] > skipValue) {
                    skipIndex = j;
                    sum += skipValue;
                    skipValue = a[j];
                } else {
                    sum += a[j];
                }
            }
            j++;
        }
        // console.log(s, a, sum, skipValue);
        if (sum + skipValue <= s) {
            console.log(0);
        } else {
            console.log(skipIndex + 1);
        }
    }
});

function main() {
  var testCasesNum = +readline();
  var testCases = [];
  for (var i = 0; i < testCasesNum * 2; i += 2) {
    (function (i) {
      testCases[i] = readline();
      testCases[i + 1] = readline();

      checkPoem(testCases[i], testCases[i + 1]);
    })(i)
  }
}

function checkPoem(ns, poem) {
  var nsArr = ns.split(' ').map(Number);
  var n = nsArr[0];
  var s = nsArr[1];
  var poemArr = poem.split(' ').map(Number);

  var poemSum = 0;
  var j = 0;
  var maxJ = 0;

  while (poemSum < s && j < n) {
    poemSum += poemArr[j];
    if (j == n - 1 && poemSum <= s) {
      print(0);
      return;
    }
    if (poemArr[j] > poemArr[maxJ]) {
      maxJ = j;
    }
    j++;
  }
  print(maxJ + 1)
}

main();


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--) {
		let [n, k] = rna();

		let ans;
		if (n % 2 == 0) {
			if (n % 4 == 0){
				ans = [n/2, n/4, n/4];
			} else {
				ans = [n/2-1, n/2-1, 2]
			}
		} else {
			ans = [(n-1)/2, (n-1)/2, 1];
		}

		console.log(ans.join(' '));
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var K = nextInt();
		if(N % 4 == 0){
			var s = N / 4;
			var d = s * 2;
			myout(d + " " + s + " " + s);
			continue;
		}
		if(N % K == 0){
			var s = N / K;
			myout(s + " " + s + " " + s);
		}else if(N % 2 == 1){
			N--;
			var s = N / 2;
			myout("1 " + s + " " + s);
		}else{
			N -= 2;
			var s = N / 2;
			myout("2 " + s + " " + s);
		}
	}
}

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

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

for(var i = 0; i<t; i++){
    var line = readline().split(' ').map(getInt);
    print(solution.apply(undefined, line));
}
function solution(n, k){
    var m;

    if(n%2 === 1){
        m = (n - 1)/ 2;
        return [m, m, 1].join(' ');
    }
    if(n%4 === 0){
        m = n/4;
        return [2*m, m, m].join(' ');
    }else{
        m = (n-2)/4;
        return [2*m, 2*m, 2].join(' ');
    }

}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let a = Math.floor(n / 2);
    if (a + a < n) {
      console.log(`${a} ${a} ${n - (a + a)}`);
    } else {
      if (a % 2) console.log(`${a - 1} ${a - 1} ${n - (a - 1 + (a - 1))}`);
      else console.log(`${a} ${a / 2} ${a / 2}`);
    }
  }
};
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 => {
    return string.trim();
  });

  main();
});

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

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

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    // var a = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var ans = new Array(k).fill(1)
    var x
    if (n % 2 === 1) {
      x = (n - 1) / 2
      return console.log(1, x, x)
    }
    if (n % 4 === 0) {
      x = n / 4
      return console.log(x*2, x, x)
    }

    return console.log(2, (n-2)/2, (n-2)/2)

  });
}

'use strict';

function solve(n, m) {
  let res = [],
      one = 0;
  if (n & 1) {
    if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;
    m--;
    one++;
    n--;
  }
  for (let i = 30; i >= 0; i--) {
    if (res.length) {
      while (1 << i <= n) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    } else {
      if (1 << i <= n / 2) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    }
  }
  if (res.length === m) {
    if (one) res.push(1);
    return res.join(' ');
  } else if (res.length > m) {
    let sum = res.splice(2, res.length - m).reduce((a, b) => a + b, 0) / 2;
    res[0] += sum;
    res[1] += sum;
    if (one) res.push(1);
    return res.join(' ');
  }
  m -= res.length;
  while (m--) {
    let cur = res[res.length - 1];
    if (cur === 2) {
      res.pop();
      one += 2;
    } else {
      res[res.length - 1] /= 2;
      res.push(cur / 2);
    }
  }
  return (res.join(' ') + ' 1'.repeat(one)).trim();
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      res.push(solve(n, m));
    }
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

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

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let a = 1,
      b = Math.floor(n / 2);
    let c = n - (a + b);
    console.log(`${a} ${b} ${c}`);
  }
};
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 => {
    return string.trim();
  });

  main();
});

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

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

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

    var a = getDel(n)
    var b = (n - a[a.length - 1]) /2
    console.log(a[a.length - 1], b, b)
  });
}

function getDel(x) {

  var i = 1
  var ans = []
  while (i * i <= x) {
    if (x % i === 0) {
      ans.push(i)
      // ans.push(x / i)
    }
    i++
  }
  return ans
}

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

  return gcd(b, a % b);
}


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const t = parseInt(readline());
  for (var i=0; i<t; i++) {
    const [x, y, k] = readline().split(" ").map(x => BigInt(parseInt(x)));
    const result = (k*y + k - 1n + x - 2n) / (x-1n) + k;
    console.log(result.toString());
  }
}

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() {
  let t = +readLine();

  while (t--) {
    const [x, y, k] = readLine()
      .split(" ")
      .map((n) => BigInt(n));
    let ans = "";
    let moves = 1n + k;
    let sticks = y * k + k - x;

    if (sticks < 0) sticks = 0n;

    moves += sticks / (x - 1n);
    if (sticks % (x - 1n) !== 0n) moves++;

    ans += moves;

    console.log(ans);
  }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var t = +inputs[0];
    for (let i = 0; i < t; i++) {
        var [x, y, k] = inputs[i + 1].split(' ').map(v => BigInt(v));
        var n = (k * y + k - 1n + x - 2n) / (x - 1n);
        console.log(n + k + '');
    }
})();
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;
    }, {});
};

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() {
  let t = +readLine();

  while (t--) {
    const [x, y, k] = readLine()
      .split(" ")
      .map((n) => BigInt(n));
    let ans = "";
    let moves = 1n + k;
    let sticks = k * y + k - x;

    moves += sticks / (x - 1n);
    if (sticks % (x - 1n) !== 0n) moves++;

    ans += moves;

    console.log(ans);
  }
}

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

// 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() {
  let t = +readLine();

  while (t--) {
    const [x, y, k] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let ans = "";
    let moves = 1n + BigInt(k);
    let sticks = BigInt(k) * BigInt(y) + BigInt(k) - BigInt(x);

    moves += sticks / BigInt(x - 1);
    if (sticks % BigInt(x - 1)) moves++;

    ans += moves;

    console.log(ans);
  }
}


const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (let i = 0; (i < q); i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }
  if (q != n) {
  process.stdout.write(r + ' ');
  }

  //console.log(r + ' ')

// if (n != 1) {
  for (let i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
//}
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  let [n, k, t] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))
  t = t / 100
  let pi = n * t | 0
  let ip = n * t - pi
  let i = ip * k | 0
  let r = []
  for (let j = 0; j < pi; j++) r.push(k)
  if (pi != n) r.push(i)
  for (let j = pi + 1; j < n; j++) r.push(0)
  console.log(r.join(' '))
})

var input = readline().split(" ");

var progress = input[2];
var left = input[1];
var outputArray = [];
var time = Math.floor((progress * left * input[0]) / 100);

for(var i=1;i<=input[0];i++) {

    if(time < 0) {
        outputArray.push(0);
    } else if(time < left) {
        outputArray.push(time);
    } else {
        outputArray.push(left);
    }

    time = time - left;

}

print(outputArray.join(" "));

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  let [n, k, t] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))
  t = t / 100
  let pi = n * t | 0
  let ip = n * t - pi
  let i = ip * k | 0
  let r = []
  for (let j = 0; j < pi; j++) r.push(k)
  r.push(i)
  for (let j = pi + 1; j < n; j++) r.push(0)
  console.log(r.join(' '))
})

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (i = 0; i < q; i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }

    process.stdout.write(r + ' ');

  //console.log(r + ' ')

if (n != 1) {
  for (i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (i = 0; i < q; i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }
  if (n !== 1) {
    process.stdout.write(r + ' ');

  }
  //console.log(r + ' ')

  for (i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

const cal = (n, k, t) => {
  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (i = 0; i < q; i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }
  process.stdout.write(r + ' ');
  //console.log(r + ' ')

  for (i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (let i = 0; (i < q); i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }

  if (q <= (n-q)){
      process.stdout.write(r + ' ');
  }

  //console.log(r + ' ')

if (n != 1) {
  for (let i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();


'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

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

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split("").map(x=>parseInt(x))

        let diverseCountTot=0
        for (let i = 0; i < n; ++i) {
            let countmap = Array(10).fill(0);
            let diverse_count=0
            let max=0
            //console.log("countmap " + countmap)
            for (let j = i; j < n; ++j) {
                let val = arr[j]

                if(countmap[val]>=10)
                    break;

                if(!countmap[val])
                    diverse_count++

                //console.log("val " + val)
                countmap[val]++

                max = Math.max(countmap[val],max)
                //console.log("max " + max)

                if(max <= diverse_count)
                    diverseCountTot++
            }
      }
      console.log(diverseCountTot)
   }
}

function solve() {
    var n = Number(read());
    var count = [];
    for (var d = 0; d < 10; d++) {
        count[d] = [0];
    }
    var s = read().split('').map(Number);
    for (var i = 0; i < n; i++) {
        for (d = 0; d < 10; d++) {
            if (s[i] !== d) {
                count[d][i + 1] = count[d][i];
                continue;
            }
            count[d][i + 1] = count[d][i] + 1;
        }
    }

    var ans = 0;
    for (i = 0; i < n; i++) {
        for (var len = 1; len < 101; len++) {
            var end = i + len;
            if (end > n) {
                break;
            }
            var maxCount = 0;
            var different = 0;
            for (d = 0; d < 10; d++) {
                var currentCount = count[d][end] - count[d][i];
                if (currentCount !== 0) {
                    different++;
                    if (currentCount > maxCount) {
                        maxCount = currentCount;
                        if (maxCount > 10) {
                            break;
                        }
                    }
                }
            }
            if (different >= maxCount) {
                ans++;
            }
        }
    }
    write(ans);
}

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

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

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

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

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split("").map(x=>parseInt(x))

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

            //let countmap = Array(10).fill(0);
            let countmap = {}
            let diverse_count=0
            let max=0

            for (let j = i; j < n; ++j) {
                let val = arr[j]

                //console.log("countmap[val] " + countmap[val])
                if(countmap[val]>=10)
                {
                    //console.log("countmap[val] " + countmap[val])
                    break;
                }

                if(countmap[val]==undefined)
                {
                    diverse_count++

                countmap[val]=0
                }

                countmap[val]++
                //console.log("countmap[val] " + countmap[val])

                max = Math.max(countmap[val],max)
                //console.log("max " + max)

                if(max <= diverse_count)
                    diverseCountTot++
            }
      }
      console.log(diverseCountTot)
   }
}

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

function solve(s) {
    let solution = 0;

    for (let i = 0; i < s.length; i++) {
        const counters = {
            0: 0,
            1: 0,
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 0,
            7: 0,
            8: 0,
            9: 0
        };

        let maxFreq = 0;
        let uniq = 0;

        for (let j = i; j < s.length; j++) {
            counters[s[j]] += 1;
            const currentFreq = counters[s[j]];

            if (currentFreq > 10) {
                break;
            }

            if (maxFreq < currentFreq) {
                maxFreq = currentFreq;
            }

            if (currentFreq === 1) {
                uniq += 1;
            }

            if (maxFreq <= uniq) {
                solution++;
            }
        }
    }

    return solution;
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 2) {
        const s = data[i + 1].trim();
        const solution = solve(s);
        console.log(solution);
    }
});

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

function getMaxFreqAndUniq(c) {
    let uniq = 0;
    let maxFreq = -Infinity;
    for (let i = 0; i < 10; i++) {
        if (c[i] > 0) {
            uniq++;
        }

        if (c[i] > maxFreq) {
            maxFreq = c[i];
        }
    }

    return {uniq, maxFreq};
}

function count(s) {
    const result = {
        0: 0,
        1: 0,
        2: 0,
        3: 0,
        4: 0,
        5: 0,
        6: 0,
        7: 0,
        8: 0,
        9: 0,
    };

    for (let i = 0; i < s.length; i++) {
        result[s[i]] += 1;
    }

    return result;
}

function solve(s, c, i = 0, j = s.length - 1, alreadySolved = {}) {
    const key = `${i}-${j}`;
    if (alreadySolved[key] === true) {
        return 0;
    }

    alreadySolved[key] = true;

    if (i === j) {
        return 1;
    }

    let result = 0;

    const {uniq, maxFreq} = getMaxFreqAndUniq(c);
    if (uniq >= maxFreq) {
        result += 1;
    }

    const leftC = {...c};
    leftC[s[i]] -= 1
    result += solve(s, leftC, i + 1, j, alreadySolved);

    const rightC = {...c};
    rightC[s[j]] -= 1;
    result += solve(s, rightC, i, j - 1, alreadySolved);

    return result;
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 2) {
        const solution = solve(data[i+1], count(data[i + 1]));
        console.log(solution);
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

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

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split("").map(x=>parseInt(x))

        let diverseCountTot=0
        for (let i = 0; i < n; i++) {
            let countmap = Array(10).fill(0);
            let diverse_count=0
            let max=0
            //console.log("countmap " + countmap[0])
            for (let j = i; j < n; j++) {
                let val = arr[j]
                if(diverse_count>=10)
                    break;

                if(!countmap[val])
                    diverse_count++

                //console.log("val " + val)
                countmap[val]++

                max = Math.max(countmap[val],max)
                //console.log("max " + max)

                if(max <= diverse_count)
                    diverseCountTot++
            }
      }
      console.log(diverseCountTot)
   }
}


function solve() {
    var n = readline()
    var s = readline().split(' ');

    var sz = 0;
    while (s[sz] === s[0]) sz++;

    if (s.length % sz)
        return false;

    for(var i=0;i<s.length;i++) {
        var m = i % (2 * sz);
        if(m < sz) {
            if(s[i] != s[0]) return false;
        }
        else {
            if(s[i] == s[0]) return false;
        }
    }

    return true;
}

print(solve() ? "YES" : "NO");

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = 0;
var hopaayega = true;
//for(var i=0;i<n;i++){
//    var curr = parseInt(a[i]);
//    if(a[i] != a[0]){
//        cycl = i;
//        break;
//    }
//}
while(a[cycl] === a[0]) cycl ++;
if(n%cycl) {
    print('NO');
}
else {
    for(var i=0;i<n;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var n = readline();
n = parseInt(n);
var s = readline().split(" ");
var p = 0;
var arr = new Array();
for (var i = 0; i < s.length; i++) {
    if (i == s.length || s[i] != s[i + 1]) {
        arr.push(i - p + 1);
        p = i + 1;
    }
}
var flag = true;
for (var i = 1; i < arr.length; i++) {
    if (arr[i] != arr[i - 1]) {
        flag = false;
        break;
    }
}
if (flag) print("YES");
else print("NO");

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

var lng = 1;
var lng_base;
var isFirst = true;
var fail = false;
for (var i = 1; i < n; i++ ) {
    var k = arr[i];
    last = arr[i-1];
    if (k == last) {
        lng++;

    } else
        if (isFirst) {
            lng_base = lng;
            lng = 1;
            isFirst = false;
        } else if (lng != lng_base) {
            fail = true;

            break;
        } else {
            lng = 1;
        }

}

if (lng != lng_base) {fail = true}
if (lng == n) {fail = false}
if (fail) {
    print('NO');
} else print('YES');

var n = parseInt(readline());
var arr = readline().split(' ');
var length = -1;
var curr = 0;
var state = arr[0];
var flag = 1;
for (var i = 0; i < n; i++) {
    if (arr[i] == state) {
        curr++;
    } else {
        if (length != -1 && curr != length) {
            flag = 0;
        } else {
            length = curr;
        }
        curr = 1;
        state = arr[i];
    }
    //print(flag, curr, length, arr[i]);
}
if (length != -1 && curr != length) {
    flag = 0;
}
if (!flag) print('NO');
else print("YES");

readline();
var a = readline().split(' ').map(Number);

var last = 0;
var good = 1;
var cur = -1;
for (var i = 1; i < a.length; i++) {
    if (a[i] != a[i - 1]) {
        var curl = i - last;
        if (cur == -1) {
            cur = curl;
        } else if (cur != curl) {
            good = 0;
            cur = curl;
        }
        last = i;
    }
}

var curl = a.length - last;
if (cur != -1 && curl != cur) {
    good = 0;
}

if (good == 0) {
    print("NO");
} else {
    print("YES");
}

var n;
var temp,last;
var curL = 1,L = -1;
var flag = false;

    var n = parseInt(readline().split(' ')[0]);
    var a = readline().split(' ').map(Number);
    for (var i = 0;i < n;i++){
        var temp = a[i];
        if (i == 0){
            last = temp;
            continue;
        }
        if (temp == last) curL++;
        else {
        if (curL!=L&&L!=-1){
            print("NO");
            flag = true;
            break;
        }
        L = curL;
        curL = 1;
        }
        last = temp;
    }
    if (!flag && curL!=0 && curL!=L && L!=-1) {
        print("NO");
    } else if (!flag)
    print("YES");

readline();
var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            com = cur;
            cur = 1;
        }
    }
}
if (cur != n && (!com || cur != com)) {
    print("NO");
} else {
    print("YES");
}

var n = readline().split(" ").map(v => +v.trim())[0];
var a = readline().split(" ").map(v => +v.trim());

var len=1, i=1;
while(i < n && a[i]==a[0]) {
	i++;
	len++;
}

var ok = 1, val = a[0];

for(var j=0; j<n && ok; j+=len) {
	for(var k=0; k<len; k++)
		if(a[j]!=a[j+k] || a[j+k] != val) {
			ok = 0;
			break;
		}
	val ^= 1;
}

if(ok)
	print("YES");
else
	print("NO");

var n = parseInt(readline());
var arr = readline().split(" ").map(v => parseInt(v));

function compute() {
  var good = true;
  for (i = 0; i < n; i++) {
    if (arr[i] != arr[0]) {
      good = false;
    }
  }
  if (good == true) {
    return "YES";
  }
  var period = 0;
  for (i = 0; i < n; i++) {
    if (arr[i] != arr[0]) {
      period = i;
      break;
    }
  }
  if (n % period != 0) {
    return "NO";
  }
  for (i = period; i < n; i = i + period) {
    if (arr[i] == arr[i - 1]) {
      return "NO";
    }
    for (j = 1; j < period; j++) {
      if (arr[i + j] != arr[i + j - 1]) {
        return "NO";
      }
    }
  }
  return "YES";
}

print(compute());

var n = parseInt(readline());

var st = readline();

var check = Number(st[0]), p, inc = 1, s = 0;

for(i = 1; i < n; ++i){
    p = Number(st[i * 2]);
    if(check == p){
        ++inc;
    }else{
        if(s){
            if(inc != s){
                break;
            }
        }else{
            s = inc;
        }
        inc = 1;
        check = p;
    }
}

if(s)
    if(inc == s)
        print("YES");
    else
        print("NO");
else
    print("YES");

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var i = readline().split(' ');
var prev = 0;
var cnt = 0;
for(var j = 0; j < n; j++)
{
    if(j!=0)
    {
        if(i[j] != i[j-1])
        {    if(prev!=0 && cnt != prev)
            {
                print("NO");
                break;
            }
            prev = cnt;
             cnt = 0;
        }
    }
    cnt++
    if(prev!=0&&cnt>prev)
        {
                print("NO");
                break;
            }
    if(j==n-1 && (cnt == prev || prev == 0))
        print("YES");
    if(j == n-1 && prev!=0 && cnt != prev)
        print("NO");
}

var n = +readline();
var a = readline().split(' ').map(v => +v.trim());;

var t = 0;
for (var i = 0; i < n; i++)
    if (a[i] == a[0])
        ++t;
    else
        break;

var ok = true;
for (var i = t, cur = 1 - a[0]; i < n && ok; i += t, cur = 1 - cur)
    for (var j = i; j < i + t; j++)
        if (a[j] != cur) {
            print("NO");
            ok = false;
            break;
        }

if (ok)
    print("YES");

n = readline().split(' ').map(Number)[0];
arr = readline().split(' ').map(Number);

var zero = arr[0];
var zeros = 0;

for (i = 0; i < n; i++) {
    if (arr[i] == zero) {
        zeros++;
    } else {
        break;
    }
}

var i = 0;

var yas = true;

yas &= (n % zeros === 0);

for (i = 0; i < n; i += zeros) {
    for (var j = 0; j < zeros; j++) {
        yas &= (arr[i + j] == zero);
    }
    zero = 1 - zero;
}
if (yas) {
    print("YES");
} else {
    print("NO");
}

var n = parseInt(readline());

var gList = readline();

var f=-1;
var l=0;
var ans=true;

var prev=-1;var now = 1;

for(var i = 0; i < gList.length; i+=2){

    if (gList[i] === '1'){
        now = 1;
    } else {
        now = 0;
    }
    //print(prev+' '+now);

    if (i!=0) {

        if (prev!=now) {

            if (f==-1) {
                f=l;

                l=1;
            } else {
                //print(l);
                //print(f);
                if (l!=f) {ans=false}
                l=1;
            }

        }else {l++};

    }else {l++};
     //print(f+' '+l);
    prev=now;
}

if (f!=-1) {
    if (l!=f) {ans=false}}

if (ans) {
    print('YES')
} else{
    print('NO')
}

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

for( var i = 0; i < n; i += 1 )a[i] = parseInt( a[i] );

var cnt = 0, lnt = 0, t = true;

f = a[0];

while( a[cnt++] === f );

f = 1 - f;

cnt--;

for( var i = cnt; i < n; i ++ ){
    if( a[i] === f )lnt++;
    else{
        if( lnt != cnt ){
            write( "NO" );
            t = false;
            break;
        }
        f = 1 - f;
        lnt = 1;
    }
    //write( i + ' ' + a[i] + ' ' + cnt + ' ' + lnt + '\n' );
}

if( t && cnt != n && lnt != cnt ){
    write( "NO" );
    t = false;
}

if( t === true )
write( "YES" );

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count && w >= 0) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

isOk = function(a, n, k){
    var black = a[0];
    for(var i = 1; i < n; i++)
    if((Math.floor(i / k) % 2 === 0 && a[i] !== black) || (Math.floor(i / k) % 2 === 1 && a[i] === black)){
        return false;
    }
    return true;
};

n = parseInt(readline());
a = readline().split(' ');
res = false;
for(var i = 1; i * i <= n; i++)
if(n % i === 0){
    if(isOk(a, n, i) || isOk(a, n, Math.floor(n/i)))
        res = true;
}
if(res)
    print("YES");
else
    print("NO");

var n = readline();
var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

var white = 0, blk = 0;
var fw = 0, fb = 0;
var fixW=0, fixB=0;
var flg = 1;
for(var i=0; i<n; i++)
{
    if(numbers[i] == 0)
    {
    	if(blk)
        {
            if(fb == 0) fixB = blk;
            else if(blk != fixB) flg = 0;
            fb = 1;
            blk = 0;
        }

        white+=1;
    }
    else
    {
        if(white)
        {
            if(fw == 0) fixW = white;
            else if(white != fixW) flg = 0;
            fw = 1;
            white = 0;
        }

        blk += 1;
    }
}

if(white)
{
    if(fw == 0) fixW = white;
    else if(white != fixW) flg = 0;
    fw = 1;
    white = 0;
}

if(blk)
{
    if(fb == 0) fixB = blk;
    else if(blk != fixB) flg = 0;
    fb = 1;
    blk = 0;
}
if(fixB ==0) fixB = fixW;
if(fixW ==0) fixW = fixB;
if(flg && fixW == fixB) print("YES\n");
else print("NO\n");

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 1;
                l2 = 1;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 0;
                l1 = 1;
            }
        } else {
            l2++;
        }
    }
}
if(l1 != l2 && l1*l2 != 0)
    result = "NO";
print(result);

var line = readline().split(' ');
var n = parseInt(line[0]);

line = readline().split(' ');

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if( len && len != nowlen)
    print('NO');
else
    print('YES');

readline();
var arr = readline().split(" ");
var cur = arr[0];
var p = 0;

var ANS = "YES";

var q = 0;
for (var i = 0; i < arr.length; ++i) {
    if (arr[i] !== arr[0]) {
        break;
    }
    q++;
}

for (i = 0; i < arr.length; ++i) {
    if (cur === arr[i]) {
        p++;
        if (p > q) {
            ANS = "NO";
            break;
        }
    }
    else {
        if (p !== q) {
            ANS = "NO";
            break;
        }
        p = 1;
        cur = arr[i];
    }
}
if (p !== q) {
    ANS = "NO";
}

print(ANS);

var n=readline();
var w = readline().split(' ').map(function(x) { return parseInt(x);});
var cnt=0,y=-1;
var last=-1,ans=1;
for(var i=0;i<n;i++){
    var x = w[i];
    if(last===-1)
        last=x;
    if(x===last)
        cnt++;
    else{
        if(y===-1)
            y=cnt;
        else{
            if(cnt!==y)
                ans=0;
        }
        cnt=1;
        last=x;
    }
}
if(ans===0)
    print("NO");
else if(y!==-1&&cnt!==y)
    print("NO");
else
    print("YES");

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

var line = readline().split(' ');
var n = parseInt(line[0]);

line = readline().split(' ');

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if(!len || len != nowlen)
    print('NO');
else
    print('YES');

var line = readline().split(' ');
var n = parseInt(line[0]);

line = readline().split(' ');

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if(len != nowlen)
    print('NO');
else
    print('YES');

var n = readline();
var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

var white = 0, blk = 0;
var fw = 0, fb = 0;
var fixW, fixB;
var flg = 1;
for(var i=0; i<n; i++)
{
    if(numbers[i] == 0)
    {
        if(fb == 0) fixB = blk;
        else if(blk != fixB) flg = 0;
        fb = 1;

        white+=1;
    }
    else
    {
        if(fw == 0) fixW = white;
        else if(white != fixW) flg = 0;
        fw = 1;
        white = 0;

        blk += 1;
    }
}

if(flg) print("YES\n");
else print("NO\n");

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = n;
var hopaayega = true;
for(var i=0;i<n;i++){
    var curr = parseInt(a[i]);
    if(a[i] != a[0]){
        cycl = i;
        break;
    }
}
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = 0;
var hopaayega = true;
//for(var i=0;i<n;i++){
//    var curr = parseInt(a[i]);
//    if(a[i] != a[0]){
//        cycl = i;
//        break;
//    }
//}
while(a[cycl] === a[0]) cycl ++;
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = n;
var hopaayega = true;
for(var i=0;i<n;i++){
    var curr = parseInt(a[i]);
    if(a[i] != a[0]){
        cycl = i;
        break;
    }
}
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var prev = parseInt(a[i-1]);
        if(i%cycl){
            if(curr != prev){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == prev){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            cur = 1;
        }
    }
}
if (!com || cur != com) {
    print("NO");
} else {
    print("YES");
}

readline();
var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            com = cur;
            cur = 1;
        }
    }
}
if (!com || cur != com) {
    print("NO");
} else {
    print("YES");
}

readline();
var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            com = cur;
            cur = 1;
        }
    }
}
if ((!com && cur != n) || cur != com) {
    print("NO");
} else {
    print("YES");
}

var n = readline().split(" ").map(v => +v.trim())[0];
var a = readline().split(" ").map(v => +v.trim());

var len=1, i=1;
while(i < n && a[i]==a[0]) {
	i++;
	len++;
}

var ok = 1;
for(var j=0; j<n && ok; j+=len) {
	for(var k=0; k<len; k++)
		if(a[j]!=a[j+k]) {
			ok = 0;
			break;
		}
}

if(ok)
	print("YES");
else
	print("NO");

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count && w > 0) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

var n = parseInt(readline());

var st = readline();

var check = Number(st[0]), p, inc = 1, s = 0;

var i

for(i = 1; i < n; ++i){
    p = Number(st[i * 2]);
    if(check == p){
        ++inc;
    }else{
        if(s){
            if(inc != s){
                break;
            }
        }else{
            s = inc;
        }
        inc = 1;
        check = p;
    }
}

if(inc == s)
    print("YES");
else
    print("NO");

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 1;
                l2 = 0;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 0;
                l1 = 0;
            }
        } else {
            l2++;
        }
    }
}
if(l1 != l2 && l1*l2 != 0)
    result = "NO";
print(result);

                print(l1);
                print(l2);

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 1;
                l2 = 0;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 0;
                l1 = 0;
            }
        } else {
            l2++;
        }
    }
    print(l1);
    print(l2);
}
if(l1 != l2 && l1*l2 != 0)
    result = "NO";
print(result);

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NOp";
            } else {
                x = 1;
                l2 = 0;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NOd";
            } else {
                x = 0;
                l1 = 0;
            }
        } else {
            l2++;
        }
    }
}
if(l1 != l2 && l1*l2 != 0)
    result = "NOg";
print(result);


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

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

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

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

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

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

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

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

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

  let suf = arr => {
    // log(arr)
    out.push([arr.length, ...arr].join(' '))
    let s = 0;
    let na = []
    arr.forEach(v => {
      na.push(a.slice(s, s += v))
    })
    a = na.reverse().flat()
    // log(a)
    // log('---')
  }

  let join = x => {
    let vx1 = a.findIndex(v => v == x - 1)
    let v1 = a.findIndex(v => v == 1)
    let vx = a.findIndex(v => v == x)
    if (v1 == vx1) {
      if (vx > v1) {
        suf([v1, 1, vx - v1, n - 1 - vx].filter(v => v))
      } else {
        suf([vx, 1, v1 - vx, n - 1 - v1].filter(v => v))
      }
    } else {
      if (v1 > vx1 && v1 > vx) {
        suf([vx, vx1 - vx, ...Arr(x - 1, i => 1), n - 1 - v1].filter(v => v))
      } else if (v1 > vx1 && v1 < vx) {
        suf([vx1, x - 1, vx - v1, n - 1 - vx].filter(v => v))
      } else if (v1 < vx1 && v1 > vx) {
        suf([vx, v1 - vx, x - 1, n - 1 - vx1].filter(v => v))
      } else {
        suf([v1, ...Arr(x - 1, i => 1), vx - vx1, n - 1 - vx].filter(v => v))
      }
    }
  }
  For(2, n, i => {
    join(i)
  })
  if (n > 1 && a[0] != 1) suf(Arr(n, i => 1))
  log(out.length)
  log(out.join('\n'))
}

'use strict';

var readline = require('readline');

function constantNumberofLinesStdin(lines) {
  return new Promise(resolve => {
    const stdin = readline.createInterface(process.stdin);
    const output = [];
    stdin.on('line', line => {
      output.push(line);

      if (output.length === lines) {
        resolve(output);
        stdin.close();
      }
    });
  });
}

function solve(cards) {
  const output = [];
  const n = cards.length;
  const lastIndex = n - 1;

  function isSolved() {
    return n === 1 || cards.slice(1).every((c, i) => c > cards[i]);
  }

  function performAction(groupSizes) {
    output.push(groupSizes.length + ' ' + groupSizes.join(' '));
    const swapped = [];
    let index = 0;

    for (const size of groupSizes) {
      swapped.splice(0, 0, ...cards.slice(index, index + size));
      index += size;
    }

    cards = swapped;
  }

  while (!isSolved()) {
    let currentOrder;

    if (cards[0] === 1 || cards[lastIndex] === n) {
      currentOrder = 'asc';
    } else if (cards[lastIndex] === 1 || cards[0] === n) {
      currentOrder = 'desc';
    } else {
      currentOrder = n & 1 ? 'asc' : 'desc';
    }

    let leadingDone = 0,
        trailingDone = 0;

    if (currentOrder === 'asc') {
      while (cards[leadingDone] === leadingDone + 1) {
        leadingDone++;
      }

      while (cards[lastIndex - trailingDone] === n - trailingDone) {
        trailingDone++;
      }
    } else {
      while (cards[leadingDone] === n - leadingDone) {
        leadingDone++;
      }

      while (cards[lastIndex - trailingDone] === trailingDone + 1) {
        trailingDone++;
      }
    }

    if (leadingDone === n) {
      trailingDone = 0;
    }

    const lastLeadingDone = cards[leadingDone - 1] || (currentOrder === 'asc' ? 0 : n + 1);
    const targetCard = currentOrder === 'asc' ? lastLeadingDone + 1 : lastLeadingDone - 1;
    const targetIndex = cards.indexOf(targetCard);
    const action = [];

    for (let x = 0; x < leadingDone; x++) {
      action.push(1);
    }

    if (targetIndex >= 0) {
      const left = targetIndex - leadingDone + 1;
      const right = n - leadingDone - left - trailingDone;
      action.push(left);

      if (right) {
        action.push(right);
      }
    }

    for (let x = 0; x < trailingDone; x++) {
      action.push(1);
    }

    performAction(action);
  }

  console.log(output.length);
  output.forEach(line => console.log(line)); // [3] [1 2 4]          Moves: 4
  // [1] [2] [4 3]        Moves: 3
  // 4 3 2 1              Moves: 2
  // 1 2 3 4
  // [6 8 4 9 1] [2 3 7 5]
  // [2 3 7 5 6 8 4 9] [1]
  // [1] [2] [3] [7 5 6 8 4] [9]
  // [9] [7] [5 6 8] [4] [3] [2] [1]
  // [1] [2] [3] [4] [5] [6] [8 7] [9]
  // [9] [8] [7] [6] [5] [4] [3] [2] [1]
  // 1 2 3 4 5 6 7 8 9
}

async function main() {
  const input = await constantNumberofLinesStdin(2);
  solve(input[1].split(' ').map(Number));
}

main().then();


const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", loop =>{
  getUserInput(loop);
})

function getUserInput(n) {
    rl.question('', (number) => {
        rl.question("", number => {
            let fi = number.indexOf("1");
            let li = number.lastIndexOf("1");
            //console.log(fi, li);
            number = number.substring(fi,li+1);
            //console.log(number);
            let arr = number.split(" ")
            //console.log(arr);
            console.log(countZeros(arr));
            if (n > 1) {
                getUserInput(n-1);
            } else {
                rl.close();
            }
        })
    });
}

function countZeros(arr){
    let count = 0;
    for (let index = 0; index < arr.length; index++) {
        if(arr[index] == 0)
            ++count;
    }
    return count;
}

rl.on("close", function() {
    process.exit(0);
});

var problem = function(arr) {

    var count = 0, first = arr.indexOf('1'), last = arr.lastIndexOf('1'), a = arr.slice(first, last);
    for (var i = 0; i < arr.length; i++) {
        if (a[i] == 1) count++;
    }
    return (a.length - count);

}

var tests = readline();

for (var i = 0; i < tests; i++) {

        var n, items;
        n = readline();
        items = readline().split(" ");
        print(problem(items));

}

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

let mem = new Map();
function query(arr){
    let RES = 0;
    let last_i = arr.lastIndexOf(1);
    let had;
    for (let i=0; i<last_i; i++)
    {
        if (arr[i])
            had = true;
        else
        {
            if (had)
                RES++;
        }
    }
    return RES
}

function main() {
    var q = +readline();
    while (q--)
    {
        var n = +readline();
        let arr = readline().split(' ').map(a=>+a);
        print(query(arr));
    }
}

const solve = (shelf) => {
    let start = shelf.indexOf(1);
    let end = shelf.lastIndexOf(1);
    if (start == end) return 0;
    let cnt = 0;
    for (let i = start; i <= end; i++) {
        if (shelf[i] == 0) {
            cnt++;
        }
    }
    return cnt;
};

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.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = Number(input[0][0]);
        let i = 2;
        while (t > 0) {
            let data = input.slice(i, i + 1);
            console.log(solve(data[0]));
            t--;
            i += 2;
        }
    });
};

main()

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

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

  data.push(line);

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

});

function goToSolution(data) {
  data.forEach((shelf, i) => {
    if(i % 2 !== 0) {
      let spaceZeroes = 0;
      let tempZeroes = 0;
      let booksDetected = false;
      for(let i = 0; i < shelf.length; i+=2) {
        if(shelf[i] == 1) {
          if(booksDetected) {
            spaceZeroes += tempZeroes;
          } else {
            booksDetected = true;
          }
          tempZeroes = 0;
        } else {
          tempZeroes++;
        }
      }

      console.log(spaceZeroes);
    }
  })
}

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

let isT = true;
let inputLength;
let inputShelf;
let inputCounter = 0;

readLine.on("line", line => {
    if (isT) {
        isT = false;
    } else {
        if (inputCounter == 1) {
            inputShelf = line;
            countMoves(inputLength ,inputShelf);
            inputCounter = 0;
        } else {
            inputLength = line;
            inputCounter++;
        }
    }
});

function countMoves(length, shelf) {
    length = parseInt(length);
    let shelfArr= [];
    for (let i = 0; i < shelf.length; i += 2) {
        shelfArr.push(shelf[i]);
    }
    let movesSum = 0;
    let outerFlag = false;
    let met = 0;
    let numberOfBooks = 0;
    for (let i = 0; i < shelfArr.length; i++) {
        if(shelfArr[i] == 1) {
            numberOfBooks++;
        }
    }
    for (let i = 0; i < shelfArr.length; i++) {
        if (shelfArr[i] == 1) {
            met++;
            if(met == numberOfBooks) {
                break;
            }
            outerFlag = true;
        } else if (shelfArr[i] == 0 && outerFlag === true) {
            movesSum++;
        }
    }
    if (met < 2) {
        movesSum = 0;
    }
    console.log(movesSum);
}

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine().split(" ").map(Number);
    let [first1, last1] = [arr.indexOf(1), arr.lastIndexOf(1)];

    if (first1 === last1) console.log(0);
    else {
      let count = 0;
      for (let i = first1; i <= last1; i++) {
        if (arr[i] === 0) count++;
      }
      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 L = -1;
		var R = -1;
		var zero = 0;
		for(var j = 0; j < N; j++){
			if(list[j] == 1){
				L = j;
				break;
			}
		}
		for(var j = N - 1; j >= 0; j--){
			if(list[j] == 1){
				R = j;
				break;
			}
		}
		for(var j = L; j <= R; j++){
			if(list[j] == 0){
				zero++;
			}
		}
		output[i] = zero;
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim();
      // const n = data[i] * 1;
      // const k = a[1];
      const s = data[i + 1].trim().split(' ').map(Number);
      // s.sort((a, b) => b - a);
      let first = s.indexOf(1);
      let arr = [];
      let min = 0;

      for (let j = first + 1; j < s.length; j += 1) {
        if (s[j] === 1) arr.push(j);
      }

      while (arr.length) {
        let diff = arr.shift();
        if (diff - first === 1) {first = diff; continue;}
        diff =  diff - first - 1;
        min += diff;
        arr = arr.map(a => a - diff);
        first += 1;
      }

      console.log(min);
      i += 2;
    }
}

//cat q2.text | node q2.js
'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();
    for (let i = 0; i < x; i++) {
        let y = readline();
        let z = readline().split(" ");
        console.log(Bookshelf(y,z))
    }
}

function Bookshelf(len, data) {

    let ans = 0;

    let firstIndex = data.indexOf("1");
    let lastIndex = data.lastIndexOf("1");

    for (let i = firstIndex; i < lastIndex; i++) {
        if (data[i] == 0) {
            ans++
        }
    }

    return ans;

}

var t = parseInt(readline());

while (t--) {
    var n = parseInt(readline());
    var f = 0;
    var ar = readline().split(' ').map(function(x) { return parseInt(x); });
    ar.forEach(function(x) { if (x == 1) f = 1 });
    if (!f) {
        print("0");
        continue;
    }
    var first = -1, last = -1;
    for (var i = 0; i < ar.length; ++i) if (ar[i] == 1) {
        first = i;
        break;
    }
    for (var i = ar.length-1; i >= 0; --i) if (ar[i] == 1) {
        last = i;
        break;
    }
    var cnt = 0;
    for (var i = first; i <= last; ++i) {
        cnt += ar[i] == 0;
    }
    print(cnt);
}

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

let isT = true;
let inputLength;
let inputShelf;
let inputCounter = 0;

readLine.on("line", line => {
    if (isT) {
        isT = false;
    } else {
        if (inputCounter == 1) {
            inputShelf = line;
            countMoves(inputLength ,inputShelf);
            inputCounter = 0;
        } else {
            inputLength = line;
            inputCounter++;
        }
    }
});

function countMoves(length, shelf) {
    length = parseInt(length);
    let shelfArr= [];
    for (let i = 0; i < shelf.length; i += 2) {
        shelfArr.push(shelf[i]);
    }
    let movesSum = 0;
    let outerFlag = false;
    let metAnother = false;
    for (let i = 0; i < shelfArr.length; i++) {
        if (shelfArr[i] == 1) {
            if(outerFlag === true) {
                metAnother = true;
            }
            outerFlag = true;
        } else if (shelfArr[i] == 0 && outerFlag === true) {
            movesSum++;
        }
    }
    if (!metAnother) {
        movesSum = 0;
    }
    console.log(movesSum);
}

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", loop =>{
  getUserInput(loop);
})

function totalPressedDigit(number){
    let digit = number[0];
    let length = number.length;
    console.log( (digit-1) * 10 + length*(length+1)/2);
}

function getUserInput(n) {
    rl.question('', (number) => {
        rl.question("", number => {
            let fi = number.indexOf("1");
            let li = number.lastIndexOf("1");
            number = number.substring(fi,li);
            let arr = number.split(" ");
            console.log(countZeros(arr));
            if (n > 1) {
                getUserInput(n-1);
            } else {
                rl.close();
            }
        })

    });
}

function countZeros(arr){
    let count = 0;
    for (let index = 0; index < arr.length; index++) {
        if(arr[index] == 0)
            ++count;
    }
    return count;
}

rl.on("close", function() {
    console.log("\nBYE BYE !!!");
    process.exit(0);
});

'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() {
    var x = readline();
   // var y = readline(); // first line of input usually gives the no. of test cases,i.e, the no. of lines ahead.
   // var inp; // declaring the variable outside the loop
    for (var i = 0; i < x; i++) {
        var y = readline();
        let inp = readline().split(" ");
        console.log(foo(inp))
    }

}

function foo(digit){

    let count = 0;
    let firstIndex = digit.indexOf("1");
    let secondIndex = digit.lastIndexOf(`1`);
    let max = firstIndex
    for(let i =0; i < digit.length; i++){
      if(digit[i] ==1 && i !== secondIndex){
          max = Math.max(i,max)
      }
    }

    if(firstIndex == secondIndex){
        return 0;
    }
    if(firstIndex == max){
        return secondIndex - max -1;
    }
 //   console.log(max,firstIndex,secondIndex)
    return secondIndex - max;

}

var problem = function(arr) {

    var count = 0, first = arr.indexOf('1'), last = arr.lastIndexOf('1'), a = arr.slice(first, last);
    for (var i = 0; i < arr.length; i++) {
        if (a[i] == 1) count++;
    }
    return (a.length - count);

}

var tests = readline();

for (var i = 0; i < tests; i++) {

        var n, items;
        //n = readline();
        items = readline().split(" ");
        print(problem(items));

}


if (process.env.ANT)
{
    global.print = this.print ||
        function(){console.log([...arguments].join(' '))} ||
        require('lol-io').print;
    global.write = this.write || require('lol-io').write
    global.readline = this.readline || require('lol-io').readline
    main();
}
else
{
    const rl = require('readline').createInterface({ input: process.stdin,
        output: process.stdout });
    global.print = console.log
    global.write = (...args) => {
        process.stdout.write(args.join(' '));
    }
    const lines = []
    rl.on('line', line =>{
        lines.push(line);
    });
    rl.on('close', main)
    let rli = 0;
    global.readline = ()=>lines[rli++];
}

///////////// CODE

function main(){

    var n = +readline();
    var arr = readline().split(' ').map(x=>+x);

    function gcd(a, b){
        if (a%b==0)
            return b;
        return gcd(b, a%b);
    }
    let g = arr[0];

    for (let i=1; i<arr.length; i++)
        g = gcd(g, arr[i]);

    const sqrt = Math.sqrt(g)|0;
    let ans = 0;
    for (i=1; i<=sqrt; i++)
    {
        if (g%i)
            continue;
        ans++;
        if (g/i!=i)
            ans++;
    }

    print(ans)

}

'use strict'

const gcd = (a,b) => {
    let c;
    if (a < b) { c = b; b = a; a = c; }
    while(b) { c = b; b = a % b; a = c; }
    return a;
};

readline();
const x = readline().split(' ').map(Number);
const m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);
const mRoot = Math.floor(Math.sqrt(m));
let r = 1;
for (let i = 2; i < mRoot + 1; i++) { if (m % i === 0) r++; }
write(2 * r - +(Math.pow(mRoot, 2) === m));

if (process.env.ANT)
{
    global.print = this.print ||
        function(){console.log([...arguments].join(' '))} ||
        require('lol-io').print;
    global.write = this.write || require('lol-io').write
    global.readline = this.readline || require('lol-io').readline
    main();
}
else
{
    const rl = require('readline').createInterface({ input: process.stdin,
        output: process.stdout });
    global.print = console.log
    global.write = (...args) => {
        process.stdout.write(args.join(' '));
    }
    const lines = []
    rl.on('line', line =>{
        lines.push(line);
    });
    rl.on('close', main)
    let rli = 0;
    global.readline = ()=>lines[rli++];
}

///////////// CODE

function main(){

    var n = +readline();
    var arr = readline().split(' ').map(x=>+x);

    function gcd(a, b){
        if (b)
            return a%b;
        return a;
    }
    let g = arr[0];

    for (let i=1; i<arr.length; i++)
        g = gcd(g, arr[i]);

    const sqrt = Math.sqrt(g)|0;
    let ans = 0;
    for (i=1; i<=sqrt; i++)
    {
        if (g%i)
            continue;
        ans++;
        if (g/i!=i)
            ans++;
    }

    print(ans)

}

'use strict'

const gcd = (a,b) => {
    let c;
    if (a < b) { c = b; b = a; a = c; }
    while(b) { c = b; b = a % b; a = c; }
    return a;
};

readline();
const x = readline().split(' ').map(Number);
const m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);
let r = 1;
const mRoot = Math.floor(Math.sqrt(m));
for (let i = 2; i < mRoot + 1; i++) { if (m % i === 0) r++; }
write(2 * r - +(Math.pow(mRoot, 2) === r)) ;

'use strict'

const gcd = (a,b) => {
    let c;
    if (a < b) { c = b; b = a; a = c; }
    while(b) { c = b; b = a % b; a = c; }
    return a;
};

readline();
const x = readline().split(' ').map(Number);
const m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);
let r = 0;
for (let i = 1; i < Math.sqrt(m) + 1; i++) { if (m % i === 0) r++; }
write(2 * r - +(Math.pow(Math.floor(Math.sqrt(r)), 2) === r)) ;