var nq = readInts();
var n  = nq[0];
var q  = nq[1];

var total = new Array(n + 1);
var max   = new Array(n + 1);
var ans   = new Array(n + 1);
var p     = new Array(n + 1);
var e     = new Array(n + 1);
var done  = new Array(n + 1);

p[1] = 1;

var i = 0;
var ps = readInts();
for (; i < n - 1; i++) {
    p[i + 2] = ps[i];
    e[ps[i]] = e[ps[i]] || [];
    e[ps[i]].push(i + 2);
}

 // dfs(1);
var stack = [1];
while (stack.length) {
    var u = stack[stack.length - 1];
    // print (u, done[u]);
    if (done[u]) {
        if (u !== 1) {
            total[p[u]] += total[u];
            if (!max[p[u]] || total[u] > total[max[p[u]]]) {
                max[p[u]] = u;
            }
        }

        if (!max[u]) {
            max[u] = u;
        }

        ans[u] = find(u);
        stack.pop();
        continue;
    }

    done[u] = true;
    total[u] = 1;
    // print (u, done[u]);

    if (e[u]) {
        for (var i = 0, len = e[u].length; i < len; i++) {
            stack.push(e[u][i]);
        }
    }
}

// print(total);
// print(max);
// print(ans);

for (i = 0; i < q; i++) {
    var v = parseInt(readline(), 10);
    print(ans[v]);
}

/**
 * functions below
 */

function readInts() {
    return readline().split(' ').map(function(v) {
        return parseInt(v, 10);
    })
}

function find(u) {
    if (total[u] <= 2) {
        return u;
    }

    var half = total[u] / 2;

    if (total[max[u]] <= half) {
        return u;
    }

    var start = ans[max[u]];
    while (start != u) {
        var top = total[u] - total[start];
        var bottom = total[max[start]];
        if (top <= half && bottom <= half) {
            return start;
        }

        start = p[start];
    }

    return 0;
}

function dfs(u) {
    if (!e[u]) {
        ans[u] = u;
        max[u] = u;
        total[u] = 1;
        return 1;
    }

    var localMax = 0;
    var localMaxI = u;
    var tot = 1;
    for (var i = 0, len = e[u].length; i < len; i++) {
        var tmp = dfs(e[u][i]);
        tot += tmp;
        if (localMax < tmp) {
            localMax = tmp;
            localMaxI = e[u][i];
        }
    }

    total[u] = tot;
    max[u] = localMaxI;

    // calc ans
    ans[u] = find(u);

    return tot;
}

var nq = readInts();
var n  = nq[0];
var q  = nq[1];

var total = new Array(n + 1);
var max   = new Array(n + 1);
var ans   = new Array(n + 1);
var p     = new Array(n + 1);
var e     = new Array(n + 1);
var done  = new Array(n + 1);

p[1] = 1;
total[0] = 0;

var i = 0;
var ps = readInts();
for (; i < n - 1; i++) {
    p[i + 2] = ps[i];
    e[ps[i]] = e[ps[i]] || [];
    e[ps[i]].push(i + 2);
}

var queue = [1];
i = 0;
while (1) {
    var to = e[queue[i]];
    if (to) {
        for (var j = 0; j < to.length; j++) {
            queue.push(to[j]);
        }
    }
    i++;
    if (i === queue.length) {
        break;
    }
}
queue.reverse();

for (i = 0, len = queue.length; i < len; i++) {
    var u = queue[i];
    total[u] = 1;
    max[u] = 0;
    var to = e[u];
    if (to) {
        for (var j = 0; j < to.length; j++) {
            total[u] += total[to[j]];
            if (total[to[j]] > total[max[u]]) {
                max[u] = to[j];
            }
        }
    }
    if (!max[u]) {
        max[u] = u;
    }

    ans[u] = find(u);
}

 // dfs(1);
// var stack = [1];
// while (stack.length) {
//     var u = stack[stack.length - 1];
//     // print (u, done[u]);
//     if (done[u]) {
//         if (u !== 1) {
//             total[p[u]] += total[u];
//             if (!max[p[u]] || total[u] > total[max[p[u]]]) {
//                 max[p[u]] = u;
//             }
//         }

//         if (!max[u]) {
//             max[u] = u;
//         }

//         ans[u] = find(u);
//         stack.pop();
//         continue;
//     }

//     done[u] = true;
//     total[u] = 1;
//     // print (u, done[u]);

//     if (e[u]) {
//         for (var i = 0, len = e[u].length; i < len; i++) {
//             stack.push(e[u][i]);
//         }
//     }
// }

// print(total)
// print(max)
// print(ans)

for (i = 0; i < q; i++) {
    var v = parseInt(readline(), 10);
    print(ans[v]);
}

/**
 * functions below
 */

function readInts() {
    return readline().split(' ').map(function(v) {
        return parseInt(v, 10);
    })
}

function find(u) {
    if (total[u] <= 2) {
        return u;
    }

    var half = total[u] / 2;

    if (total[max[u]] <= half) {
        return u;
    }

    var start = ans[max[u]];
    while (start != u) {
        var top = total[u] - total[start];
        var bottom = total[max[start]];
        if (top <= half && bottom <= half) {
            return start;
        }

        start = p[start];
    }

    return 0;
}

function dfs(u) {
    if (!e[u]) {
        ans[u] = u;
        max[u] = u;
        total[u] = 1;
        return 1;
    }

    var localMax = 0;
    var localMaxI = u;
    var tot = 1;
    for (var i = 0, len = e[u].length; i < len; i++) {
        var tmp = dfs(e[u][i]);
        tot += tmp;
        if (localMax < tmp) {
            localMax = tmp;
            localMaxI = e[u][i];
        }
    }

    total[u] = tot;
    max[u] = localMaxI;

    // calc ans
    ans[u] = find(u);

    return tot;
}

var nq = readInts();
var n  = nq[0];
var q  = nq[1];

var total = new Array(n + 1);
var max   = new Array(n + 1);
var ans   = new Array(n + 1);
var p     = new Array(n + 1);
var e     = new Array(n + 1);
var done  = new Array(n + 1);

p[1] = 1;

var i = 0;
var ps = readInts();
for (; i < n - 1; i++) {
    p[i + 2] = ps[i];
    e[ps[i]] = e[ps[i]] || [];
    e[ps[i]].push(i + 2);
}

 // dfs(1);
var stack = [1];
while (stack.length) {
    var u = stack[stack.length - 1];
    // print (u, done[u]);
    if (done[u]) {
        if (u !== 1) {
            total[p[u]] += total[u];
            if (!max[p[u]] || total[u] > total[max[p[u]]]) {
                max[p[u]] = u;
            }
        }

        ans[u] = find(u);
        stack.pop();
        continue;
    }

    done[u] = true;
    total[u] = 1;
    // print (u, done[u]);

    if (e[u]) {
        for (var i = 0, len = e[u].length; i < len; i++) {
            stack.push(e[u][i]);
        }
    }
}

for (i = 0; i < q; i++) {
    var v = parseInt(readline(), 10);
    print(ans[v]);
}

/**
 * functions below
 */

function readInts() {
    return readline().split(' ').map(function(v) {
        return parseInt(v, 10);
    })
}

function find(u) {
    if (total[u] <= 2) {
        return u;
    }

    var half = total[u] / 2;

    if (max[u] <= half) {
        return u;
    }

    var start = ans[max[u]];
    while (start != u) {
        var top = total[u] - total[start];
        var bottom = total[max[start]];
        if (top <= half && bottom <= half) {
            return start;
        }

        start = p[start];
    }

    return 0;
}

function dfs(u) {
    if (!e[u]) {
        ans[u] = u;
        max[u] = u;
        total[u] = 1;
        return 1;
    }

    var localMax = 0;
    var localMaxI = u;
    var tot = 1;
    for (var i = 0, len = e[u].length; i < len; i++) {
        var tmp = dfs(e[u][i]);
        tot += tmp;
        if (localMax < tmp) {
            localMax = tmp;
            localMaxI = e[u][i];
        }
    }

    total[u] = tot;
    max[u] = localMaxI;

    // calc ans
    ans[u] = find(u);

    return tot;
}


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

module.exports = E;

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

const EPS = 1e-6;

const get_cnt = ()=>{
  let cnt = new Map();
  for (let i=-2; i<=2; i++)
    cnt.set(i, 0);
  return cnt;
};

const split = (arr)=>{
  let i=0;
  let sets = [];
  let cur_set = {l: 0, cnt: get_cnt()}
  while (i<arr.length){
    if (arr[i]==0){
      cur_set.r = i;
      if (cur_set.cnt.size)
        sets.push(cur_set);
      cur_set = {l: i+1, cnt: get_cnt()};
      i++;
      continue;
    }
    cur_set.cnt.set(arr[i], cur_set.cnt.get(arr[i])+1);
    i++
  }
  cur_set.r = arr.length
  if (cur_set.cnt.size)
    sets.push(cur_set);
  return sets;
};

const processSet = ({l, r, cnt}, arr)=>{
  debugger
  let power = cnt.get(2) + cnt.get(-2);
  let sign = (cnt.get(-2)+cnt.get(-1));
  let rm_left = 0;
  let rm_right = 0;
  if (sign%2==0){
    return {power, rm_left, rm_right};
  }
  let left_cnt = new Map(cnt);
  let right_cnt = new Map(cnt);
  let i;
  // rm_left
  for (i=l; i<r; i++){
    left_cnt.set(arr[i], left_cnt.get(arr[i])-1)
    if (arr[i]<0){
      break;
    }
  }
  let left_ans = {power: left_cnt.get(2) + left_cnt.get(-2), rm_left: i-l+1, rm_right: 0};
  // rm_right
  for (i=r-1; i>=l; i--){
    right_cnt.set(arr[i], right_cnt.get(arr[i])-1)
    if (arr[i]<0){
      break;
    }
  }
  let right_ans = {power: right_cnt.get(2) + right_cnt.get(-2), rm_left: 0, rm_right: r-i};
  if (left_ans.power>right_ans.power)
    return left_ans;
  else
    return right_ans;
}

const calc = (arr, n)=>{
  let sets = split(arr);
  let maxPower = 0;
  let ans = [arr.length, 0];
  for (let set of sets){
    let {power, rm_left, rm_right} = processSet(set, arr);
    if (power>maxPower){
      maxPower = power;
      ans = [set.l+rm_left, n-set.r+rm_right];
    }
  }
  return ans.join(' ');
  //console.log(arr, '->', sets);
  return
  // set = {l: int, r: int, cnt: Map}
  let l=0, r=0;
  let cnt = new Map();
  for (let i=-2; i<=2; i++)
    cnt.set(i, 0);
  while (l<n){

  }
};

function main() {
    let T = +readline();
    while (T--){
      let n = +readline();
      let arr = ra();
      print(calc(arr, n))
    }
}

E.calc = calc;

var n, a;

    function solve(s, e) {
        var negs = 0;
        var bits = 1;
        for (var i = s; i <= e; i++) {
            if (a[i] < 0) {
                negs++;
            }
            if (Math.abs(a[i]) == 2) {
                bits++;
            }
        }
        if (negs & 1) {
            var b = s;
            var bitsS = bits;
            while (a[b] > 0) {
                if (Math.abs(a[b]) == 2) {
                    bitsS--;
                }
                b++;
            }
            if (Math.abs(a[b]) == 2) {
                bitsS--;
            }
            var c = e;
            var bitsE = bits;
            while (a[c] > 0) {
                if (Math.abs(a[c]) == 2) {
                    bitsE--;
                }
                c--;
            }
            if (Math.abs(a[c]) == 2) {
                bitsE--;
            }
            //console.log(bits, bitsS, bitsE)
            if (bitsS > bitsE) {
                return [bitsS, b+1, e];
            } else {
                return [bitsE, s, c-1];
            }
        } else {
            return [bits, s, e];
        }
    }
    var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        var start = 0;
        var ans = [1, 0, -1];
        while (start < n) {
            while (start < n && !a[start]) {
                start++;
            }
            var end = start+1;
            while (end < n && a[end]) {
                end++;
            }
            var reply = solve(start, end-1);
            //console.log(reply);
            if (reply[0] > ans[0]) {
                ans = reply;
            }
            start = end;
        }
        print(ans[1] + " " + (n - ans[2] - 1));
    }

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function getMax(a, start, end) {
  var _a, _b
  const n = end - start + 1
  let first = -1,
    last = -1,
    sum = new Array(n).fill(0),
    count = 0
  for (let i = 0; i < n; i++) {
    sum[i] = ((_a = sum[i - 1]) !== null && _a !== void 0 ? _a : 0) + (Math.abs(a[i + start]) === 2 ? 1 : 0)
    if (first === -1 && a[i + start] < 0) first = i
    if (a[i + start] < 0) {
      count++
      last = i
    }
  }
  if (count % 2 === 0) {
    return [sum[n - 1] * 2, start, end]
  } else {
    let left = ((_b = sum[last - 1]) !== null && _b !== void 0 ? _b : 0) * 2 + (last > 0 ? 1 : 0),
      right = (sum[n - 1] - sum[first]) * 2 + (first < n - 1 ? 1 : 0)
    if (left >= right) {
      return [left, start, start + last - 1]
    } else {
      return [right, start + first + 1, end]
    }
  }
}
function solve(n, a) {
  let left = -1,
    right = -1,
    max = 1
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) {
      let j = i
      while (j < n - 1 && a[j + 1] !== 0) j++
      const [num, l, r] = getMax(a, i, j)
      if (max < num) {
        max = num
        left = l
        right = r
      }
      i = j
    }
  }
  if (left === -1) return [0, n]
  else return [left, n - right - 1]
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    const a = inputs[__++].trim().split(' ').map(Number)
    const [l, r] = solve(n, a)
    res.push(`${l} ${r}`)
  }
  console.log(res.join('\n'))
})()

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

		let ans, mx = 0;
		for (let round = 0; round < 2; round++) {
			let twos = 0, positive = 1, cnt = 0;
			for (let i = 0; i < n; i++) {
				if (a[i] == 0) cnt = 0, twos = 0, positive = 1; else cnt++;
				if (a[i] < 0) positive ^= 1;
				if (Math.abs(a[i]) == 2) twos++;
				if (positive & twos > mx) {
					mx = twos;
					ans = [(i + 1) - cnt, n - (i + 1)];
					if (round) ans.reverse();
				}
				//console.log({round, i, twos, positive, mx, cnt, ans});
			}
			a.reverse();
		}

		if (mx == 0) {
			console.log(n, 0);
		} else {
			console.log(ans.join(' '));
		}

	}
}

const readline = require('readline')

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

function solve(n, nums) {
    let ans = [-1, 3 * n]
    let pos
    let neg
    let pp = -1, pn = -1
    let seg
    nums.forEach((x, i) => {
        if (i) {
            const [sp, vp] = pos
            const [sn, vn] = neg
            if (x > 0) {
                // pos *= x
                // neg *= x
                const pow = x === 1 ? 0 : 1
                pos = [1, vp + pow]
                neg = [sn, vn + pow]
                // ans = Math.max(ans, pos, neg)
                if (pp < 0) pp = i
                if (pn < 0) pn = i
                // if (pos > ans) {
                if (cmp(pos, ans) > 0) {
                    ans = pos
                    seg = [pp, i]
                }
            } else if (x < 0) {
                const pow = x === -1 ? 0 : 1
                if (neg[0] < 0) {
                    if (pp < 0) pp = i
                    if (pn < 0) pn = i
                    // ;[pos, neg] = [neg * x, pos * x]
                    pos = [-sn, vn + pow]
                    neg = [-sp, vp + pow]
                    ;[pp, pn] = [pn, pp]
                    // ans = Math.max(ans, pos, neg)
                    if (cmp(pos, ans) > 0) {
                        ans = pos
                        seg = [pp, i]
                    }
                    if (cmp(neg, ans) > 0) {
                        ans = neg
                        seg = [pn, i]
                    }
                } else {
                    if (pp < 0) pp = i
                    // ;[pos, neg] = [1, pos * x]
                    ;[pp, pn] = [-1, pp]
                    pos = [1, 0]
                    neg = [-1, vp + pow]
                    // ans = Math.max(ans, neg)
                    //
                    if (cmp(neg, ans) > 0) {
                        ans = neg
                        seg = [pn, i]
                    }
                }
            } else {
                // pos = 1
                // neg = 1
                pos = [1, 0]
                neg = [1, 0]
                pp = -1
                pn = -1
                // ans = Math.max(ans, 0)
                //
                if (cmp([1, -1], ans) > 0) {
                    ans = [1, -1] // special 0
                    seg = [i, i]
                }
            }
        } else {
            if (x > 0) {
                // pos = x
                // neg = 1
                pos = [1, x === 1 ? 0 : 1] // pos, power
                neg = [1, 0]
                ans = pos
                pp = i
            } else if (x < 0) {
                // pos = 1
                // neg = x
                pos = [1, 0]
                neg = [-1, x === -1 ? 0 : 1]
                ans = neg
                pn = i
            } else {
                // pos = 1
                // neg = 1
                pos = [1, 0]
                neg = [1, 0]
                ans = [1, -1]
            }
            // ans = Math.max(ans, x)
            seg = [i, i]
        }
        // console.log(pos, neg, ans)
    })
// console.log(ans, seg)
// return
    const [a, b] = seg
    if (cmp(ans, [1, -1]) <= 0) return [0, n].join(' ')
    return [a, n - 1 - b].join(' ')
}
function cmp(a, b) {
    const [sa, va] = a
    const [sb, vb] = b
    if (sa > 0 && sb > 0) {
        return va - vb
    } else if (sa < 0 && sb < 0) {
        return vb - va
    } else if (sa > 0) {
        return 1
    } else {
        return -1
    }
}

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
let n;
let a;
function solve() {
    const pre2 = af(n).fill(0);
    const preve = af(n).fill(0);
    for (let i = 0; i < n; i++) {
        if (i > 0) {
            pre2[i] = pre2[i - 1];
            preve[i] = preve[i - 1];
        }
        if (a[i] == 0) {
            pre2[i] = 0;
            preve[i] = 0;
        }
        if (a[i] < 0) {
            preve[i]++;
        }
        if (Math.abs(a[i]) == 2) {
            pre2[i]++;
        }
    }
    const lim = af(n).fill(n);
    const lastve = af(n).fill(INIT);
    for (let i = n - 1; i >= 0; i--) {
        if (i < n - 1) {
            lim[i] = lim[i + 1];
            lastve[i] = lastve[i + 1];
        }
        if (a[i] == 0) {
            lim[i] = i;
            lastve[i] = INIT;
        }
        if (a[i] < 0 && lastve[i] == INIT) {
            lastve[i] = i;
        }
    }
    // printf("lim: %j\n", lim);
    // printf("lastve: %j\n", lastve);
    let best2 = 0;
    let l = 0;
    let r = 0; // [l,r)
    for (let i = 0; i < n; i++) {
        if (a[i] == 0) {
            continue;
        }
        let j = lim[i];
        let cnt2 = pre2[j - 1] - (i > 0 ? pre2[i - 1] : 0);
        let cntve = preve[j - 1] - (i > 0 ? preve[i - 1] : 0);
        if ((cntve % 2) == 1) {
            j = lastve[i];
            if (j <= i) {
                continue;
            }
            cnt2 = pre2[j - 1] - (i > 0 ? pre2[i - 1] : 0);
            cntve = preve[j - 1] - (i > 0 ? preve[i - 1] : 0);
        }
        check((cntve % 2) == 0);
        if (cnt2 > best2) {
            best2 = cnt2;
            l = i;
            r = j;
        }
    }
    // printf("best2: %d\n", best2);
    printf("%d %d\n", l, n - r);
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        solve();
    }
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

function getMax(a, start, end) {
  var _a, _b
  const n = end - start + 1
  let first = -1,
    last = -1,
    sum = new Array(n).fill(0),
    count = 0
  for (let i = 0; i <= n; i++) {
    sum[i] = ((_a = sum[i - 1]) !== null && _a !== void 0 ? _a : 0) + (Math.abs(a[i]) === 2 ? 1 : 0)
    if (first === -1 && a[i + start] < 0) first = i
    if (a[i + start] < 0) {
      count++
      last = i
    }
  }
  if (count % 2 === 0) {
    return [sum[n - 1] * 2, start, end]
  } else {
    let left = ((_b = sum[last - 1]) !== null && _b !== void 0 ? _b : 0) * 2 + (last > 0 ? 1 : 0),
      right = (sum[n - 1] - sum[first]) * 2 + (first < n - 1 ? 1 : 0)
    if (left >= right) {
      return [left, start, start + last - 1]
    } else {
      return [right, start + first + 1, end]
    }
  }
}
function solve(n, a) {
  let left = -1,
    right = -1,
    max = 1
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) {
      let j = i
      while (j < n - 1 && a[j + 1] !== 0) j++
      const [num, l, r] = getMax(a, i, j)
      if (max < num) {
        max = num
        left = l
        right = r
      }
    }
  }
  if (left === -1) return [0, n]
  else return [left, n - right - 1]
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    const a = inputs[__++].trim().split(' ').map(Number)
    const [l, r] = solve(n, a)
    res.push(`${l} ${r}`)
  }
  console.log(res.join('\n'))
})()

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

const _ = Number(inputs[0])

main(_, inputs)

function main(_, lines) {
  let res = []
  for (let i = 0; i < _; i++) {
    const n = Number(lines[i * 2 + 1])
    const data = lines[i * 2 + 2].split(' ').map(Number)
    const check = (l, r) => {
      if (l === r) return
      let product = 1,
        count = 0

      for (let i = l; i < r; i++) {
        product *= data[i]
        if (data[i] < 0) count++
      }
      if (count % 2 === 0) {
        if (ans < product) {
          ans = product
          x = l
          y = n - r
        }
        return
      }

      let left = -1
      product = 1
      for (let i = l; i < r; i++) {
        if (left !== -1) {
          product *= data[i]
        }
        if (data[i] < 0 && left === -1) {
          left = i
        }
      }
      if (ans < product) {
        ans = product
        x = left + 1
        y = n - r
      }
      let right = -1
      product = 1
      for (let i = r - 1; i >= l; i--) {
        if (right !== -1) {
          product *= data[i]
        }
        if (data[i] < 0 && right === -1) {
          right = i
        }
      }
      if (ans < product) {
        ans = product
        x = l
        y = n - right
      }
    }

    let x = n,
      y = 0,
      ans = 1
    for (let i = 0, j = 0; j <= n; j++) {
      if (j === n || data[j] === 0) {
        check(i, j)
        i = j + 1
      }
    }
    res.push([x, y])
  }

  console.log(res.map(arr => arr.join(' ')).join('\n'))
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

const _ = Number(inputs[0])

main(_, inputs)

function main(_, lines) {
  let res = []
  for (let i = 0; i < _; i++) {
    const n = Number(lines[i * 2 + 1])
    const data = lines[i * 2 + 2].split(' ').map(Number)
    const check = (l, r) => {
      if (l === r) return
      const products = []
      for (let i = l; i < r; i++) {
        products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])
      }

      let pre = -1
      for (let i = 0; i < products.length; i++) {
        let max = products[i]
        if (max > 0 || pre === -1) {
          if (ans < max) {
            ans = max
            x = l
            y = n - 1 - (l + i)
          }
        } else {
          max = products[i] / products[pre]
          if (ans < max) {
            ans = max
            x = l + pre + 1
            y = n - 1 - (l + pre + i)
          }
        }

        if (max < 0 && pre === -1) {
          pre = i
        }
      }
    }

    let x = 0,
      y = 0,
      ans = -Infinity
    for (let i = 0, j = 0; j <= n; j++) {
      if (j === n || data[j] === 0) {
        check(i, j)
        i = j + 1
      }
    }
    res.push([x, y])
  }

  console.log(res.map(arr => arr.join(' ')).join('\n'))
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

const _ = Number(inputs[0])

main(_, inputs)

function main(_, lines) {
  let res = []
  for (let i = 0; i < _; i++) {
    const n = Number(lines[i * 2 + 1])
    const data = lines[i * 2 + 2].split(' ').map(Number)
    const check = (l, r) => {
      if (l === r) return
      const products = []
      for (let i = l; i < r; i++) {
        products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])
      }

      let pre = -1
      for (let i = 0; i < products.length; i++) {
        let max = products[i]
        if (max > 0 || pre === -1) {
          if (ans < max) {
            ans = max
            x = l
            y = n - 1 - (l + i)
          }
        } else {
          max = products[i] / products[pre]
          if (ans < max) {
            ans = max
            x = l + pre + 1
            y = n - 1 - (l + pre + i)
          }
        }

        if (max < 0 && pre === -1) {
          pre = i
        }
      }
    }
    let x = 0,
      y = n,
      ans = 1
    for (let i = 0, j = 0; j <= n; j++) {
      if (j === n || data[j] === 0) {
        check(i, j)
        i = j + 1
      }
    }
    res.push([x, y])
  }

  console.log(res.map(arr => arr.join(' ')).join('\n'))
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

const _ = Number(inputs[0])

main(_, inputs)

function main(_, lines) {
  let res = []
  for (let i = 0; i < _; i++) {
    const n = Number(lines[i * 2 + 1])
    const data = lines[i * 2 + 2].split(' ').map(Number)
    const check = (l, r) => {
      if (l === r) return
      const products = []
      for (let i = l; i < r; i++) {
        products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])
      }

      let pre = -1
      for (let i = 0; i < products.length; i++) {
        let max = products[i]
        if (max > 0 || pre === -1) {
          if (ans < max) {
            ans = max
            x = l
            y = n - 1 - (l + i)
          }
        } else {
          max = products[i] / products[pre]
          if (ans < max) {
            ans = max
            x = l + pre
            y = n - 1 - (l + pre + i)
          }
        }

        if (max < 0 && pre === -1) {
          pre = i
        }
      }
    }
    let x = 0,
      y = n,
      ans = 1
    for (let i = 0, j = 0; j <= n; j++) {
      if (j === n || data[j] === 0) {
        check(i, j)
        i = j + 1
      }
    }
    res.push([x, y])
  }

  console.log(res.map(arr => arr.join(' ')).join('\n'))
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

const _ = Number(inputs[0])

main(_, inputs)

function main(_, lines) {
  let res = []
  for (let i = 0; i < _; i++) {
    const n = Number(lines[i * 2 + 1])
    const data = lines[i * 2 + 2].split(' ').map(Number)
    const check = (l, r) => {
      if (l === r) return
      const products = []
      for (let i = l; i < r; i++) {
        products.push((products[products.length - 1] === undefined ? 1 : products[products.length - 1]) * data[i])
      }

      let pre = l
      for (let i = 0; i < products.length; i++) {
        let max = products[i]
        if (max > 0 || pre === -1) {
          if (ans < max) {
            ans = max
            x = l
            y = n - 1 - (l + i)
          }
        } else {
          max = products[i] / products[pre]
          if (ans < max) {
            ans = max
            x = pre + 1
            y = n - 1 - (pre + i)
          }
        }

        if (max < 0 && pre === -1) {
          pre = i
        }
      }
    }
    let x = 0,
      y = 0,
      ans = -Infinity
    for (let i = 0, j = 0; j <= n; j++) {
      if (j === n || data[j] === 0) {
        check(i, j)
        i = j + 1
      }
    }
    res.push([x, y])
  }

  console.log(res.map(arr => arr.join(' ')).join('\n'))
}

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

		let ans, mx = 0;
		for (let round = 0; round < 2; round++) {
			let twos = 0, positive = 1, cnt = 0;
			for (let i = 0; i < n; i++) {
				if (a[i] == 0) cnt = 0, twos = 0; else cnt++;
				if (a[i] < 0) positive ^= 1;
				if (Math.abs(a[i]) == 2) twos++;
				if (positive & twos > mx) {
					mx = twos;
					ans = [(i + 1) - cnt, n - (i + 1)];
					if (round) ans.reverse();
				}
				//console.log({round, i, twos, positive, mx, cnt, ans});
			}
			a.reverse();
		}

		if (mx == 0) {
			console.log(n, 0);
		} else {
			console.log(ans.join(' '));
		}

	}
}

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

		let ans, mx = 0;
		for (let round = 0; round < 2; round++) {
			let twos = 0, positive = 1, cnt = 0;
			for (let i = 0; i < n; i++) {
				if (a[i] == 0) cnt = 0, twos = 0; else cnt++;
				if (a[i] < 0) positive ^= 1;
				if (Math.abs(a[i]) == 2) {
					twos++;
					if (positive & twos > mx) {
						mx = twos;
						ans = [(i + 1) - cnt, n - (i + 1)];
						if (round) ans.reverse();
					}
					//console.log({round, i, twos, positive, mx, cnt, ans});
				}
			}
			a.reverse();
		}

		if (mx == 0) {
			console.log(n, 0);
		} else {
			console.log(ans.join(' '));
		}

	}
}

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

		let mx = 1, l, r;
		for (let round = 0; round < 2; round++) {
			let prod = 0, left = 0;
			for (let i = 0; i < n; i++) {
				if (prod == 0) prod = 1;
				prod *= a[i];
				if (prod > mx) {
					mx = prod;
					if (round == 0) {
						l = left;
						r = i;
					} else {
						l = n - i - 1;
						r = n - left - 1;
					}
					//console.log({round, i, mx, l, r});
				}
				if (a[i] == 0) {
					left = i + 1;
				}
			}
			a.reverse();
		}
		//console.log({mx, l, r});

		if (mx == 1) {
			console.log(n, 0);
		} else {
			console.log(l, n - (r + 1));
		}
	}
}

const readline = require('readline')

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

function solve(n, nums) {
    let ans = [-1, 3 * n]
    let pos
    let neg
    let pp = -1, pn = -1
    let seg
    nums.forEach((x, i) => {
        if (i) {
            const [sp, vp] = pos
            const [sn, vn] = neg
            if (x > 0) {
                // pos *= x
                // neg *= x
                const pow = x === 1 ? 0 : 1
                pos = [1, vp + pow]
                neg = [sn, vn + pow]
                // ans = Math.max(ans, pos, neg)
                if (pp < 0) pp = i
                if (pn < 0) pn = i
                // if (pos > ans) {
                if (cmp(pos, ans) > 0) {
                    ans = pos
                    seg = [pp, i]
                }
            } else if (x < 0) {
                const pow = x === -1 ? 0 : 1
                if (neg[0] < 0) {
                    if (pp < 0) pp = i
                    if (pn < 0) pn = i
                    // ;[pos, neg] = [neg * x, pos * x]
                    pos = [-sn, vn + pow]
                    neg = [-sp, vp + pow]
                    ;[pp, pn] = [pn, pp]
                    // ans = Math.max(ans, pos, neg)
                    if (cmp(pos, ans) > 0) {
                        ans = pos
                        seg = [pp, i]
                    }
                    if (cmp(neg, ans) > 0) {
                        ans = neg
                        seg = [pn, i]
                    }
                } else {
                    if (pp < 0) pp = i
                    // ;[pos, neg] = [1, pos * x]
                    ;[pp, pn] = [-1, pp]
                    pos = [1, 0]
                    neg = [-1, vp + pow]
                    // ans = Math.max(ans, neg)
                    //
                    if (cmp(neg, ans) > 0) {
                        ans = neg
                        seg = [pn, i]
                    }
                }
            } else {
                // pos = 1
                // neg = 1
                pos = [1, 0]
                neg = [1, 0]
                pp = -1
                pn = -1
                // ans = Math.max(ans, 0)
                //
                if (cmp([1, -1], ans)) {
                    ans = [1, -1] // special 0
                    seg = [i, i]
                }
            }
        } else {
            if (x > 0) {
                // pos = x
                // neg = 1
                pos = [1, x === 1 ? 0 : 1] // pos, power
                neg = [1, 0]
                ans = pos
                pp = i
            } else if (x < 0) {
                // pos = 1
                // neg = x
                pos = [1, 0]
                neg = [-1, x === -1 ? 0 : 1]
                ans = neg
                pn = i
            } else {
                // pos = 1
                // neg = 1
                pos = [1, 0]
                neg = [1, 0]
                ans = [1, -1]
            }
            // ans = Math.max(ans, x)
            seg = [i, i]
        }
        // console.log(pos, neg, ans)
    })
// console.log(ans, seg)
// return
    const [a, b] = seg
    if (cmp(ans, [1, -1]) <= 0) return [0, n].join(' ')
    return [a, n - 1 - b].join(' ')
}
function cmp(a, b) {
    const [sa, va] = a
    const [sb, vb] = b
    if (sa > 0 && sb > 0) {
        return va - vb
    } else if (sa < 0 && sb < 0) {
        return vb - va
    } else if (sa > 0) {
        return 1
    } else {
        return -1
    }
}

const readline = require('readline')

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

function solve(n, nums) {
    let ans = -Infinity
    let pos
    let neg
    let pp = -1, pn = -1
    let seg
    nums.forEach((x, i) => {
        if (i) {
            if (x > 0) {
                pos *= x
                neg *= x
                // ans = Math.max(ans, pos, neg)
                if (pp < 0) pp = i
                if (pn < 0) pn = i
                if (pos > ans) {
                    ans = pos
                    seg = [pp, i]
                }
            } else if (x < 0) {
                if (neg < 0) {
                    if (pp < 0) pp = i
                    if (pn < 0) pn = i
                    ;[pos, neg] = [neg * x, pos * x]
                    ;[pp, pn] = [pn, pp]
                    ans = Math.max(ans, pos, neg)
                    //
                    if (pos === ans) {
                        seg = [pp, i]
                    } else if (neg === ans) {
                        seg = [pn, i]
                    }
                } else {
                    if (pp < 0) pp = i
                    ;[pos, neg] = [1, pos * x]
                    ;[pp, pn] = [-1, pp]
                    ans = Math.max(ans, neg)
                    //
                    if (neg === ans) {
                        seg = [pn, i]
                    }
                }
            } else {
                pos = 1
                neg = 1
                pp = -1
                pn = -1
                ans = Math.max(ans, 0)
                //
                if (ans === 0) {
                    seg = [i, i]
                }
            }
        } else {
            if (x > 0) {
                pos = x
                neg = 1
                pp = i
            } else if (x < 0) {
                pos = 1
                neg = x
                pn = i
            } else {
                pos = 1
                neg = 1
            }
            ans = Math.max(ans, x)
            seg = [i, i]
        }
        // console.log(pos, neg, ans)
    })
// console.log(ans, seg)
    const [a, b] = seg
    if (ans <= 0) return [0, n].join(' ')
    return [a, n - 1 - b].join(' ')
}


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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const d = rl();

		const dpl = Array(n+1).fill(0);
		for (let i = 1; i <= n; i++) {
			if (d[i-1] == 'L') {
				dpl[i]++;
				if (i-2 >= 0 && d[i-2] == 'R') {
					dpl[i]++;
					dpl[i] += dpl[i-2];
				}
			}
		}

		const dpr = Array(n+1).fill(0);
		for (let i = n-1; i >= 0; i--) {
			if (d[i] == 'R') {
				dpr[i]++;
				if (i+1 < n && d[i+1] == 'L') {
					dpr[i]++;
					dpr[i] += dpr[i+2];
				}
			}
		}

		const ans = [];
		for (let i = 0 ; i <= n; i++) {
			ans[i] = 1 + dpl[i] + dpr[i];
		}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        var a = readline().split('').map((x, iii) => {
            return x
        })
        var dpl  = new Array(n+1).fill(0)
        var dpr  = new Array(n+1).fill(0)

        for (let i = 0; i <= n; i++) {
            if(i===0 || a[i-1] === 'R') dpl[i] = i
            else if(i===1 || a[i-2] === 'L') dpl[i] = i-1
            else dpl[i] = dpl[i-2]

        }

        for (let i = n; i >=0; i--) {
            if(i===n || a[i] === 'L') dpr[i] = i
            else if(i===n-1 || a[i+1] === 'R') dpr[i] = i+1
            else dpr[i] = dpr[i+2]
        }

        var res = new Array(n)
        for (let i = 0; i <= n; i++) {
            res[i] = i- dpl[i]+1 + dpr[i] - i
        }

            // console.log(dpl)
        // console.log(dpr)
        console.log(res.join(' '))

        // x = x.sort((a, b) => {
        //     if (a.x - b.x === 0)
        //         return a.y - b.y
        //     return a.x - b.x
        // })
        // var res = []
    })
}


print(function(n) {
	var i, j, a = [];

	for (i = 0; i < n; i++)
		a.push(readline());

	for (i = 0; i < 20; i++)
		for (j = 0; j < n; j++)
			if (a[j][i] !== a[0][i]) return i;

	return 20;

}(+readline()));

;(function () {

	print(function (n) {

		var s = readline(), b, l;
		while (n--) {
			b = ''; l = readline();

			for (var i = 0, _i = Math.min(l.length, s.length); i < _i; i++) {
				if (s[i] === l[i]) b += l[i];
				else break;
			}

			s = b;
		}

		return s.length;

	}(+readline() - 1));

}.call(this));

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

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

  phones.push(d);

  c++;
});

rl.on('close', () => {
  let ans = 0;

  for (let i = 0; i < phones[0].length; i++) {
    let code = phones[0][i];
    let isDiffer = false;
    for(let j = 0; j < phones.length; j++) {
      if (code !== phones[j][i]) {
        isDiffer = true;
        break;
      }
    }

    if (isDiffer) {
      break;
    }
    else {
      ans++;
    }
  }

  console.log(ans);
});


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function greeting() {
    let t = parseInt(readLine());
while(t > 0)
{
    let n = parseInt(readLine());
    let s = readLine();

    if(n < 2)
    console.log("YES");
    else if(n == 2 && s[0] != s[1])
    console.log("YES");
    else
    {
        console.log("NO");
    }

    t--;
}
}

function main() {
    greeting();
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var l = 1; l <= n * 2; l++){
        if(l % 2 === 0){
            var k = lines[l].split('').map(Number);
            var one = 0;
            var zero = 0;
            for(var j = 0; j < e; j++){
                if(k[j] == 1){
                    one++;
                }else{
                    zero++;
                }
            }
            if(one <= 1 && zero <= 1){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }else{
            e = lines[l];
        }
    }
});

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let n = nl.num();
		let s = nl.line().split('');
		ans.push((n == 2 && s[0] != s[1]) || n == 1);
	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

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

'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++];
}
/* let arr = readLine().split(" ").map((x) => {return parseInt(x)});
let test = readLine();
while(test--)
{

}
*/
function main() {
    let test = readLine();
    while(test--)
        {
            let noNeed = readLine();
            let string = readLine();
            if (string == "0" || string == "01" || string == "10" || string == "10" || string == "1"){
            console.log("YES");
        }
        else {
            console.log("NO");
        }
        }
    return 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++];
}

function main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
     let trash = readline();
     let num = readline();
     let ones=0, zeroes =0;
     num.split("").forEach(x => (x==1 ? ones++ : zeroes++));
     if(zeroes+ones == 1) console.log("YES")
     else if(zeroes+ones == 2 && zeroes==ones) console.log("YES")
     else console.log("NO")
 }
}

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

let inputString = '';

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

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

    main(inputString);
});

function log(message){
    if(process.env.NODE_ENV === "debug"){
        console.log(message);
    }
}

const YES = "YES"
const NO = "NO"

function main(fileContents) {//input lines as an array
    // console.log(fileContents);
    fileContents.splice(0,1);
    for(let i = 1; i < fileContents.length; i+=2){
        const bs = fileContents[i];
        // console.log("BS",bs)
        if(bs.length == 1){
            console.log(YES) // 0 1
        }else if(bs.length == 2){
            if(bs.charAt(0) === bs.charAt(1)){
                console.log(NO) // 11 00
            }else{
                console.log(YES) // 01 10
            }
        }else{
            console.log(NO)
        }
    }
}

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 testCases = readline();

  for (let i = 0; i < testCases; i++) {
    let size = readline();
    let s = readline();

    if (
      size === "1" ||
      (size === "2" && s === "10") ||
      (size === "2" && s === "01")
    ) {
      console.log("YES");
    } else {
      console.log("NO");
    }
  }
}

//readline().split(" ").map(function(x) { return parseInt(x); });
var numbers = parseInt(readline());
var i =0;
while(i < numbers) {
	var n =parseInt(readline());
	var a =(readline());

	print(n > 2 || a === '00' || a === '11' ? 'NO' : 'YES'); // ends with newline
	i++;
}

//print(numbers[0] + numbers[1]); // ends with newline

var t = parseInt(readline());
while(t > 0)
{
    var n = parseInt(readline());
    var s = readline();

    if(n < 2)
    print("YES");
    else if(n == 2 && s[0] != s[1])
    print("YES");
    else
    {
        print("NO");
    }
    t--;
}

var x = parseInt(readline());
for(var i=0; i<x; i++) {
    var y = parseInt(readline());
    var z = readline();
    if(y >= 3 || (y == 2 && z[0] == z[1])) {
        print("NO");
    }
    else {
        print("YES");
    }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let _ = readSingleInt();
    while(_--){
        let n = readSingleInt();
        let st = readLine();
        if(n>2 || st=='11' || st=='00'){
            console.log("NO");
        }else{
            console.log("YES");
        }
    }

}

let data = "";
let some = 0;

process.stdin.on("data", (c) => (data += c));
process.stdin.on("end", () => {
  let [_, ...input] = data
    .trim()
    .split(/\n/)
    .map((el) => el.trim());

  input = input.filter((el, idx) => idx % 2 !== 0);
  input.forEach((el) => {
    if (el.length > 2) {
      console.log("NO");
    } else {
      if (el[0] === el[1]) {
        console.log("NO");
      } else console.log("YES");
    }
  });
});

let data = "";

process.stdin.on("data", (c) => (data += c));
process.stdin.on("end", () => {
  let [_, ...input] = data
    .trim()
    .split(/\n/)
    .map((el) => el.trim());

  input = input.filter((el, idx) => idx % 2 !== 0);
  input.forEach((el) => {
    if (el.length > 2) {
      console.log("NO");
    } else {
      if (el[0] === el[1]) {
        console.log("NO");
      } else console.log("YES");
    }
  });
});

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
function palindrome(arr) {
  if (arr.length <= 1) {
    return false;
  }
  for (let i = 0, j = arr.length - 1; i < j; i++, j--) {
    if (arr[i] !== arr[j]) {
      return false;
    }
  }
  return true;
}
function permutationGenerator(arr, n, permutation, permutations) {
  if (permutation.length === arr.length) {
    permutations.push(permutation.slice().join(""));
  } else {
    for (let i = n; i < arr.length; i++) {
      let temp = arr[n];
      arr[n] = arr[i];
      arr[i] = temp;
      permutation.push(arr[n]);
      permutationGenerator(arr, n + 1, permutation, permutations);
      temp = arr[n];
      arr[n] = arr[i];
      arr[i] = temp;
      permutation.pop();
    }
  }
}
function subsetGenerator(arr, n, subsets, subset) {
  if (n === arr.length) {
    subsets.push(subset.slice().join(""));
  } else {
    subsetGenerator(arr, n + 1, subsets, subset);
    subset.push(arr[n]);
    subsetGenerator(arr, n + 1, subsets, subset);
    subset.pop();
  }
}
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0].trim());
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++].trim());
    let s = lines[i++].trim();
    if (n == 1) {
      console.log("YES");
    } else if (n == 2) {
      if (s[0] !== s[1]) {
        console.log("YES");
      } else {
        console.log("NO");
      }
    } else {
      console.log("NO");
    }
  }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let s = readline().split('').map(Number);

        if (s.length > 2) {
            output('NO');
        } else if (s[0] === s[1]) {
            output('NO');
        } else {
            output('YES');
        }
    }
}

//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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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();
	while(hasNext()){
		var N = nextInt();
		var S = nextCharArray();
		if(N >= 3){
			myout("NO");
			continue;
		}else if(N == 1){
			myout("YES");
		}else{
			var set = new Set(S);
			if(set.size == 1){
				myout("NO");
			}else{
				myout("YES");
			}
		}
	}
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let _ = readSingleInt();
    while(_--){
        let n = readSingleInt();
        let st = readLine();
        if(n>2){
            console.log("NO");
        }else{
            console.log("YES");
        }
    }

}

//readline().split(" ").map(function(x) { return parseInt(x); });
var numbers = parseInt(readline());
var i =0;
while(i < numbers) {
	var n =parseInt(readline());
	var a =parseInt(readline());

	print(n > 2 || a === '00' || a === '11' ? 'NO' : 'YES'); // ends with newline
	i++;
}

//print(numbers[0] + numbers[1]); // ends with newline

//readline().split(" ").map(function(x) { return parseInt(x); });
var numbers = parseInt(readline());
var i =0;
while(i < numbers) {
	var n =parseInt(readline());
	var a =parseInt(readline());

	print(n > 2 ? 'NO' : 'YES'); // ends with newline
	i++;
}

//print(numbers[0] + numbers[1]); // ends with newline

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

for (var i in numbers) {
	var n =parseInt(readline());
	var a =parseInt(readline());

	print(n > 2 ? 'NO' : 'YES'); // ends with newline
}

//print(numbers[0] + numbers[1]); // ends with newline


const readline = require('readline');

let count, array, previous = 0, counters = [];

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

rl.on('line', (line) => {
    if (!count) {
        count = parseInt(line.trim());

        if (count < 2 || count > 100000) {
            rl.close();
        }
    } else if (!array) {
        array = line.trim().split(" ").map (symbol => parseInt(symbol));

        rl.close();
    }
}).on('close', () => {
    array.forEach(element => {
        if (previous == element) {
            counters[counters.length - 1] += 1;
        } else {
            counters.push(1)
        }

        previous = element;
    });

    var result = 0;

    for (let i = 0; i < counters.length; i++) {
        if (i + 1 == counters.length) break;

        let value = Math.min(counters[i], counters[i + 1]) * 2;

        result = Math.max(value, result);
    }

    console.log(result);
});

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  const lines = input.split(EOL)
l = []
count = 0
lines[1] = lines[1].replace(/\ /g, '')
lines[1] = Array.from(lines[1])
lastchar = lines[1][0]
for (var i in lines[1]){
    if (lines[1][i] != lastchar){
    l.push(count)
    count = 1
    lastchar = lines[1][i]
    }
    else{
    count += 1
    }
}
l.push(count)
mx = 0
for (var i = 0; i < l.length -1; i++){
    mx = Math.max(mx, Math.min(l[i], l[i+1]))
}
console.log(mx * 2)
})

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  const lines = input.split(EOL)
  let line = lines[1]
  line = line.replace(/\ /g, '')
  let cache = ['1', 0, 0]
  let max = 0
  for (let i = 0; i < line.length; i++) {
    if (line[i] == cache[0]) {
      cache[2]++
    } else {
      cache[0] = line[i]
      cache[1] = cache[2]
      cache[2] = 1
    }
    if (Math.min(cache[1], cache[2]) > max) {
      max = Math.min(cache[1], cache[2])
    }
  }
  console.log(max * 2)
})

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

const solution = () => {
	let line = data.split('\n');
	let n = parseInt(line[0],10);
	let a = line[1].split(' ').map(v => parseInt(v,10));
	let t = a[0];
	let c = 0;
	let x = [];
	for(let i of a){
		if (t == i){
			c++;
		} else {
			x.push(c);
			c = 1;
			t = i;
		}
	}
	x.push(c);

	let m = 0;
	t = 0;
	for(let i of x){
		if (Math.min(t,i) > m){
			m = Math.min(t,i);
		}
		t = i;
	}
	console.log(2 * m);
};

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

// const print = require('lol-io').print;
// const readline = require('lol-io').readline;

const t = readline();
const arr = readline().split(' ');

const obj = {
	0: 0,
	1: 0,
};

const a = arr.map(i => {
	return i == 1 ? 1 : 0;
});

var maxSegment = 0;
var flag = 0;

if (a[0] === 0) {
	flag = 0;
} else flag = 1;

for (var i = 0; i < a.length; i++) {
	obj[a[i]]++;

	// if (obj[0] <= obj[1] ) {
	if (flag !== a[i]) {
		obj[a[i]] = 1;
		flag = +(!flag);
	}

	maxSegment =
		Math.min(obj[0], obj[1]) > maxSegment
			? Math.min(obj[0], obj[1])
			: maxSegment;

	// if (obj[0] > maxSegment) maxSegment = obj[0];
	// obj[!a[i]] = 0;
	// } else if()
}
// console.log(maxSegment * 2);
maxSegment = maxSegment * 2;
print(maxSegment);

var numOfLines = readline();
var nums = readline().split(' ').map(function(num) {
  return parseInt(num);
})

function min(a, b) {
  if (a < b)
    return a;
  if (b <= a)
    return b;
}

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

function main() {
  var currentSegment = 1;
  var prevSegment = 0;
  var maxSegments = 0;
  var currentNum = nums[0];

  for (var i = 1; i < nums.length; i++) {
    if (nums[i] === currentNum)
      currentSegment++;
    else {
      maxSegments = max(maxSegments, 2 * min(prevSegment, currentSegment));
      prevSegment =  currentSegment;
      currentSegment = 1;
      currentNum = nums[i];
    }
  }

  maxSegments = max(maxSegments, 2 * min(prevSegment, currentSegment));

  write(maxSegments)
}

main()

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

let inputString = '';
let currentLine = 0;

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

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

    console.log(findMaxSushiSeq(inputString[1].split(' ')));
});

const findMaxSushiSeq = (data) => {
    let high = 0;
    let low = 0;
    let i = 0;
    let max = 0;
    while (i < data.length) {
        if (data[i] !== data[high]) {
            low = high;
            high = i;
        }

        if (high > low) {
            max = Math.max(max, (Math.min(i - high + 1, high - low) * 2));
        }

        i++;
    }
    return max;
};

Array.prototype.eachTwo = function(callback) {
    for (let i = 0; i < this.length; i++) {
        if (i + 1 == this.length) break;

        callback(this[i], this[i + 1]);
    }
}

const readline = require('readline');

let iteration = 0, count, array, previous = 0, counters = [];

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

rl.on('line', (line) => {
    if (iteration == 0) {
        count = parseInt(line.trim());
        iteration++;

        if (count < 2 || count > 100000) {
            rl.close();
        }
    } else {
        array = line.trim().split(" ").map (symbol => parseInt(symbol));
        iteration++;

        rl.close();
    }

    if (iteration != 2) { return; }

    array.forEach(element => {
        if (element == 1) {
            if (previous == 1) {
                counters[counters.length - 1] += 1;
            } else {
                counters.push(1)
            }

            previous = 1
        }

        if (element == 2) {
            if (previous == 2) {
                counters[counters.length - 1] += 1;
            } else {
                counters.push(1)
            }

            previous = 2
        }
    });

    var result = 0

    counters.eachTwo(function(first, second) {
        let value = Math.min(first, second) * 2;

        if (value > result) {
            result = value
        }
    });

    console.log(result);
});

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

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

  const arr = d.split(' ').map(Number);
  let max = 0;
  let count = 0;
  let ones = 0;
  let twos = 0;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] !== arr[i - 1]) {
      count++;

      if (count === 2) {
        count = 1;

        if (arr[i - 1] === 1) {
          twos = 0;
        }

        if (arr[i - 1] === 2) {
          ones = 0;
        }
      }
    }

    if (arr[i] === 1) {
      ones++;
    }

    if (arr[i] === 2) {
      twos++;
    }

    max = Math.max(max, Math.min(ones, twos) * 2);
  }

  console.log(max);
  c++;
});

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

let inputString = '';
let currentLine = 0;

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

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

    console.log(findMaxSushiSeq(inputString[1].split(' ')));
});

const findMaxSushiSeq = (data) => {
    let high = 0;
    let low = 0;
    let i = 0;
    let max = 0;
    while (i < data.length) {
        if (data[i] !== data[high]) {
            low = high;
            high = i;
        }

        if (high > low) {
            max = Math.max(max, (Math.min(i - high + 1, high - low) * 2));
        }

        i++;
    }
    return max;
};

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

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

  const arr = d.split(' ').map(Number);
  let max = 0;
  let type1 = 0;
  let type2 = 0;
  let switchCount = 0;
  let prev = arr[0];

  for (let i = 0; i < arr.length; i++) {
    if (prev !== arr[i]) {
      switchCount++;

      if (switchCount === 2) {
        switchCount = 0
        if (prev === 1) {
          type2 = 0;
        }
        else {
          type1 = 0;
        }
      }
    }

    if (arr[i] === 1) {
      type1++;
    }

    if (arr[i] === 2) {
      type2++;
    }

    if (type1 === type2) {
      max = Math.max(max, type1 + type2);
    }

    prev = arr[i];
  }

  console.log(max);

  c++;
});

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

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

  const arr = d.split(' ').map(Number);
  let max = 0;
  let count = 0;
  let ones = 0;
  let twos = 0;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] !== arr[i - 1]) {
      count++;

      if (count === 2) {
        count = 0;

        if (arr[i - 1] === 1) {
          twos = 0;
        }

        if (arr[i - 1] === 2) {
          ones = 0;
        }
      }
    }

    if (arr[i] === 1) {
      ones++;
    }

    if (arr[i] === 2) {
      twos++;
    }

    max = Math.max(max, Math.min(ones, twos) * 2);
  }

  console.log(max);
  c++;
});

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

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

    n = +d;
    return;
  }

  if (n === 100000) {
    console.log(d);
    return;
  }

  const arr = d.split(' ').map(Number);
  let max = 0;
  let count = 0;
  let ones = 0;
  let twos = 0;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] !== arr[i - 1]) {
      count++;

      if (count === 2) {
        count = 0;

        if (arr[i - 1] === 1) {
          twos = 0;
        }

        if (arr[i - 1] === 2) {
          ones = 0;
        }
      }
    }

    if (arr[i] === 1) {
      ones++;
    }

    if (arr[i] === 2) {
      twos++;
    }

    max = Math.max(max, Math.min(ones, twos) * 2);
  }

  console.log(max);
  c++;
});

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

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

  const arr = d.split(' ').map(Number);
  let max = 0;
  let type1 = 0;
  let type2 = 0;
  let switchCount = 0;
  let prev = arr[0];

  for (let i = 0; i < arr.length; i++) {
    if (prev !== arr[i]) {
      switchCount++;

      if (switchCount === 2) {
        switchCount = 0
        if (prev === 1) {
          type2 = 0;
        }
        else {
          type1 = 0;
        }
      }
    }

    if (arr[i] === 1) {
      type1++;
    }

    if (arr[i] === 2) {
      type2++;
    }

    max = Math.max(max, Math.min(type1, type2) + Math.min(type1, type2));

    prev = arr[i];
  }

  console.log(max);

  c++;
});

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

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

  const arr = d.split(' ').map(Number);
  let max = 0;
  let count = 0;
  let ones = 0;
  let twos = 0;

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] !== arr[i - 1]) {
      count++;

      if (count === 2) {
        count = 0;

        if (arr[i - 1] === 1) {
          twos = 0;
        }

        if (arr[i - 1] === 2) {
          ones = 0;
        }
      }
    }

    if (arr[i] === 1) {
      ones++;
    }

    if (arr[i] === 2) {
      twos++;
    }

    max = Math.max(max, Math.min(ones, twos) * 2);
  }

  console.log(max);
  c++;
});

var numOfLines = readline();
var nums = readline().split(' ').map(function(num) {
  return parseInt(num);
})

function min(a, b) {
  if (a < b)
    return a;
  if (b <= a)
    return b;
}

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

function main() {
  var currentSegment = 0;
  var prevSegment = 0;
  var maxSegments = 0;
  var currentNum = nums[0];

  for (var i = 1; i < nums.length; i++) {
    if (nums[i] === currentNum)
      currentSegment++;
    else {
      maxSegments = max(maxSegments, min(prevSegment, currentSegment));
      prevSegment =  currentSegment;
      currentSegment = 1;
      currentNum = nums[i];
    }
  }

  maxSegments = max(maxSegments, 2*min(prevSegment, currentSegment));

  write(maxSegments)
}

main()

var numOfLines = readline();
var nums = readline().split(' ').map(function(num) {
  return parseInt(num);
})

function min(a, b) {
  if (a < b)
    return a;
  if (b <= a)
    return b;
}

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

function main() {
  var currentSegment = 1;
  var prevSegment = 0;
  var maxSegments = 0;
  var currentNum = nums[0];

  for (var i = 1; i < nums.length; i++) {
    if (nums[i] === currentNum)
      currentSegment++;
    else {
      maxSegments = max(maxSegments, min(prevSegment, currentSegment));
      prevSegment =  currentSegment;
      currentSegment = 1;
      currentNum = nums[i];
    }
  }

  maxSegments = max(maxSegments, 2*min(prevSegment, currentSegment));

  write(maxSegments)
}

main()

var numOfLines = readline();
var nums = readline().split(' ').map(function(num) {
  return parseInt(num);
})

function min(a, b) {
  if (a < b)
    return a;
  if (b <= a)
    return b;
}

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

function main() {
  var currentSegment = 1;
  var prevSegment = 0;
  var maxSegments = 0;
  var currentNum = nums[0];

  for (var i = 1; i < nums.length; i++) {
    if (nums[i] === currentNum)
      currentSegment++;
    else {
      maxSegments = max(maxSegments, 2 * min(prevSegment, currentSegment));
      prevSegment =  currentSegment;
      currentSegment = 1;
      currentNum = nums[i];
    }
  }

  maxSegments = max(maxSegments, min(prevSegment, currentSegment));

  write(maxSegments)
}

main()


//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 if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var output = 0;
		while(true){
			var isOK = true;
			for(var i = 0; i < N - 1; i++){
				if(list[i] > list[i + 1]){
					isOK = false;
					break;
				}
			}
			if(isOK){
				break;
			}
			if(output % 2 == 0){
				for(var i = 0; i < N - 2; i += 2){
					if(list[i] > list[i + 1]){
						var tmp = list[i];
						list[i] = list[i + 1];
						list[i + 1] = tmp;
					}
				}
			}else{
				for(var i = 1; i < N - 1; i += 2){
					if(list[i] > list[i + 1]){
						var tmp = list[i];
						list[i] = list[i + 1];
						list[i + 1] = tmp;
					}
				}
			}
			output++;
		}
		myout(output);
	}
}

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

function isSorted(p) {
  for (let i = 0; i < p.length - 1; i++) {
    if (p[i] > p[i + 1]) {
      return false
    }
  }
  return true
}

function sort(p, i) {
  if (i % 2 === 0) {
    for (let j = 1; j < p.length - 1; j = j + 2) {
      if (p[j] > p[j + 1]) {
        const aux = p[j]
        p[j] = p[j + 1]
        p[j + 1] = aux
      }
    }
  } else {
    for (let j = 0; j < p.length - 1; j = j + 2) {
      if (p[j] > p[j + 1]) {
        const aux = p[j]
        p[j] = p[j + 1]
        p[j + 1] = aux
      }
    }
  }
}

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

  while (t > 0) {
    lines.shift()
    let p = lines.shift().split(' ').map(x => parseInt(x))
    let op = 0
    while (!isSorted(p)) {
      op++
      sort(p, op)
    }
    console.log(op)
    t--
  }
}


let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  let candy = lines[1].split(' ');
  candy = candy.map(c => parseInt(c, 10));
  // console.log(maxChildren(candy));
  console.log(maxChildrenFast(candy));
});

function maxChildrenFast(candies) {
  const arr = [];
  arr.length = 2 * (10 ** 5);
  arr.fill(0);
  let max = 1;
  for (let i = 0; i < candies.length - 1; i++) {
    for (let j = i + 1; j < candies.length; j++) {
      max = Math.max(++arr[candies[i] + candies[j] - 1], max);
    }
  }
  return max;
}

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

var inputs = [];
const PI = parseInt;

function main() {
    const sw = inputs[1].split(" ").map(_ => PI(_));
    let possibleSolution = {};
    sw.forEach((val, idx) => {
        for(let q = idx + 1 ; q < sw.length; q++) {
            let k = sw[q] + val;
            possibleSolution[k] = (possibleSolution[k]) ? possibleSolution[k] : 0;
            possibleSolution[k.toString()]++;

        }
    });
    let res = 0;
    Object.keys(possibleSolution).forEach((key) => {
        res = Math.max(res, possibleSolution[key]);
    });

    console.log(res);
}

readline.on('line', (input) => { inputs.push(input); });
readline.on('close', main)


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

function solve(n) {
  const filter = new Array(n + 1).fill(0);
  filter[0] = filter[1] = 1;
  for (let i = 2; i <= n; ++i) {
    if (filter[i] !== 0) continue;
    filter[i] = 1;
    for (let j = i + i; j <= n; j += i) {
      if (filter[j] === 0) filter[j] = Math.floor(j / i);
    }
  }
  return filter.slice(2).sort((a, b) => a - b).join(' ');
}

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

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

wt = write;
rd = readline;

n = parseInt(rd());
arr = [];
for(i =  1; i <= n; i++){
	for(j = 2; j * i <= n; j++){
		arr[i * j] = i;
	}
}
arr.sort(function(a,b){ return a - b; });
for(i = 0; i < n - 1; i++){
	wt(arr[i] + " ");
}


'use strict';

function solve(n, m, a) {
  if (m === 1) {
    return Math.ceil(n / 2) - 1;
  }
  let res = 0;
  for (let i = 1; i < n - 1; i++) {
    if (a[i] > a[i - 1] + a[i + 1]) res++;
  }
  return res;
}

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

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

"use strict";
function toInt(x) {
	return parseInt(x);
}
function readInt() {
	return toInt(readline());
}
function readLInt() {
	return readline().split(' ').map(toInt);
}
function divCeil(a, b) {
	return Math.floor((a - 1) / b) + 1;
}
function solve() {
	let n, k;
	let x = readLInt();
	n = x[0];
	k = x[1];
	let a = readLInt();
	if (k == 1) {
		print(Math.floor((n - 1) / 2));
		return 0;
	}
	let res = 0;
	for (let ind = 1; ind + 1 < n; ind++) {
		if (a[ind] > a[ind + 1] + a[ind - 1]) res++;
	}
	print(res);
}

let t = readInt();
while (t--) solve();

var t = +readline();

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

    var t1 = +readline().split(' ')[1]
    var t2 = readline().split(' ').map((t) => +t);
    print(ShuffleArray(t1,t2))

}

function ShuffleArray(k,arr){
  var count = 0;
  if (k == 1){
    return Math.floor((arr.length + 1) / 2) -1
  }
  for(var i = 0; i<arr.length-1;i++){
    if (arr[i] > arr[i-1] + arr[i+1]) count++;
  }

  return count;

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

    for (let i = 0; i < N; i++) {
        const [n, k] = readline().split(' ').map(Number);
        let arr = readline().split(' ').map(Number);
        if (k === 1) {
            output(Math.floor((n - 1) / 2));
        } else {
            let tooHigh = 0;
            for (let j = 1; j < arr.length - 1; j++) {
                if (arr[j - 1] + arr[j + 1] < arr[j]) {
                    tooHigh++;
                }
            }
            output(tooHigh);
        }
    }
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(parseInt((n[0] - 1) / 2));
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i]

		}
		write(count);
	}
	print();
}

var tests = parseInt(readline());
for (var t=0; t < tests; t++) {
    var nk = readline().split(' ').map(x => parseInt(x));
    var n = nk[0];
    var k = nk[1];
    var arr = readline().split(' ').map(x => parseInt(x));
    var max = Math.floor((n - 1) / 2);
    if (k == 1) {
        print(max);
        continue;
    }
    var piles = 0;
    for (var i=1; i < n-1; i++) {
        if (arr[i-1]+arr[i+1] < arr[i]) piles++;
    }
    print(piles);
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseConstraints = readline().split(" ");
    var caseLength = parseInt(caseConstraints[0]);
    var caseOpLength = parseInt(caseConstraints[1]);
    var caseArray = readline().split(" ");
    var count = 0;
    var result = 0;
    if (caseOpLength == 1)
    {
        if (caseLength % 2 === 0)
        {
            result = (caseLength/2) - 1;
        }
        else result = Math.floor(caseLength/2);
    }
    else
    {
        for (var j = 1; j < caseLength-1; j++)
        {
            var term = parseInt(caseArray[j]);
            var oneLessTerm = parseInt(caseArray[j-1]);
            var onePlusTerm = parseInt(caseArray[j+1]);
            var sum = oneLessTerm + onePlusTerm;
            if (term > sum) count++;
        }
        result = count;
    }
    print(result);
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i >= n[1] || arr.length - i - 1 >= n[1]));
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					i >= n[1] &&
					arr.length - i >= n[1]);
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i >= n[1] ||
						(i + 1 <= arr.length - 1 && arr.length - (i + 1) >= n[1]))) ||
				0;
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i - 1 >= n[1] ||
						(i + 1 <= arr.length - 1 && arr.length - (i + 1) >= n[1]))) ||
				0;
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1 && n[0] > 2) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i - 1 >= n[1] ||
						(i + 1 <= arr.length - 1 && arr.length - (i + 1) + 1 >= n[1]))) ||
				0;
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i - 1 >= n[1] ||
						(i + 1 <= arr.length - 1 && arr.length - (i + 1) + 1 >= n[1])));
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i - 1 >= n[1] || (i + 1 <= arr.length - 1 && i + 1 >= n[1])));
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] &&
					(i - 1 >= n[1] || (i + 1 < arr.length - 1 && i + 1 >= n[1])));
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] && i - 1 >= n[1]);
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] && i >= n[1]);
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i === 0 || i == arr.length - 1) continue;
			count +=
				arr[i - 1] + arr[i + 1] < arr[i] ||
				(arr[i - 1] + arr[i + 1] === arr[i] && i >= n[0]);
		}
		write(count);
	}
	print();
}

var t = +readline();

while (t--) {
	var n = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});
	var arr = readline()
		.split(" ")
		.map(function (a) {
			return +a;
		});

	if (n[1] == 1) {
		write(n[0] - 2);
	} else {
		var count = 0;
		for (var i = 0; i < arr.length; i++) {
			if (i == 0 || i == arr.length - 1) continue;
			count += arr[i - 1] + arr[i + 1] < arr[i];
		}
		write(count);
	}
	print();
}

var tests = parseInt(readline());
for (var t=0; t < tests; t++) {
    var nk = readline().split(' ').map(x => parseInt(x));
    const n = nk[0];
    const k = nk[1];
    var arr = readline().split(' ').map(x => parseInt(x));
    var max = Math.floor((n - 1) / 2);
    if (k == 1) {
        print(max);
        continue;
    }
    var piles = 0;
    for (var i=1; i < n-1; i++) {
        if (arr[i-1]+arr[i+1] < arr[i]) piles++;
    }
    print(piles);
}

var tests = parseInt(readline());
for (var t=0; t < tests; t++) {
    const nk = readline().split(' ').map(x => parseInt(x));
    const n = nk[0];
    const k = nk[1];
    const arr = readline().split(' ').map(x => parseInt(x));
    var max = Math.floor((n - 1) / 2);
    if (k == 1) {
        print(max);
        continue;
    }
    var piles = 0;
    for (var i=1; i < n-1; i++) {
        if (arr[i-1]+arr[i+1] < arr[i]) {
            piles++;
        }
    }
    print(piles);
}

var tests = parseInt(readline());
for (var t=0; t < tests; t++) {
    const nk = readline().split(' ').map(x => parseInt(x));
    const n = nk[0];
    const k = nk[1];
    const arr = readline().split(' ').map(x => parseInt(x));
    var max = Math.floor((n - 1) / 2);
    if (k == 1) {
        print(max);
        continue;
    }
    var piles = 0;
    for (var i=1; i < n-1; i++) {
        if (arr[i-1]+arr[i+1] < arr[i]) piles++;
    }
    print(piles);
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseConstraints = readline().split(" ");
    var caseLength = parseInt(caseConstraints[0]);
    var caseOpLength = parseInt(caseConstraints[1]);
    var caseArray = readline().split(" ");
    var count = 0;
    var result = 0;
    if (caseOpLength == 1)
    {
        if (caseLength % 2 === 0)
        {
            result = (caseLength/2) - 1;
        }
        else result = Math.floor(caseLength/2);
    }
    else
    {
        for (var j = 1; j < caseLength-1; j++)
        {
            var term = parseInt(caseArray[j]);
            var oneLessTerm = parseInt(caseArray[j-1]);
            var onePlusTerm = parseInt(caseArray[j+1]);
            var sum = oneLessTerm + onePlusTerm;
            if (term > sum) count++;
        }
        reuslt = count;
    }
    print(result);
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseConstraints = readline().split(" ");
    var caseLength = parseInt(caseConstraints[0]);
    var caseOpLength = parseInt(caseConstraints[1]);
    var caseArray = readline().split(" ");
    var count = 0;
    var result = 0;
    if (caseOpLength == 1)
    {
        if (caseLength % 2 === 0)
        {
            result = (caseLength/2) - 1;
        }
        else result = Math.floor(caseLength/2);
    }
    else
    {
        for (var j = 1; j < caseLength-1; j++)
        {
            var term = parseInt(caseArray[j]);
            var oneLessTerm = parseInt(caseArray[j-1]);
            var onePlusTerm = parseInt(caseArray[j+2]);
            var sum = oneLessTerm + onePlusTerm;
            if (term > sum) count++;
        }
        reuslt = count;
    }
    print(result);
}

"use strict";
function toInt(x) {
	return parseInt(x);
}
function readInt() {
	return toInt(readline());
}
function readLInt() {
	return readline().split(' ').map(toInt);
}
function divCeil(a, b) {
	return Math.floor((a - 1) / b) + 1;
}
function solve() {
	let n, k;
	let x = readLInt();
	n = x[0];
	k = x[1];
	let a = readLInt();
	if (k == 1) {
		print(Math.floor(n / 2));
		return 0;
	}
	let res = 0;
	for (let ind = 1; ind + 1 < n; ind++) {
		if (a[ind] > a[ind + 1] + a[ind - 1]) res++;
	}
	print(res);
}

let t = readInt();
while (t--) solve();

var t = +readline();

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

    var t1 = readline();
    var t2 = readline().split(' ').map((t) => +t);
    print(ShuffleArray(t2))

}

function ShuffleArray(arr){
  var count = 0;
  for(var i = 0; i<arr.length-1;i++){
    if (arr[i] > arr[i-1] + arr[i+1]) count++;
  }

  return count;

}

'use strict';

function solve(n, m, a) {
  let res = 0;
  for (let i = 1; i < n - 1; i++) {
    if (a[i] > a[i - 1] + a[i + 1]) res++;
  }
  return res;
}

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

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


var n = parseInt(readline());
var q = Array(n);
var arr = readline().split(' ');
var total = 0;
for (var i = 0; i < n; i ++)
{
    q[i] = parseInt(arr[i]);
    total += q[i];
}
var m = parseInt(readline());
var t = Array(m);
var ret = -1;
for (var i = 0; i < m; i ++)
{
    var arr = readline().split(' ');
    t[i] = [parseInt(arr[0]), parseInt(arr[1])];
    if (total < t[i][0])
    {
        ret = t[i][0];
        break;
    }
    else if (total >= t[i][0] && total <= t[i][1])
    {
        ret = total;
        break;
    }
}
print(ret);

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  var tot = 0;
  a.forEach(x => tot += x);
  var m = parseInt(readline());
  var l = [];
  var r = [];
  var res = Infinity;
  for(var i = 0; i < m; i += 1) {
    var tmp = readline().split(' ').map(x => parseInt(x));
    var l = tmp[0];
    var r = tmp[1];
    if(tot >= l && tot <= r) {
      res = tot;
      break;
    }
    if(tot <= l) {
      res = l;
      break;
    }
  }
  print(res === Infinity ? -1 : res);