AquaMoon has $$$n$$$ friends. They stand in a row from left to right, and the $$$i$$$-th friend from the left wears a T-shirt with a number $$$a_i$$$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.AquaMoon hopes that after some operations, the numbers written on the T-shirt of $$$n$$$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 50$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of Aquamoon's friends. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$) — the numbers, written on the T-shirts. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower).

NoteThe possible list of operations in the first test case:  Swap $$$a_1$$$ and $$$a_2$$$. The resulting sequence is $$$3, 4, 2, 5$$$. The directions are: left, left, right, right.  Swap $$$a_2$$$ and $$$a_3$$$. The resulting sequence is $$$3, 2, 4, 5$$$. The directions are: left, left, right, right.  Swap $$$a_1$$$ and $$$a_2$$$. The resulting sequence is $$$2, 3, 4, 5$$$. The directions are: right, right, right, right.

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

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

main()

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

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

const mxV = 1e5+10;

const par = Array.from(Array(mxV), x => [0, 0]);

function main () {
	let T = rn();
	while (T--) {

		for (let i = 0; i < mxV; i++) {
			par[i][0] = par[i][1] = 0;
		}

		const n = rn();
		const a = rna();

		for (let i = 0; i < n; i++) {
			par[a[i]][i&1]++;
		}

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

		let ok = true;
		for (let i = 0; ok && i < n; i++) {
			ok = --par[a[i]][i&1] >= 0;
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const mxV = Math.max(...a) + 10;
		const par = Array.from(Array(mxV), x => [0, 0]);

		for (let i = 0; i < n; i++) {
			par[a[i]][i%2]++;
		}

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

		let ok = true;
		for (let i = 0; ok && i < n; i++) {
			ok = --par[a[i]][i%2] >= 0;
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

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

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

main()

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

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

main()

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

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

main()


Ziota found a video game called "Monster Invaders".Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.For the sake of simplicity, we only consider two different types of monsters and three different types of guns.Namely, the two types of monsters are:   a normal monster with $$$1$$$ hp.  a boss with $$$2$$$ hp. And the three types of guns are:   Pistol, deals $$$1$$$ hp in damage to one monster, $$$r_1$$$ reloading time  Laser gun, deals $$$1$$$ hp in damage to all the monsters in the current level (including the boss), $$$r_2$$$ reloading time  AWP, instantly kills any monster, $$$r_3$$$ reloading time The guns are initially not loaded, and the Ziota can only reload 1 gun at a time.The levels of the game can be considered as an array $$$a_1, a_2, \ldots, a_n$$$, in which the $$$i$$$-th stage has $$$a_i$$$ normal monsters and 1 boss. Due to the nature of the game, Ziota cannot use the Pistol (the first type of gun) or AWP (the third type of gun) to shoot the boss before killing all of the $$$a_i$$$ normal monsters.If Ziota damages the boss but does not kill it immediately, he is forced to move out of the current level to an arbitrary adjacent level (adjacent levels of level $$$i$$$ $$$(1 < i < n)$$$ are levels $$$i - 1$$$ and $$$i + 1$$$, the only adjacent level of level $$$1$$$ is level $$$2$$$, the only adjacent level of level $$$n$$$ is level $$$n - 1$$$). Ziota can also choose to move to an adjacent level at any time. Each move between adjacent levels are managed by portals with $$$d$$$ teleportation time.In order not to disrupt the space-time continuum within the game, it is strictly forbidden to reload or shoot monsters during teleportation. Ziota starts the game at level 1. The objective of the game is rather simple, to kill all the bosses in all the levels. He is curious about the minimum time to finish the game (assuming it takes no time to shoot the monsters with a loaded gun and Ziota has infinite ammo on all the three guns). Please help him find this value.

The first line of the input contains five integers separated by single spaces: $$$n$$$ $$$(2 \le n \le 10^6)$$$ — the number of stages, $$$r_1, r_2, r_3$$$ $$$(1 \le r_1 \le r_2 \le r_3 \le 10^9)$$$ — the reload time of the three guns respectively, $$$d$$$ $$$(1 \le d \le 10^9)$$$ — the time of moving between adjacent levels. The second line of the input contains $$$n$$$ integers separated by single spaces $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^6, 1 \le i \le n)$$$.

Print one integer, the minimum time to finish the game.

NoteIn the first test case, the optimal strategy is:  Use the pistol to kill three normal monsters and AWP to kill the boss (Total time $$$1\cdot3+4=7$$$)  Move to stage two (Total time $$$7+3=10$$$)  Use the pistol twice and AWP to kill the boss (Total time $$$10+1\cdot2+4=16$$$)  Move to stage three (Total time $$$16+3=19$$$)  Use the laser gun and forced to move to either stage four or two, here we move to stage four (Total time $$$19+3+3=25$$$)  Use the pistol once, use AWP to kill the boss (Total time $$$25+1\cdot1+4=30$$$)  Move back to stage three (Total time $$$30+3=33$$$)  Kill the boss at stage three with the pistol (Total time $$$33+1=34$$$) Note that here, we do not finish at level $$$n$$$, but when all the bosses are killed.

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, r1, r2, r3, d] = $(5), a = $(n)
  let f0 = Array(n), f1 = Array(n)
  f0[0] = r1 * a[0] + r3;
  f0[1] = d + r1 * a[0] + r3 + r1 * a[1] + r3;
  f0[1] = min(f0[1], 3 * d + min(r2 + r1, r1 * a[0] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[1] + min(r1 * 2, r3)))
  f1[1] = 2 * d + min(r2 + r1, r1 * a[0] + min(r1 * 2, r3)) + r1 * a[1] + r3;
  f1[1] = min(f1[1], 4 * d + min(r2 + r1, r1 * a[0] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[1] + min(r1 * 2, r3)));

  For(2, n - 1, i => {
    f1[i] = min(
      f1[i - 1] + d * 3 + r1 * a[i] + r3,
      f1[i - 1] + d * 5 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 1] + d * 2 + r1 * a[i] + r3,
      f0[i - 1] + d * 4 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 2] + d * 3 + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + r1 * a[i] + r3,
      f0[i - 2] + d * 5 + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
    );
    // if (i > 2) {
    //   f1[i] = min(f1[i],
    //     f1[i - 2] + 4 * d + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + r1 * a[i] + r3,
    //     f1[i - 2] + 6 * d + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
    //   )
    // }
    f0[i] = min(
      f1[i - 1] + d * 2 + r1 * a[i] + r3,
      f1[i - 1] + d * 4 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 1] + d + r1 * a[i] + r3,
      f0[i - 1] + d * 3 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 2] + d * 2 + r1 * a[i - 1] + r3 + r1 * a[i] + r3,
      f0[i - 2] + d * 4 + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3))
    );
    // if (i > 2) {
    //   f0[i] = min(f0[i],
    //     f1[i - 2] + 3 * d + r1 * a[i-1] + r3 + r1 * a[i] + r3,
    //     f1[i - 2] + 5 * d + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
    //   )
    // }
  });
  log(min(f0[n - 1], f1[n - 1]))
}

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, r1, r2, r3, d] = $(5), a = $(n)
  let f0 = Array(n), f1 = Array(n)
  f0[0] = r1 * a[0] + r3;
  f0[1] = d + r1 * a[0] + r3 + r1 * a[1] + r3;
  f0[1] = min(f0[1], 3 * d + min(r2 + r1, r1 * a[0] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[1] + min(r1 * 2, r3)))
  f1[1] = 2 * d + min(r2 + r1, r1 * a[0] + min(r1 * 2, r3)) + r1 * a[1] + r3;
  f1[1] = min(f1[1], 4 * d + min(r2 + r1, r1 * a[0] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[1] + min(r1 * 2, r3)));

  For(2, n - 1, i => {
    f1[i] = min(
      f1[i - 1] + d * 3 + r1 * a[i] + r3,
      f1[i - 1] + d * 5 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 1] + d * 2 + r1 * a[0] + r3,
      f0[i - 1] + d * 4 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 2] + d * 3 + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + r1 * a[i] + r3,
      f0[i - 2] + d * 5 + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
    );
    f0[i] = min(
      f1[i - 1] + d * 2 + r1 * a[i] + r3,
      f1[i - 1] + d * 4 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 1] + d + r1 * a[0] + r3,
      f0[i - 1] + d * 3 + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3)),
      f0[i - 2] + d * 2 + r1 * a[i - 1] + r3 + r1 * a[i] + r3,
      f0[i - 2] + d * 4 + min(r2 + r1, r1 * a[i - 1] + min(r1 * 2, r3)) + min(r2 + r1, r1 * a[i] + min(r1 * 2, r3))
    );
  });
  log(min(f0[n - 1], f1[n - 1]))
}


According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.

The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.

Output YES, if the flag meets the new ISO standard, and NO otherwise.

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

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

  const s = new Set(d);

  if (s.size !== 1 || prev === d[0]) {
    ans = 'NO';
  }
  else {
    prev = d[0];
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var isSameChar = function(str){
    for(let i=0; i<str.length; i++){
        if(str[0]!=str[i])
           return false;
    }
    return true;
}

var n, m, temp = [], indicator = 0, prev="", ans="YES";

rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0], m = temp[1];
        indicator++;
    }
    else {
        if(prev == input || !isSameChar(input))
            ans="NO";

       prev = input;
    }
}).on('close',function(){
    console.log(ans);
});

const readline = require('readline');

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

var IsSameColour = function (s) {
    // console.log("inside function s=%s  type is: %s", s, typeof s);
    for (let i = 1; i < s.length; i++) {
        if (s[0] != s[i])
            return false;
    }
    return true;
}

var prev, current, n, m, indicator = 0,
    ans = "YES";

rl.on('line', (current) => {
    if (indicator == 0) {
        var temp = current.split(' ').map(item => parseInt(item));
        n = temp[0];
        m = temp[1];
        indicator++;
    } else if (indicator == 1) {
        prev = current;

        if (!IsSameColour(prev)) {
            ans = "NO";
            rl.close();
        }
        indicator++;
    } else {
        if (!IsSameColour(current) || prev == current) {
            ans = "NO";
            //break;
            rl.close();
        }
        prev = current;

    }

}).on('close', () => {
    console.log(ans);
});

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var rowNum = integers[0], colNum = integers[1];

	var previousColor = -1;

	for (var r = 0; r < rowNum; r += 1) {
		var row = trim(readline());
		if (row[0] == previousColor) {
			print("NO");
			return;
		}
		previousColor = row[0];
		for (var c = 1; c < colNum; c += 1) {
			if (row[c] != row[c-1]) {
				print("NO");
				return;
			}
		}
	}

	print("YES");
}

main();

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

const N = lll[0]
const M = lll[1]

let plc = -1

;(function () {
  while(lll = readline()) {
    let lc = lll[0]
    for (var i = 1; i < lll.length; i++) {
      if (lc != lll[i]) return print('NO')
    }
    if (plc == lc) return print('NO')
    plc = lc
  }
  print('YES')
})()

var nm = readline().split(' ').map(Number);
var n = nm[0];
var m = nm[1];
var f = [];
var ans = 'YES';
for (var i=0; i<n; i++){
	f[i] = readline();
}
for (var j=0; j<n; j++){
	for (var i=0; i<m-1; i++){
	if (f[j][i] != f[j][i+1]){
			ans = 'NO';
			break;
		}
	}
	if (j<n-1){
			if (f[j][0] == f[j+1][0]){
			ans = 'NO';
			break;
		}
	}
}
print(ans);


You are given an array $$$a$$$ consisting of $$$n$$$ integers.You can remove at most one element from this array. Thus, the final length of the array is $$$n-1$$$ or $$$n$$$.Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.Recall that the contiguous subarray $$$a$$$ with indices from $$$l$$$ to $$$r$$$ is $$$a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$$$. The subarray $$$a[l \dots r]$$$ is called strictly increasing if $$$a_l < a_{l+1} < \dots < a_r$$$.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array $$$a$$$ after removing at most one element.

NoteIn the first example, you can delete $$$a_3=5$$$. Then the resulting array will be equal to $$$[1, 2, 3, 4]$$$ and the length of its largest increasing subarray will be equal to $$$4$$$.

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin
});

rl.on('line', (input) => {
    if (length === null) {
        length = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        rl.close();
    }
});

let length = null;

const solve = numbers => {
    let maxLength = 1;
    let currentLength = 1;
    let removed = false;

    for (let i = 0; i < numbers.length - 1; i++) {
        if (numbers[i] < numbers[i + 1]) {
            currentLength++;
        } else {
            if (currentLength === 1) {
                continue;
            } else {
                if (removed) {
                    if (currentLength > maxLength) {
                        maxLength = currentLength;
                    }

                    currentLength = 1;
                    removed = false;
                } else {
                    if (i + 2 <= numbers.length - 1) {
                        if (numbers[i + 2] > numbers[i]) {
                            removed = true;
                        } else if (numbers[i - 1] < numbers[i + 1]) {
                            removed = true;
                        } else {
                            if (currentLength > maxLength) {
                                maxLength = currentLength;
                            }

                            currentLength = 1;
                        }
                    }
                }
            }
        }
    }

    if (currentLength > maxLength) {
        maxLength = currentLength;
    }

    console.log(maxLength);
};

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        r = Math.max(r, x);
        if (a[i] > a[i-2]) { x = y; y = 1; continue; }
        if (a[i+1] > a[i-1]) { x = y; y = 1; continue; }
        y = 1; x = 1;
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin
});

rl.on('line', (input) => {
    if (length === null) {
        length = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        rl.close();
    }
});

let length = null;

const solve = numbers => {
    let maxLenght = 1;
    let currentLenght = 1;

    let i = 0;
    let removed = false;

    while (true) {
        while (i < (numbers.length - 1) && numbers[i] < numbers[i + 1]) {
            currentLenght++;
            i++
        }

        if (i === numbers.length - 1) {
            if (currentLenght > maxLenght) {
                maxLenght = currentLenght;
            }
            break;
        }

        if (removed) {
            if (currentLenght > maxLenght) {
                maxLenght = currentLenght;
            }
            i++;
            removed = false;
        } else {
            if (currentLenght !== 1 && numbers[i + 1] > numbers[i - 1]) {
                removed = true;
            } else {
                currentLenght = 1;
            }
            i++;
        }
    }

    console.log(maxLenght);
};

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin
});

rl.on('line', (input) => {
    if (length === null) {
        length = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        rl.close();
    }
});

let length = null;

const solve = numbers => {
    let maxLength = 1;
    let currentLength = 1;
    let removed = false;
    let lengthBeforeRemove = null;

    for (let i = 0; i < numbers.length - 1; i++) {
        if (numbers[i] < numbers[i + 1]) {
            currentLength++;
        } else {
            if (currentLength === 1) {
                continue;
            } else {
                if (removed) {
                    if (lengthBeforeRemove > currentLength) {
                        currentLength = lengthBeforeRemove;
                    }

                    if (currentLength > maxLength) {
                        maxLength = currentLength;
                    }

                    lengthBeforeRemove = null;
                    currentLength = 1;
                    removed = false;
                } else {
                    numbers[i] = numbers[i - 1];
                    lengthBeforeRemove = currentLength--;
                    i--;
                    removed = true;
                }
            }
        }
    }

    if (currentLength > maxLength) {
        maxLength = currentLength;
    }

    console.log(maxLength);
};

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 0; }
        else if (a[i+1] <= a[i-1]) { y = 0; x = 0; }
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) x = Math.max(x, y);
    }
    return Math.max(x, y);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 1; continue; }
        if (a[i+1] > a[i-1]) { r = Math.max(r, x); x = y; y = 0; continue; }
        y = 1; x = 1;
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 1; }
        else if (a[i+1] <= a[i-1]) { y = 1; x = 1; }
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] === a[i-1] + 1) { x++; y++; continue; }

        r = Math.max(r, x);
        x = 1;
        if (a[i+1] === a[i-1] + 1) { x += y; i++; }
        y = 1;
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        r = Math.max(r, x);
        if (a[i] > a[i-2]) { x = y; y = 1; continue; }
        if (a[i+1] > a[i-1]) { x = y; y = 0; continue; }
        y = 1; x = 1;
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 0; }
        else if (a[i+1] <= a[i-1]) { y = 1; x = 1; }
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0,j;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 1; continue; }
        if (a[i+1] > a[i-1]) { r = Math.max(r, x); x = y; y = 0; continue; }
        y = 1; x = 1;
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] === a[i-1] + 1) { x++; y++; continue; }

        r = Math.max(r, x);
        x = 1;
        if (a[i+1] === a[i-1] + 1) { x += y; i++; }
        y = 1;
    }
    if(n===1000) return [ x, y, a.slice(51) ];

    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }

        r = Math.max(r, x);
        x = 1;
        if (a[i+1] > a[i-1]) { x += y; i++; }
        y = 1;
    }
    return Math.max(r, x);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));

'use strict'

const problem = (n, a) => {
    let x = 1, y = 1, r = 0;
    if (a[1] > a[0]) { x++; y++; }
    for (let i = 2; i < n; i++) {
        if (a[i] > a[i-1]) { x++; y++; continue; }
        if (a[i] > a[i-2]) { r = Math.max(r, x); x = y; y = 0; }
    }
    return Math.max(r, y);
}

print(problem(+readline(), readline().split(' ').map(i => +i)));


An important meeting is to be held and there are exactly $$$n$$$ people invited. At any moment, any two people can step back and talk in private. The same two people can talk several (as many as they want) times per meeting.Each person has limited sociability. The sociability of the $$$i$$$-th person is a non-negative integer $$$a_i$$$. This means that after exactly $$$a_i$$$ talks this person leaves the meeting (and does not talk to anyone else anymore). If $$$a_i = 0$$$, the $$$i$$$-th person leaves the meeting immediately after it starts.A meeting is considered most productive if the maximum possible number of talks took place during it.You are given an array of sociability $$$a$$$, determine which people should talk to each other so that the total number of talks is as large as possible.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of each test case description contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) —the number of people in the meeting. The second line consists of $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2 \cdot 10^5$$$) — the sociability parameters of all people.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. It is also guaranteed that the sum of all $$$a_i$$$ (over all test cases and all $$$i$$$) does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ answers to all test cases. On the first line of each answer print the number $$$k$$$ — the maximum number of talks possible in a meeting. On each of the next $$$k$$$ lines print two integers $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$ and $$$i \neq j$$$) — the numbers of people who will have another talk. If there are several possible answers, you may print any of them.

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        readline();
        const myArr = readline().split(" "), myObj = {}, mostScbObj = {}, ans = [];
        let key = Number(myArr[0]), n = 0;

        myArr.forEach((scb, index) => {
            if(0 < scb) {
                if(key < Number(scb)) key = Number(scb);
                if(myObj[scb] == undefined) myObj[scb] = [index + 1];
                else myObj[scb].push(index + 1);
                n++;
            }
        });

        for(const scb in myObj) mostScbObj[key - scb] = true;

        while(1 < n) {
            let maxScb, minScb, mostScbPerson, leastScbPerson;
            for(const scb in mostScbObj) {
                maxScb = key - scb;
                break;
            }
            for(const scb in myObj) {
                minScb = scb;
                break;
            }

            mostScbPerson = myObj[maxScb].pop();
            leastScbPerson = myObj[minScb].shift();

            ans.push(mostScbPerson + " " + leastScbPerson);

            if(myObj[maxScb] != undefined && myObj[maxScb].length == 0) {
                delete myObj[maxScb];
                delete mostScbObj[key - maxScb];
            }

            if(myObj[minScb] != undefined && myObj[minScb].length == 0) {
                delete myObj[minScb];
                delete mostScbObj[key - minScb];
            }

            if(0 < maxScb - 1) {
                if(myObj[maxScb - 1] == undefined) {
                    myObj[maxScb - 1] = [mostScbPerson];
                    mostScbObj[key - (maxScb - 1)] = true;
                }else {
                    myObj[maxScb - 1].push(mostScbPerson);
                }
            }else if(0 == maxScb - 1) n--;

            if(0 < minScb - 1) {
                if(myObj[minScb - 1] == undefined) {
                    myObj[minScb - 1] = [leastScbPerson];
                    mostScbObj[key - (minScb - 1)] = true;
                }else {
                    myObj[minScb - 1].push(leastScbPerson);
                }
            }else if(0 == minScb - 1) n--;

        }

        console.log(ans.length);
        ans.forEach(conv => console.log(conv));

    }
}

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

// max heap
const mxSZ = 2e5+100;

const a = Array(mxSZ);
let sz = 0;

const L = i => 2*i+1;
const R = i => 2*i+2;
const P = i => i-1>>1;

function add (x) {
	a[sz] = x, sz++;
	let i = sz-1;
	while (i && a[P(i)].v < a[i].v) {
		[a[P(i)], a[i]] = [a[i], a[P(i)]];
		i = P(i);
	}
}

function getMax () {
	return sz ? a[0] : -1;
}

function remove () {
	if (sz == 0) return;
	a[0] = a[sz-1], sz--;
	let i = 0;
	while (L(i) < sz) {
		let smallest = i;
		if (L(i) < sz && a[L(i)].v > a[smallest].v) smallest = L(i);
		if (R(i) < sz && a[R(i)].v > a[smallest].v) smallest = R(i);
		if (i != smallest) {
			[a[smallest], a[i]] = [a[i], a[smallest]]; i = smallest;
		} else {
			break;
		}
	}
}

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const s = rna();

		for (let i = 0; i < n; i++) add({v: s[i], id: i});

		const ans = [];
		while (true) {
			const x = getMax(); if (x.v) remove(); else break;
			const y = getMax(); if (y.v) remove(); else break;
			ans.push(x.id, y.id);
			--x.v, --y.v;
			add(x), add(y);
		}

		console.log(ans.length/2);
		while (ans.length) console.log(ans.pop() + 1, ans.pop() + 1);
	}
}

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

// max heap
const mxSZ = 2e5+100;

const a = Array(mxSZ);
let sz = 0;

const L = i => 2*i+1;
const R = i => 2*i+2;
const P = i => i-1>>1;

function add (x) {
	a[sz] = x, sz++;
	let i = sz-1;
	while (i && a[P(i)].v < a[i].v) {
		[a[P(i)], a[i]] = [a[i], a[P(i)]];
		i = P(i);
	}
}

function getMax () {
	return sz ? a[0] : -1;
}

function remove () {
	if (sz == 0) return;
	a[0] = a[sz-1], sz--;
	let i = 0;
	while (L(i) < sz) {
		let smallest = i;
		if (L(i) < sz && a[L(i)].v > a[smallest].v) smallest = L(i);
		if (R(i) < sz && a[R(i)].v > a[smallest].v) smallest = R(i);
		if (i != smallest) {
			[a[smallest], a[i]] = [a[i], a[smallest]]; i = smallest;
		} else {
			break;
		}
	}
}

//add(5);
//add(10);
//add(21);
//for (let i = 0; i < 10; i++) {
//console.log(getMax());
//remove();
//}

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const s = rna();

		for (let i = 0; i < n; i++) s[i] = {v: s[i], id: i};

		for (let i = 0; i < n; i++) s[i].v && add(s[i]);

		const ans = [];
		while (true) {
			const x = getMax(); if (x != -1) remove(); else break;
			const y = getMax(); if (y != -1) remove(); else break;
			//console.log({x, y})

			ans.push(x.id, y.id);
			x.v--, y.v--;
			if (x.v > 0) add(x);
			if (y.v > 0) add(y);
		}

		console.log(ans.length/2);
		while (ans.length) console.log(ans.pop() + 1, ans.pop() + 1);
	}
}

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

		for (let i = 0; i < n; i++) a[i] = [a[i], i];

		a.sort((x, y) => y[0] - x[0]);

		const id = [];
		for (let i = 0; i < n; i++) [a[i], id[i]] = a[i];

		let ans = [];
		let r = 0; while (a[r+1]) r++;
		while (a[0] > a[1]) {
			if (r > 0 && a[r] > 0) ans.push(id[0], id[r]), a[0]--, a[r]--;
			if (a[r] == 0) r--;
			if (r == 0) break;
		}
		while (a[1]) {
			for (let i = 0; i < n; i++) {
				if (a[i] == 0) break;
				if (a[i]) ans.push(id[i]), a[i]--;
			}
		}

		console.log(ans.length>>1);
		for (let i = 0; i < ans.length>>1; i++) {
			console.log(ans[2*i] + 1, ans[2*i+1] + 1);
		}
	}

}

"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++];
}

class PriorityQueue {
  constructor(cmp) {
    this.cmp = cmp;
    this.data = [];
    this.size = 0;
  }

  add(value) {
    this.data[this.size] = value;
    this.siftUp(this.size);
    this.size += 1;
  }

  pop() {
    const top = this.top();
    if (this.size !== 0) {
      this.swap(0, this.size - 1);
      this.size -= 1;
      this.siftDown(0);
    }
    return top;
  }

  top() {
    return this.data[0];
  }

  siftDown(index) {
    while (this.leftChild(index) < this.size) {
      const leftChildIndex = this.leftChild(index);
      const rightChildIndex = this.rightChild(index);
      let swapIndex = leftChildIndex;
      if (
        rightChildIndex < this.size &&
        this.cmp(this.data[leftChildIndex], this.data[rightChildIndex]) < 0
      ) {
        swapIndex = rightChildIndex;
      }
      if (this.cmp(this.data[index], this.data[swapIndex]) > 0) break;
      this.swap(index, swapIndex);
      index = swapIndex;
    }
  }

  siftUp(index) {
    while (this.parent(index) >= 0) {
      let p = this.parent(index);
      if (this.cmp(this.data[index], this.data[p]) > 0) {
        this.swap(index, p);
      }
      index = p;
    }
  }

  swap(index1, index2) {
    [this.data[index1], this.data[index2]] = [
      this.data[index2],
      this.data[index1],
    ];
  }

  parent(index) {
    return Math.floor((index - 1) / 2);
  }

  leftChild(index) {
    return index * 2 + 1;
  }

  rightChild(index) {
    return index * 2 + 2;
  }
}

function main() {
  let n = parseInt(readline());
  while (n--) {
    readline();
    const nums = readline()
      .split(" ")
      .map((v, i) => {
        return {
          value: parseInt(v),
          index: i,
        };
      })
      .filter(v => v.value !== 0)
    const heap = new PriorityQueue((a, b) => a.value - b.value)
    for (let num of nums) {
      heap.add(num);
    }
    const ans = [];
    while (heap.size >= 2) {
      const top1 = heap.pop();
      const top2 = heap.pop();
      ans.push([top1.index, top2.index]);
      top1.value -= 1;
      top2.value -= 1;
      if (top1.value !== 0) heap.add(top1);
      if (top2.value !== 0) heap.add(top2);
    }
    console.log(ans.length);
    for (let i = 0; i < ans.length; i += 1) {
      console.log(ans[i][0] + 1, ans[i][1] + 1);
    }

  }
}

/* Common Template Starts */
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++];
}

class Heap {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  peek() {
    return this.data[0];
  }

  pop() {
    let v = this.data[0];
    this.data[0] = this.data[this.size-1];
    this.size -= 1;
    this.down(0);
    return v;
  }

  insert(o) {
    this.data[this.size] = o;
    this.size += 1;
    this.up(this.size-1);
  }

  up(i) {
    let c = i;
    while (Math.floor(c/2) >= 0) {
      let p = Math.floor(c/2);
      if (this.data[c].v > this.data[p].v) {
	let tmp = this.data[c];
	this.data[c] = this.data[p];
	this.data[p] = tmp;
	c = p;
      } else {
	break;
      }
    }
  }

  down(i) {
    let c = i;

    while (c * 2 < this.size) {
      let left = c * 2;
      let right = c * 2 + 1;

      let min = left;
      if (right < this.size && (this.data[right].v > this.data[left].v)) {
	min = right;
      }

      if (this.data[min].v > this.data[c].v) {
	let tmp = this.data[min];
	this.data[min] = this.data[c];
	this.data[c] = tmp;
	c = min;
      } else {
	break;
      }
    }
  }
}

/* Common Template Ends */
function main() {
  let Q = +(readline()); // Read Input

  for (let q = 0; q < Q; q++) {
    let N = +(readline());

    let A = readline().split(" ").map((a) => parseInt(a));
    let heap = new Heap();

    for (let i = 0; i < A.length; i++) {
      heap.insert({index: i, v: A[i]});
    }

    let talks = [];

    while (true) {
      //console.log("heap data", heap.data);
      let max1 = heap.pop();
      let max2 = heap.pop();

      if (max1.v === 0 || max2.v === 0) break;

      talks.push([max1.index+1, max2.index+1]);
      max1.v -= 1;
      max2.v -= 1;

      //console.log("heap data after", heap.data);
      heap.insert(max1);
      heap.insert(max2);
    }

    console.log(talks.length);
    for (let i = 0; i < talks.length; i++) {
      console.log(talks[i][0] + " " + talks[i][1]);
    }
  }
}

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        readline();
        const myArr = readline().split(" "), myObj = {}, mostScbObj = {}, ans = [];
        let key = myArr[0], n = 0;

        myArr.forEach((scb, index) => {
            if(0 < scb) {
                if(key < scb) key = scb;
                if(myObj[scb] == undefined) myObj[scb] = [index + 1];
                else myObj[scb].push(index + 1);
                n++;
            }
        });

        for(const scb in myObj) mostScbObj[key - scb] = true;

        while(1 < n) {
            let maxScb, minScb, mostScbPerson, leastScbPerson;
            for(const scb in mostScbObj) {
                maxScb = key - scb;
                break;
            }
            for(const scb in myObj) {
                minScb = scb;
                break;
            }

            mostScbPerson = myObj[maxScb].pop();
            leastScbPerson = myObj[minScb].shift();

            ans.push(mostScbPerson + " " + leastScbPerson);

            if(myObj[maxScb] != undefined && myObj[maxScb].length == 0) {
                delete myObj[maxScb];
                delete mostScbObj[key - maxScb];
            }

            if(myObj[minScb] != undefined && myObj[minScb].length == 0) {
                delete myObj[minScb];
                delete mostScbObj[key - minScb];
            }

            if(0 < maxScb - 1) {
                if(myObj[maxScb - 1] == undefined) {
                    myObj[maxScb - 1] = [mostScbPerson];
                    mostScbObj[key - (maxScb - 1)] = true;
                }else {
                    myObj[maxScb - 1].push(mostScbPerson);
                }
            }else if(0 == maxScb - 1) n--;

            if(0 < minScb - 1) {
                if(myObj[minScb - 1] == undefined) {
                    myObj[minScb - 1] = [leastScbPerson];
                    mostScbObj[key - (minScb - 1)] = true;
                }else {
                    myObj[minScb - 1].push(leastScbPerson);
                }
            }else if(0 == minScb - 1) n--;

        }

        console.log(ans.length);
        ans.forEach(conv => console.log(conv));

    }
}

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        readline();
        const myArr = readline().split(" "), myObj = {}, mostScbObj = {}, ans = [];
        let key = myArr[0], n = 0;

        myArr.forEach((scb, index) => {
            if(0 < scb) {
                if(key < scb) key = scb;
                if(myObj[scb] == undefined) myObj[scb] = [index];
                else myObj[scb].push(index);
                n++;
            }
        });

        for(const scb in myObj) mostScbObj[key - scb] = true;

        while(1 < n) {
            let maxScb, minScb, mostScbPerson, leastScbPerson;
            for(const scb in mostScbObj) {
                maxScb = key - scb;
                break;
            }
            for(const scb in myObj) {
                minScb = scb;
                break;
            }

            mostScbPerson = myObj[maxScb].pop();
            leastScbPerson = myObj[minScb].shift();

            ans.push(mostScbPerson + " " + leastScbPerson);

            if(myObj[maxScb] != undefined && myObj[maxScb].length == 0) {
                delete myObj[maxScb];
                delete mostScbObj[key - maxScb];
            }

            if(myObj[minScb] != undefined && myObj[minScb].length == 0) {
                delete myObj[minScb];
                delete mostScbObj[key - minScb];
            }

            if(0 < maxScb - 1) {
                if(myObj[maxScb - 1] == undefined) {
                    myObj[maxScb - 1] = [mostScbPerson];
                    mostScbObj[key - (maxScb - 1)] = true;
                }else {
                    myObj[maxScb - 1].push(mostScbPerson);
                }
            }else if(0 == maxScb - 1) n--;

            if(0 < minScb - 1) {
                if(myObj[minScb - 1] == undefined) {
                    myObj[minScb - 1] = [leastScbPerson];
                    mostScbObj[key - (minScb - 1)] = true;
                }else {
                    myObj[minScb - 1].push(leastScbPerson);
                }
            }else if(0 == minScb - 1) n--;

        }

        console.log(ans.length);
        ans.forEach(conv => console.log(conv));

    }
}

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), myArr = readline().split(" "), ans = [];
        const people = mergeSort([...Array(n).keys()], myArr);
        let i = 0, j = n - 1;

        while(myArr[people[n - 2]] != 0) {
            if(0 == myArr[people[i]]) i++;
            else {
                myArr[people[i]]--;
                myArr[people[j]]--;
                ans.push((people[i] + 1) + " " + (people[j] + 1));

                if(myArr[people[j]] < myArr[people[j - 1]]) j--;
                if(j < n && myArr[people[j]] < myArr[people[j + 1]] || i == j) j++;
            }
        }
        console.log(ans.length);
        ans.forEach(element => console.log(element));
    }
}

function mergeSort(array, reference) {
    const half = array.length / 2;
    if(array.length < 2) return array;
    const left = array.splice(0, half);
    return merge(mergeSort(left, reference),mergeSort(array, reference), reference);
}

function merge(left, right, reference) {
    let arr = [];
    while (left.length && right.length) {
        if (reference[left[0]] < reference[right[0]]) arr.push(left.shift());
        else arr.push(right.shift());
    }
    return [ ...arr, ...left, ...right ];
}

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), myArr = readline().split(" "), ans = [];
        const people = mergeSort([...Array(n).keys()], myArr);
        let i = 0, j = n - 1;

        while(myArr[people[n - 2]] != 0) {
            if(0 == myArr[people[i]]) i++;
            if(myArr[people[j]] < myArr[people[j - 1]]) j--;
            if(j < n && myArr[people[j]] < myArr[people[j + 1]] || i == j) j++;
            myArr[people[i]]--;
            myArr[people[j]]--;
            ans.push((people[i] + 1) + " " + (people[j] + 1));
        }
        console.log(ans.length);
        ans.forEach(element => console.log(element));
    }
}

function mergeSort(array, reference) {
    const half = array.length / 2;
    if(array.length < 2) return array;
    const left = array.splice(0, half);
    return merge(mergeSort(left, reference),mergeSort(array, reference), reference);
}

function merge(left, right, reference) {
    let arr = [];
    while (left.length && right.length) {
        if (reference[left[0]] < reference[right[0]]) arr.push(left.shift());
        else arr.push(right.shift());
    }
    return [ ...arr, ...left, ...right ];
}

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), myArr = readline().split(" "), ans = [];
        const people = mergeSort([...Array(n).keys()], myArr);
        let i = 0, j = n - 1;

        while(myArr[people[n - 2]] != 0) {
            if(0 == myArr[people[i]]) i++;
            if(myArr[people[j]] < myArr[people[j - 1]]) j--;
            if(j < n && myArr[people[j]] < myArr[people[j + 1]] || i == j) j++;
            myArr[people[i]]--;
            myArr[people[j]]--;
            ans.push((people[i] + 1) + " " + (people[j] + 1));
        }
        console.log(ans);
    }
}

function mergeSort(array, reference) {
    const half = array.length / 2;
    if(array.length < 2) return array;
    const left = array.splice(0, half);
    return merge(mergeSort(left, reference),mergeSort(array, reference), reference);
}

function merge(left, right, reference) {
    let arr = [];
    while (left.length && right.length) {
        if (reference[left[0]] < reference[right[0]]) arr.push(left.shift());
        else arr.push(right.shift());
    }
    return [ ...arr, ...left, ...right ];
}

'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 t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        let people = readline().split(" "), i = 0, j = n - 1;
        const ans = [];
        people = mergeSort(people);

        while(i < j) {
            if(0 == people[i]) i++;
            else if(0 == people[j]) j--;
            else {
                people[i]--;
                people[j]--;
                ans.push((i + 1) + " " + (j + 1));
            }
        }
        console.log(ans.length);
        ans.forEach(element => console.log(element));
    }
}

function mergeSort(array) {
  const half = array.length / 2;

  if(array.length < 2) return array;

  const left = array.splice(0, half);
  return merge(mergeSort(left),mergeSort(array));
}

function merge(left, right) {
    let arr = [];
    while (left.length && right.length) {
        if (left[0] < right[0]) arr.push(left.shift());
        else arr.push(right.shift());
    }
    return [ ...arr, ...left, ...right ];
}

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

		for (let i = 0; i < n; i++) a[i] = [a[i], i];

		a.sort((x, y) => y[0] - x[0]);

		const id = [];
		for (let i = 0; i < n; i++) [a[i], id[i]] = a[i];

		let ans = [];
		let r = 0; while (a[r+1]) r++;
		while (a[0] > a[1]) {
			if (r > 0 && a[r] > 0) ans.push(0, r), a[0]--, a[r]--;
			if (a[r] == 0) r--;
			if (r == 0) break;
		}
		while (a[1]) {
			for (let i = 0; i < n; i++) {
				if (a[i] == 0) break;
				if (a[i]) ans.push(i), a[i]--;
			}
		}

		console.log(ans.length>>1);
		for (let i = 0; i < ans.length>>1; i++) {
			console.log(ans[2*i] + 1, ans[2*i+1] + 1);
		}
	}

}

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		for (let i = 0; i < n; i++)
			a[i] = [a[i], i];

		a.sort((x, y) => y[0] - x[0]);

		const ans = [];
		let i = 0, j = 1;
		while (j < n) {
			if (a[j][0] == 0) { j++; continue; }
			if (a[i][0] == 0) { i++; j = i + 1; continue; }
			ans.push([a[i][1] + 1, a[j][1] + 1]);
			a[i][0]--;
			a[j][0]--;
		}

		console.log(ans.length);
		for (const pair of ans)
			console.log(pair.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 a = rna();

		for (let i = 0; i < n; i++)
			a[i] = [a[i], i];

		a.sort((x, y) => x[0] - y[0]);

		const ans = [];
		for (let i = 0; i < n-1; i++) {
			while (a[i][0]) {
				ans.push([a[i][1] + 1, a[i+1][1] + 1]);
				a[i][0]--;
				a[i+1][0]--;
			}
		}

		console.log(ans.length);
		for (const pair of ans)
			console.log(pair.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() {
  let n = parseInt(readline());
  while (n--) {
    readline();
    const nums = readline()
      .split(" ")
      .map((v, i) => {
        return {
          value: parseInt(v),
          index: i,
        };
      })
      .sort((a, b) => b.value - a.value);
    const len = nums.length;
    let [leftPoint, rightPoint] = [0, 1];
    let ans = [];
    while (leftPoint < len && rightPoint < len) {
      const left = nums[leftPoint];
      const right = nums[rightPoint];
      if (leftPoint === rightPoint) {
        rightPoint += 1;
        continue;
      }
      if (left.value === 0) {
        leftPoint += 1;
        continue;
      }
      if (right.value === 0) {
        rightPoint += 1;
        continue;
      }
      ans.push([left.index, right.index]);
      left.value -= 1;
      right.value -= 1;
    }
    console.log(ans.length);
    for (let i = 0; i < ans.length; i += 1) {
      console.log(ans[i][0] + 1, ans[i][1] + 1);
    }
  }
}


A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $$$s_1 s_2 \ldots s_n$$$. It is necessary to make this string non-decreasing in the least number of operations. In other words, each character should be not less than the previous. In one operation, you can do the following: Select an arbitrary index $$$1 \leq i \leq n$$$ in the string; For all $$$j \geq i$$$, change the value in the $$$j$$$-th position to the opposite, that is, if $$$s_j = 1$$$, then make $$$s_j = 0$$$, and vice versa.What is the minimum number of operations needed to make the string non-decreasing?

Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of test cases follows. The first line of each test cases a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the string. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the minimum number of operations that are needed to make the string non-decreasing.

NoteIn the first test case, the string is already non-decreasing.In the second test case, you can select $$$i = 1$$$ and then $$$s = \mathtt{01}$$$.In the third test case, you can select $$$i = 1$$$ and get $$$s = \mathtt{010}$$$, and then select $$$i = 2$$$. As a result, we get $$$s = \mathtt{001}$$$, that is, a non-decreasing string.In the sixth test case, you can select $$$i = 5$$$ at the first iteration and get $$$s = \mathtt{100001}$$$. Then choose $$$i = 2$$$, then $$$s = \mathtt{111110}$$$. Then we select $$$i = 1$$$, getting the non-decreasing string $$$s = \mathtt{000001}$$$.

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        s = read().split('').map(Number);
  const dp = Array.from({
    length: n
  }, () => [Infinity, Infinity]);
  if (s[n - 1] === 0) {
    dp[n - 1] = [0, 1];
  } else {
    dp[n - 1] = [1, 0];
  }
  for (let i = n - 2; i >= 0; i--) {
    if (s[i] === 0) {
      dp[i][0] = dp[i + 1][0];
      dp[i][1] = dp[i + 1][0] + 1;
    } else {
      dp[i][1] = dp[i + 1][1];
      dp[i][0] = dp[i + 1][1] + 1;
    }
  }
  let res = Infinity,
      sum = 0;
  for (let i = 0; i < n; i++) {
    res = Math.min(res, sum + dp[i][sum & 1 ^ 1]);
    if (s[i] !== (sum & 1)) sum++;
  }
  res = Math.min(res, sum);
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

function solve() {
    var n = Number(read());
    var a = read().split('').map(Number);
    var ans = 0;
    var inv = 0;
    for (var i = 0; i < n; i++) {
        var cur = (a[i] + inv) % 2;
        if (cur === 1) {
            ans++;
            inv = 1 - inv;
        }
    }
    if (ans === 0) {
        write(0);
        return;
    }
    write(ans - 1);
}

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

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

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

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

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

  return gcd(b, a % b);
}

function main() {

    let t = parseInt(readLine());

    while(t--)
    {
        const n = parseInt(readLine());

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

        let len =arr.length
        let reverse_count=false
        let count=0

        for(let i=0;i<len-1;i++){

            if(reverse_count)
            {
                if(arr[i] < arr[i+1])
                    {
                        //console.log("i2 " + i)

                        count++;
                        reverse_count=false;
                    }

            }
            else
            {
                if(arr[i] > arr[i+1])
                {
                    //console.log("i1 " + i)
                    count++;
                    reverse_count=true;
                }
            }

        }

        console.log(count)
    }
}

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const n = parseInt(input[index]);
    index++;
    const s = input[index];
    const testCase = {
      n,
      s,
    };

    testCases.push(testCase);
  }
}

function solution(testCase) {
  const { n, s } = testCase;

  let result = 0;

  let desc = true;
  for (let i = 1; i < n; i++) {
    if (desc && s[i] < s[i - 1]) {
      desc = false;
      result++;
    } else if (!desc && s[i] > s[i - 1]) {
      desc = true;
      result++;
    }
  }

  console.log(result);
}

parseInput();

testCases.forEach(solution);

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        s = read().split('').map(Number);
  const dp = Array.from({
    length: n
  }, () => [Infinity, Infinity]);
  if (s[n - 1] === 0) {
    dp[n - 1] = [0, 1];
  } else {
    dp[n - 1] = [1, 0];
  }
  for (let i = n - 2; i >= 0; i--) {
    if (s[i] === 0) {
      dp[i][0] = dp[i + 1][0];
      dp[i][1] = dp[i + 1][0] + 1;
    } else {
      dp[i][1] = dp[i + 1][1];
      dp[i][0] = dp[i + 1][1] + 1;
    }
  }
  let res = Infinity,
      sum = 0;
  for (let i = 0; i < n; i++) {
    res = Math.min(res, sum + dp[i][sum & 1 ^ 1]);
    if (s[i] !== (sum & 1)) sum++;
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

function solve() {
    var n = Number(read());
    var a = read().split('').map(Number);
    var ans = 0;
    var inv = 0;
    for (var i = 0; i < n; i++) {
        var cur = (a[i] + inv) % 2;
        if (cur === 1) {
            ans ++;
            inv = 1 - inv;
        }
    }
    write(ans - 1);
}

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

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

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

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

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