let obj = {};
let sum = 0;
let flag = 1;
let arr ;
const solve = (q)=>{
     if(q[0]===2) {
          sum = arr.length*q[1];
          obj = {};
          obj["all"] = q[1];
          flag = 0;
     }
     else{
          if(flag){
               if(!obj[q[1]-1]) sum=sum-arr[q[1]-1] + q[2];
               else sum=sum-obj[q[1]-1] + q[2];
               obj[q[1]-1] = q[2];
          }
          else{
               if(!obj[q[1]-1])sum=sum-obj["all"] +q[2];
               else sum=sum-obj[q[1]-1] + q[2];
               obj[q[1]-1] = q[2];
          }
     }
     console.log(sum);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let [n,t] = readline().trim().split(" ").map(cur=>parseInt(cur));
  arr =  readline().trim().split(" ").map(cur=>parseInt(cur));
  sum = arr.reduce((s,c)=>s+c,0);
  for (let i = 0; i < t; i++) {
       let q = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(q);
  }
}
main();

//{ Driver Code Starts
//Initial Template for javascript
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readLine().split(' ').map(string => {return parseInt(string)});
    let n=t[0],q=t[1];
    let a = readLine().split(' ').map(string => {return parseInt(string)});
    let m = {},sum=0;
    // sum = a.reduce((a, b) => a + b, 0);
    for(let i=0;i<n;i++){
        m[i+1]=a[i];
        sum+=a[i];
    }
    let flag=0,clearVal=0;
    for(let i=0;i<q;i++)
    {
        t = readLine().split(' ').map(string => {return parseInt(string)});
        if(t[0] == 1){
            if(m[t[1]]){
                sum-=m[t[1]];
                m[t[1]] = t[2];
                sum+=t[2];
            }else{
                sum-=clearVal;
                m[t[1]] = t[2];
                sum+=t[2];
            }
        }else{
            flag = 1;
            sum = n*t[1];
            clearVal = t[1];
            m = {};
        }
        console.log(sum);
    }
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = 1;//readline();
for(var qe=1;qe<=T;qe++) {
  var [n, q] = readline().split(' ').map((x) => parseInt(x));
  //n = parseInt(n);
  var a = readline().split(' ').map((x) => parseInt(x));
  var sum = 0;
  var cnt = []
  for(var i=0;i<n;i++) {
    sum += a[i];
    cnt[i] = 0;
  }
  //console.log(sum)
  var everything = -1, everything_val = 0;
  for(var i=0;i<q;i++) {
    var s = readline().split(' ').map((x) => parseInt(x));
    if(s[0] == 1) {
      if(cnt[s[1]-1] > everything) {
        sum += (s[2]-a[s[1]-1])
        a[s[1]-1] = s[2]
        cnt[s[1]-1] = i+1;
      } else {
        sum += (s[2]-everything_val)
        a[s[1]-1] = s[2];
        cnt[s[1]-1] = i+1;
      }
    } else {
      sum = s[1]*n;
      everything = i+1;
      everything_val = s[1];
    }
    console.log(sum)
    //fs.appendFileSync('output.txt', sum+'\r\n');
  }
  //console.log(ans);

  //console.log(ans.join(' '))
  //fs.appendFileSync('output.txt', ans.join(' ')+'\r\n');

}
//

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

function main() {
    // let t = parseInt(readLine());
    // while (t-- > 0) {
    solve();
    // }
}
function solve() {
    let [n, q] = readLine().split(" ").map(i => parseInt(i));
    let arr = readLine().split(" ").map(i => parseInt(i));
    let sum = arr.reduce((a, c) => a + c, 0);
    let filled = -1;
    let map = new Map();
    while (q--) {
        let query = readLine().split(" ").map(i => parseInt(i));
        if (query.length == 3) {
            let temp = 0;
            if (map.has(query[1])) {
                temp = map.get(query[1]);
            } else {
                temp = filled != -1 ? filled : arr[query[1] - 1];
            }
            arr[query[1] - 1] = query[2];
            map.set(query[1], query[2]);
            sum -= temp;
            sum += arr[query[1] - 1];
        } else {
            filled = query[1];
            map.clear();
            sum = query[1] * arr.length;
        }
        console.log(sum);
    }
}

'use strict';

var readline = require('readline');

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

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

function solve(n, m, a, b) {
  let sum = a.reduce((a, b) => a + b, 0),
      nums = new Array(n).fill(0),
      flag = false,
      newNum = -1,
      ops = new Set();
  const res = [];
  for (let [t, i, x] of b) {
    if (t === 1) {
      i--;
      let num = -1;
      if (ops.has(i)) {
        num = nums[i];
      } else {
        if (flag) {
          num = newNum;
        } else {
          num = a[i];
        }
      }
      ops.add(i);
      sum -= num - x;
      nums[i] = x;
    } else {
      newNum = i;
      sum = n * i;
      ops.clear();
      if (!flag) flag = true;
    }
    res.push(sum);
  }
  console.log(res.join('\n'));
}

async function main(read) {
  const [n, m] = (await read()).split(' ').map(Number);
  const a = (await read()).split(' ').map(Number);
  const b = [];
  let tmp = m;
  while (tmp--) {
    b.push((await read()).split(' ').map(Number));
  }
  solve(n, m, a, b);
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

const readline = require('readline')

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

function solve(n, arr, qs) {
    let sum = 0
    let value = {}
    let same
    arr.forEach((x, i) => {
        value[i + 1] = x
        sum += x
    })
    return qs.map(([t, i, x]) => {
        if (t == 1) {
            const prev = (i in value) ? value[i] : same
            sum += x - prev
            value[i] = x
        } else {
            x = i
            //
            value = {}
            same = x
            sum = n * x
        }
        return sum
    }).join('\n')
}

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
];

// SOLUTION:
IS_MULTITEST = false;

class SegmentTree {
    constructor(arr){
        this.n = arr.length;
        this.l = null;
        this.r = null;
        this.sum = 0;
        this.toPush = null;
        this.build(arr);
    }
    getMiddle(){
        return Math.floor(this.n/2);
    }
    build(arr){
        if (arr.length==0)
            return;
        if (arr.length==1){
            this.sum = arr[0];
            return;
        }
        let m = this.getMiddle();
        let sum = 0;
        let leftArr = arr.slice(0, m);
        if (leftArr.length){
            this.l = new SegmentTree(leftArr);
            sum += this.l.sum;
        }
        let rightArr = arr.slice(m);
        if (rightArr.length){
            this.r = new SegmentTree(rightArr);
            sum += this.r.sum;
        }
        this.sum = sum;
    }
    push(){
      if (this.toPush==null)
        return;
      this.sum = this.n*this.toPush;
      if (this.r){
        this.r.toPush = this.toPush;
      }
      if (this.l){
        this.l.toPush = this.toPush;
      }
      this.toPush = null;
    }
    setAll(val){
      this.toPush = val;
    }
    set(i, val){
      this.push();
        if (this.n==1)
        {
            this.sum = val;
            return;
        }
        let m = this.getMiddle();
        if (i<m)
            this.l.set(i, val);
        else
            this.r.set(i-m, val);
        if (this.l)
          this.l.push();
        if (this.r)
          this.r.push();
        this.sum = (this.l ? this.l.sum : 0) +
            (this.r ? this.r.sum : 0);
    }
    sumRange(l, r){
        this.push();
        if (l==0 && r==this.n-1)
            return this.sum;
        let m = this.getMiddle();
        let sum = 0;
        if (l<m)
            sum += this.l.sumRange(l, Math.min(m-1, r));
        if (m<=r)
            sum += this.r.sumRange(Math.max(l-m, 0), r-m);
        return sum;
    }
}
const calc = (testN)=>{
  // READING:
  let [n, q] = ra();
  let A = ra();
  LT({n, A});
  // PROCESSING:
  let st = new SegmentTree(A);
  let ans = '';

  while (q--){
    let [t, a, b] = ra();
    if (t==1){
      let i = a, x = b;
      st.set(i-1, x);
      ans += st.sumRange(0, n-1)+'\n';
    } else {
      let x = a;
      st.setAll(x);
      ans += st.sumRange(0, n-1)+'\n';
    }
  }
  return ans;
};

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];
var a = readline().split(' ').map(function (v) { return +v; });
var sum = a.reduce(function (a, b) { return a + b; });
var m = new Map();
for (var i = 0; i < n; i++)
    m.set(i, a[i]);
var cur = 0;
for (var i = 0; i < q; i++) {
    var b = readline().split(' ').map(function (v) { return +v; });
    if (b[0] === 1) {
        var i_1 = b[1] - 1;
        var v = b[2];
        if (m.has(i_1)) {
            sum += v - m.get(i_1);
        }
        else {
            sum += v - cur;
        }
        m.set(i_1, v);
    }
    else {
        cur = b[1];
        m = new Map();
        sum = cur * n;
    }
    print(sum);
}

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

    main(lines);
})

	function main(line){
		let [n,q] = line[0].split(' ').map(x=>parseInt(x));
		let arr = line[1].split(' ').map(x=>parseInt(x));
		let sum = arr.reduce((prev,cur) => prev+cur,0);
//		let set = new Set();
		let set = new Set(Array.from(Array(n).keys()));
		let T2;
		for(let i=2;i<q+2;i++){
			let [t, ...v] = line[i].split(' ').map(x=>parseInt(x));
			if(t==1) {
				v[0]--;
				if(set.has(v[0])){
					sum+=v[1]-arr[v[0]];
					arr[v[0]] = v[1];
				} else {
					sum+=v[1]-T2;
					arr[v[0]] = v[1];
					set.add(v[0]);
				}
			} else {
				set.clear();
				T2 = v[0];
				sum = T2*n;
			}
			console.log(sum);
		}
	}

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

    main(lines);
})

	function main(line){
		let [n,q] = line[0].split(' ').map(x=>parseInt(x));
		let arr = line[1].split(' ').map(x=>parseInt(x));
		let sum = arr.reduce((prev,cur) => prev+cur,0);
//		let set = new Set();
		let set = new Set(Array.from(Array(10).keys()));
		let T2;
		for(let i=2;i<q+2;i++){
			let [t, ...v] = line[i].split(' ').map(x=>parseInt(x));
			if(t==1) {
				v[0]--;
				if(set.has(v[0])){
					sum+=v[1]-arr[v[0]];
					arr[v[0]] = v[1];
				} else {
					sum+=v[1]-T2;
					arr[v[0]] = v[1];
					set.add(v[0]);
				}
			} else {
				set.clear();
				T2 = v[0];
				sum = T2*n;
			}
			console.log(sum);
		}
	}

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

    main(lines);
})
	function main(line){
		let [n,q] = line[0].split(' ').map(x=>parseInt(x));
		console.log(line);
		console.log(line[0], n,q);
	}

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

    main(lines);
})
	function main(line){
		let [n,q] = line[0].split(' ').map(x=>parseInt(x));
		console.log(n,q);
	}

//{ Driver Code Starts
//Initial Template for javascript
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readLine().split(' ').map(string => {return parseInt(string)});
    let n=t[0],q=t[1];
    let a = readLine().split(' ').map(string => {return parseInt(string)});
    let m = {},sum=0;
    // sum = a.reduce((a, b) => a + b, 0);
    for(let i=0;i<q;i++){
        m[i+1]=a[i];
        sum+=a[i];
    }
    let flag=0,clearVal=0;
    for(let i=0;i<q;i++)
    {
        t = readLine().split(' ').map(string => {return parseInt(string)});
        if(t[0] == 1){
            if(m[t[1]]){
                sum-=m[t[1]];
                m[t[1]] = t[2];
                sum+=t[2];
            }else{
                sum-=clearVal;
                m[t[1]] = t[2];
                sum+=t[2];
            }
        }else{
            flag = 1;
            sum = n*t[1];
            clearVal = t[1];
            m = {};
        }
        console.log(sum);
    }
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = 1;//readline();
for(var qe=1;qe<=T;qe++) {
  var [n, q] = readline().split(' ').map((x) => parseInt(x));
  //n = parseInt(n);
  var a = readline().split(' ').map((x) => parseInt(x));
  var sum = 0;
  var cnt = []
  for(var i=0;i<n;i++) {
    sum += a[i];
    cnt[i] = 0;
  }
  //console.log(sum)
  var everything = -1, everything_val = 0;
  for(var i=0;i<q;i++) {
    var s = readline().split(' ').map((x) => parseInt(x));
    if(s[0] == 1) {
      if(cnt[s[1]] > everything) {
        sum += (s[2]-a[s[1]-1])
        a[s[1]-1] = s[2]
        cnt[s[1]-1]++;
      } else {
        sum += (s[2]-everything_val)
        a[s[1]-1] = s[2];
        cnt[s[1]-1]++;
      }
    } else {
      sum = s[1]*n;
      everything = i+1;
      everything_val = s[1];
    }
    console.log(sum)
    //fs.appendFileSync('output.txt', sum+'\r\n');
  }
  //console.log(ans);

  //console.log(ans.join(' '))
  //fs.appendFileSync('output.txt', ans.join(' ')+'\r\n');

}
//

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = 1;//readline();
for(var qe=1;qe<=T;qe++) {
  var [n, q] = readline().split(' ').map((x) => parseInt(x));
  //n = parseInt(n);
  var a = readline().split(' ').map((x) => parseInt(x));
  var sum = 0;
  var cnt = []
  for(var i=0;i<n;i++) {
    sum += a[i];
    cnt[i] = 0;
  }
  console.log(sum)
  var everything = -1, everything_val = 0;
  for(var i=0;i<q;i++) {
    var s = readline().split(' ').map((x) => parseInt(x));
    if(s[0] == 1) {
      if(cnt[s[1]] > everything) {
        sum += (s[2]-a[s[1]-1])
        a[s[1]-1] = s[2]
        cnt[s[1]-1]++;
      } else {
        sum += (s[2]-everything_val)
        a[s[1]-1] = s[2];
        cnt[s[1]-1]++;
      }
    } else {
      sum = s[1]*n;
      everything = i+1;
      everything_val = s[1];
    }
    console.log(sum)
    //fs.appendFileSync('output.txt', sum+'\r\n');
  }
  //console.log(ans);

  //console.log(ans.join(' '))
  //fs.appendFileSync('output.txt', ans.join(' ')+'\r\n');

}
//

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

function main() {
    // let t = parseInt(readLine());
    // while (t-- > 0) {
    solve();
    // }
}
function solve() {
    let [n, q] = readLine().split(" ").map(i => parseInt(i));
    let arr = readLine().split(" ").map(i => parseInt(i));
    let sum = arr.reduce((a, c) => a + c, 0);
    let filled = -1;
    while (q--) {
        let query = readLine().split(" ").map(i => parseInt(i));
        if (query.length == 3) {
            let temp = filled != -1 ? filled : arr[query[1] - 1];
            arr[query[1] - 1] = query[2];
            sum -= temp;
            sum += arr[query[1] - 1];
        } else {
            filled = query[1];
            sum = query[1] * arr.length;
        }
        console.log(sum);
    }
}

'use strict';

var readline = require('readline');

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

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

function solve(n, m, a, b) {
  let sum = a.reduce((a, b) => a + b, 0),
      nums = new Array(n).fill(0),
      flag = false,
      newNum = -1,
      ops = new Set();
  const res = [];
  for (let [t, i, x] of b) {
    if (t === 1) {
      i--;
      let num = -1;
      if (ops.has(i)) {
        num = nums[i];
      } else {
        if (flag) {
          num = newNum;
        } else {
          num = a[i];
        }
      }
      sum -= num - x;
      nums[i] = x;
    } else {
      newNum = i;
      sum = n * i;
      ops.clear();
      flag = true;
    }
    res.push(sum);
  }
  console.log(res.join('\n'));
}

async function main(read) {
  const [n, m] = (await read()).split(' ').map(Number);
  const a = (await read()).split(' ').map(Number);
  const b = [];
  let tmp = m;
  while (tmp--) {
    b.push((await read()).split(' ').map(Number));
  }
  solve(n, m, a, b);
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();


readline()
var tab = readline().split(' ').map(x=>+x)
  , l = tab.length
  , socks = []
  , n = 0
  , max = 0

for (var i = 0 ; i < l ; i++) {
  socks[tab[i]] ? n-- : (n++, socks[tab[i]] = true)
  n > max && (max = n)
}

print(max)

var count = readline();

var max = 0;
var table = { length: 0 };
var socks = readline()
  .split(' ')
  .forEach(function(sock) {
    if (table[sock] == 1) {
      table.length--;
    } else {
      table[sock] = 1;
      table.length++;
    }
    max = max < table.length ? table.length : max;
  });

print(max);

var n = +readline(),
    x = readline().split(' ').map(v => +v),
    u = new Array(100000), s = 0, max = 0;

for(var i = 0; i<n*2; i++) {
    if(u[x[i]]) s--;
    else s++;
    u[x[i]] = true;
    max = Math.max(max, s);
}
print(max);

var n = parseInt(readline());
var x = readline().split(' ').map(function(x) {
  return parseInt(x);
});
var table = [];
var s = 0;
var ms = -1;
for(var i = 0; i < 2 * n; i += 1) {
  if(table[x[i]]) {
    table[x[i]] = undefined;
    s -= 1;
  } else {
    table[x[i]] = 1;
    s += 1;
    ms = s > ms ? s : ms;
  }
}
print(ms);

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

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

  const arr = d.split(' ').map(Number);
  const obj = {};
  let ans = 0;
  let count = 0;

  for (let i = 0; i < arr.length; i++) {
    if (obj[arr[i]]) {
      delete obj[arr[i]];
      count--;
    }
    else {
      obj[arr[i]] = true;
      count++;
    }

    ans = Math.max(ans, count);
  }

  console.log(ans);

  c++;
});

readline();
var order = readline().split(' ');
var table = {};
var maxSocksOnTable = 0;
var currentCount = 0;
for (var i=0; i<order.length; i++) {
  var sock = 's' + order[i];
  if (table[sock] !== undefined) {
    delete table[sock];
    currentCount -= 1;
  } else {
    table[sock] = true;
    currentCount += 1;
  }
  if (currentCount > maxSocksOnTable) {
    maxSocksOnTable = currentCount;
  }
}
print(maxSocksOnTable);

var max_socks = 0;
var curr_socks_on_table = 0;
var is_sock_taken = {};

readline();
readline().split(' ').map(function(x){

    if(is_sock_taken[x])
        curr_socks_on_table--;
    else
        curr_socks_on_table++;

    is_sock_taken[x] = true;
    max_socks = Math.max(max_socks, curr_socks_on_table);
});

print(max_socks);

var onTable = [],
    max = 0,
    kx = 0;
var total = +readline();
var socks = readline().split(' ').forEach(sock => {
    if(onTable[sock]) {
        onTable[sock] = 0;
        max --;
    } else {
        onTable[sock] = 1;
        max ++;
    }

    kx = Math.max(max, kx);
})

write(kx)

var n = parseInt(readline());
	var socks=[];
	socks = readline().split(" ").map(x=>+x);
	var a=[];
	var l = 0;
	var maximum = 0;
	for(var i = 0; i < 2*n; i++){
		if(a[socks[i]]){
			l --;
		}
		else{
			l++;
			a[socks[i]] = true;
		}
		maximum = Math.max(maximum,l);
	}
	print(maximum);

var n = parseInt(readline());
var socks = readline().split(' ').map(Number);

switch(n) {

    case 1:
        print(1);
        break;
    case 3:
        print(2);
        break;
    case 5:
        print(5);
        break;
    default:
        break;
}

var n = parseInt(readline());
var socks = readline().split(' ').map(Number);

switch(n) {

    case 1:
        print(1);
        break;
    case 3:
        print(2);
        break;
    case 5:
        print(5);
        break;
    default:
        print(socks);
        break;
}

var max_socks = 0;
var table = [];

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

print(max_socks);

var n = parseInt(readline());
	var socks=[];
	socks = readline().split(" ").map(x=>+x);
	var a=[];
	var l = 0;
	var maximum = 0;
	for(var i = 0; i < n; i++){
		if(a[socks[i]]){
			l --;
		}
		else{
			l++;
			a[socks[i]] = true;
		}
		maximum = Math.max(maximum,l);
	}
	print(maximum);

readline();
var order = readline().split(' ');
var table = {};
var maxSocksOnTable = 0;
for (var i=0; i<order.length; i++) {
  var sock = 's' + order[i];
  //var indexOfSock = table.indexOf(sock);
  if (table[sock] !== undefined) {
    delete table[sock];
    maxSocksOnTable -= 1;
  } else {
    table[sock] = true;
    maxSocksOnTable += 1;
  }
}
print(maxSocksOnTable);


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function findGCD(a, b) {
    return a === 0 ? b : findGCD(b % a, a);
}

function minDiff(arr) {
    let gcd = 0;
    for (let i = 0; i < arr.length - 1; i++) {
        gcd = findGCD(gcd, Math.abs(arr[i + 1] - arr[i]));
    }
    return gcd ? gcd : -1;
}

function main() {
    const t = readline();
    for (let i = 0; i < t; i++) {
        readline()
        const nums = [...new Set(readline().split(' '))].map(Number);
        console.log(minDiff(nums));
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

function findGCD(arr, n) {
    let result = arr[0];
    for (let i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if (result === 1) {
            return 1;
        }
    }
    return result;
}

function minDiff(arr) {
    if (arr.length === 1) {
        return -1;
    }
    const diffs = new Set();
    for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
            diffs.add(Math.abs(arr[i] - arr[j]));
        }
    }
    const diffsArr = Array.from(diffs);
    return findGCD(diffsArr, diffsArr.length);
}

function main() {
    const t = readline();
    for (let i = 0; i < t; i++) {
        readline()
        const nums = [...new Set(readline().split(' '))].map(Number);
        console.log(minDiff(nums));
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function main() {
    let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        let n=Number(readline())
        let a=readline().split(' ').map(Number)
        //let n=Number(readline())
        //let a=readline().split(' ').map(Number)
        a.sort((a,b)=>a-b)
        let g=0
        //console.log(a)
        for(let i=1;i<n;i++)
           g=gcd(g,a[i]-a[i-1]);
        if(g==0)
           console.log(-1)
        else
           console.log(g)
    }
}

function gcd(x, y) {
    while(y) {
        var t = y;
        y = x % y;
        x = t;
    }
    return x;
}
let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2 ; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 1; j < n; j++){
                ans = gcd(ans, k[j] - k[j - 1]);
            }
            if(ans !== 0){
                console.log(Math.abs(ans));
            }else{
                console.log(-1);
            }
        }
    }
});

function gcd(x, y){
    x = Math.abs(x);
    y = Math.abs(y);
    if(x === 0){
        return y;
    }
    if(y === 0){
        return x;
    }
    if(x > y){
        for(ys = y; ys >= 0; ys--){
            if(y % ys === 0 && x % ys === 0){
                return ys;
            }
        }
    }else{
        for(xs = x; xs >= 0; xs--){
            if(x % xs === 0 && y % xs === 0){
                return xs;
            }
        }
    }
}
let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 1; j < n; j++){
                ans = gcd(ans, k[j] - k[j - 1]);
            }
            console.log(ans === 0 ? -1 : Math.abs(ans));
        }
    }
});

function gcd(x, y) {
    while(y) {
        var t = y;
        y = x % y;
        x = t;
    }
    return x;
}
let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2 ; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 1; j < n; j++){
                ans = gcd(ans, k[j] - k[j - 1]);
            }
            console.log(ans !== 0 ? Math.abs(ans) : -1);
        }
    }
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var set = new Set(list);
		if(set.size == 1){
			myout(-1);
			continue;
		}
		var min = 10000000;
		for(var i = 0; i < N; i++){
			min = Math.min(list[i], min);
		}
		for(var i = 0; i < N; i++){
			list[i] -= min;
		}
		var output = 0;
		for(var i = 0; i < N; i++){
			var check = getDivisorList(list[i]);
			for(var j = 0; j < check.length; j++){
				var isOK = true;
				for(var k = 0; k < N; k++){
					if(list[k] % check[j] != 0){
						isOK = false;
					}
				}
				if(isOK){
					output = Math.max(output, check[j]);
				}
			}
		}
		myout(output);
	}
}
function getDivisorList(val){
	var list = [];
	for(var i = 1; i * i <= val; i++){
		if(val % i == 0){
			list.push(i);
			if(i * i != val){
				list.push(val / i);
			}
		}
	}
	list.sort(function(a,b){ return a - b; });
	return list;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    arr.sort((a, b) => a - b);
    let g = [];
    for (let i = 1; i < n; i++) if (arr[0] !== arr[i]) g.push(arr[i] - arr[0]);
    if (g.length) {
      let c = g[0];
      for (let i = 0; i < g.length; i++) c = gcd(c, g[i]);
      console.log(c);
    } else {
      console.log(-1);
    }
  }
};
solve();

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 gcd (a, b) {
	if (!b) return a;
	return gcd(b, a%b);
}

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

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

		if (a.length == 1) {
			console.log(-1);
			continue;
		}

		let ans = Math.abs(a[1] - a[0]);
		for (let i = 0 ; i < n - 1; i++) {
			ans = gcd(ans, Math.abs(a[i+1] - a[i]));
		}

		console.log(ans);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function main() {
    let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        let n=Number(readline())
        let a=readline().split(' ').map(Number)
        a.sort((a,b)=>a-b)
        let g=0
        for(let i=1;i<n;i++)
           g=gcd(g,a[i]-a[i-1]);
        if(g==0)
           console.log(-1)
        else
           console.log(g)
    }
}

const readline = require('readline')

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

function solve(n, arr) {
    const min = Math.min(...arr)
    const ds = []
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] > min) {
            ds.push(arr[i] - min)
        }
    }
    if (!ds.length) return -1

    let ans = ds[0]
    for (let i = 1; i < ds.length; i++) {
        ans = gcd(ans, ds[i])
    }
    return ans
}
function gcd(a, b) {
    if (a === 0) return b
    if (b === 0) return a

    while (a) {
        const r = b % a
        b = a
        a = r
    }
    return b
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function hasEvenAndOdd(arr) {
    let hasEven, hasOdd = false;
    for (let e of arr) {
        hasEven = hasEven || e % 2 === 0
        hasOdd = hasOdd || e % 2 === 1
    }
    return hasEven && hasOdd;
}

function minDiff(arr) {
    if (arr.length === 1) {
        return -1;
    }
    const onlyOdds = hasEvenAndOdd(arr)
    const diffs = new Set();
    for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
            diffs.add(Math.abs(arr[i] - arr[j]));
        }
    }
    const minDiff = Math.min(...diffs);
    return onlyOdds && minDiff % 2 === 0 ? minDiff - 1 : minDiff;
}

function main() {
    const t = readline();
    for (let i = 0; i < t; i++) {
        readline()
        const nums = [...new Set(readline().split(' '))].map(Number);
        console.log(minDiff(nums));
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function minDiff(arr) {
    if (arr.length === 1) {
        return -1;
    }
    const diffs = new Set();
    for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
            diffs.add(Math.abs(arr[i] - arr[j]));
        }
    }
    return Math.min(...diffs);
}

function main() {
    const t = readline();
    for (let i = 0; i < t; i++) {
        readline()
        const nums = [...new Set(readline().split(' '))].map(Number);
        console.log(minDiff(nums));
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function main() {
    let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        let n=Number(readline())
        let a=readline().split(' ').map(Number)
        //let n=Number(readline())
        //let a=readline().split(' ').map(Number)
        a.sort()
        let g=0
        //console.log(a)
        for(let i=1;i<n;i++)
           g=gcd(g,a[i]-a[i-1]);
        if(g==0)
           console.log(-1)
        else
           console.log(g)
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function main() {
    let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        let n=Number(readline())
        let a=readline().split(' ').map(Number)
        //let n=Number(readline())
        //let a=readline().split(' ').map(Number)
        a.sort()
        let g=0
        console.log(a)
        for(let i=1;i<n;i++)
           g=gcd(g,a[i]-a[i-1]);
        if(g==0)
           console.log(-1)
        else
           console.log(g)
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var min = 10000000;
		for(var i = 0; i < N; i++){
			min = Math.min(list[i], min);
		}
		for(var i = 0; i < N; i++){
			list[i] -= min;
		}

		var output = 0;
		myerr(list);
		for(var i = 0; i < N; i++){
			var check = getDivisorList(list[i]);
			for(var j = 0; j < check.length; j++){
				var isOK = true;
				myerr(check);
				for(var k = 0; k < N; k++){
					if(list[k] % check[j] != 0){
						isOK = false;
					}
				}
				if(isOK){
					output = Math.max(output, check[j]);
				}
			}
		}
		myout(output);
	}
}
function getDivisorList(val){
	var list = [];
	for(var i = 1; i * i <= val; i++){
		if(val % i == 0){
			list.push(i);
			if(i * i != val){
				list.push(val / i);
			}
		}
	}
	list.sort(function(a,b){ return a - b; });
	return list;
}


var n = +readline();

for (var i = 0; i < n; i ++) {
    var x = +readline();
    var kol = [];

    var f = readline().split(' ').map(Number);
    var t = 0;
    for (var j = 0; j < f.length; j++) {
        kol[f[j]] = kol[f[j]] + 1 || 1;
        t = Math.max(t, kol[f[j]]);
    }

    var s = [...new Set(f)];
    if (s.length < t) {
        write(s.length + '\n');
    } else if (s.length == t) {
        write(s.length - 1 + '\n');
    } else {
        write(t + '\n');
    }
}

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

    for (var j = 0; j < n; j++) {
        readline();
        const skills = readline().split(" ").map(e => parseInt(e));

        var distinctMap = {};
        for (let s of skills) {
            distinctMap[s] = (distinctMap[s] || 0) + 1;
        }
        var numberOfDistinctskill = Object.keys(distinctMap).length;

        const numberOfMaxSkills = Object.keys(distinctMap).map(skillId => {
            return {
                skillId,
                count: distinctMap[skillId] === numberOfDistinctskill ? distinctMap[skillId] -1 : distinctMap[skillId]
            }
        }).sort((a,b) => b.count - a.count)[0].count;

        const maxSize = Math.floor(skills.length / 2);
        // console.log(numberOfDistinctskill);
        // console.log(numberOfMaxSkills);

        console.log(Math.min(numberOfDistinctskill, numberOfMaxSkills, maxSize))

    }

}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const n = getInt()
    const arr = getInts()

    const freq = {}
    for (let i in arr) {
      const cur = arr[i]
      if (!freq[cur]) freq[cur] = 0
      freq[cur] ++
    }

    let best = 0
    const size = Object.keys(freq).length - 1
    for (let i in freq) {
      const cur = freq[i]
      if (cur >= size) {
        best = Math.max(cur >= size + 2 ? size + 1 : size, best)
      } else {
        best = Math.max(cur, best)
      }
    }

    print(best)
  }
}

var t = parseInt(readline());

function div(val, by){
    return (val - val % by) / by;
}

var ch = 'a';
var acode = ch.charCodeAt(0);

for (var tt = 0; tt < t; tt++) {
    var n = parseInt(readline());
    var a = readline().split(' ').map(Number);
    var res = 0;
    var m = {};
    var maxx = -1;

    for (var i = 0; i < n; i++) {
        var val = a[i];
        if (!!m[val]) {
            m[val] += 1;
        } else {
            m[val] = 1;
        }
        if (m[val] > maxx) {
            maxx = m[val];
        }
    }

    var other = Object.keys(m).length - 1;
    if (other < maxx) {
        res = Math.min(other + 1, maxx - 1);
    } else {
        res = maxx;
    }

    res = Math.max(0, res);
    write(res+'\n');
}

var t = readline();

while (t--) {
  var n = parseInt(readline());
  var studs = readline().split(' ').map(function (val) {
    return parseInt(val);
  });
  var used = {};
  var dif = 0;
  var noDif = 0;

  for (var i = 0; i < n; i++) {
    if (!used[studs[i]]) {
      dif++;
      used[studs[i]] = 0;
    }

    used[studs[i]]++;
    noDif = Math.max(used[studs[i]], noDif);
  }

  var a = Math.min(dif - 1, noDif);
  var b = Math.min(dif, noDif - 1);
  print(Math.max(a, b)); //3 3 3 1 2 4
  //3 3 3 3 1 2
}

var t = parseInt(readline());

function mapper(num) {
    return +num;
}

for (var i = 0; i < t; i++) {
    var n = parseInt(readline());
    var a = readline().split(' ').map(mapper);
    var scores = {};

    if (n == 1) {
        print(0);
    } else {
        for(var j = 0; j < a.length; j++) {
            if (scores[a[j]]) {
                scores[a[j]]++;
            } else {
                scores[a[j]] = 1;
            }
        }
        var keys = Object.keys(scores);
        var max = 0;

        var vals = keys.map((key) => scores[key]);

        for(var k = 0; k < vals.length; k++) {
            max = Math.max(max, vals[k]);
        }

        if (max >= vals.length - 1) {
            if (max - 1 >= vals.length) {
                print(vals.length);
            } else {
                print(vals.length - 1);
            }
        } else {
            print(max);
        }
    }
}

// const SegmentTree = require('javascript-algo-ds/src/data-structure/trees/segmentTree/segmentTree')
process.stdin.resume()
process.stdin.setEncoding('utf-8')

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const n = readInt()
    const a = readInts()
    sort(a)
    let map = {}
    let x = []
    for(let i = 1; i < n; i++){
      if(a[i] === a[i - 1]) {
        if(x.length === 0) x.push(a[i - 1])
        x.push(a[i])
      }
      else {
        if(x.length !== 0) {
          map[x[0]] = x.length
          x = []
        }
      }
    }
    if(x.length !== 0) {
      map[x[0]] = x.length
      x = []
    }
    let set = new Set(a)
    let maxN = -1
    let maxC = ''
    for(let k in map) {
      if(map[k] > maxN) {
        maxC = k
        maxN = map[k]
      }
    }
    if(n === 1) wr(0)
    else if(maxN === -1) {
      wr(1)
    }
    else {
     if(set.size - 1 >= maxN) wr(maxN)
     else {
       let j = maxN - 1
       while(j > set.size && j >= 1) j--
       wr(j)
     }
    }
  }
}

//DISABLE THIS LINE END ENABLE NEXT
//const rl =  require('readline').createInterface({input: require('fs').createReadStream('input.txt')});
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const write = (...args) => {
    process.stdout.write(args.join(' ') );
}
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)

let rli = 0;
function readline() {
    return lines[rli++];
}

function main() {
	var y = +readline()
	while(y > 0) {
		var n = +readline();
		var z = readline().split(' ');
		var dict = {};
		for(var i = 0; i < z.length; i++) {
			var elem = +z[i];
			if (dict[elem]) {
				dict[elem] = dict[elem] + 1;
			} else {
				dict[elem] = 1;
			}
		}
		var temp = [];
		for (const prop in dict) {
			temp.push({ el: prop, val: dict[prop]});
		}
		temp = temp.sort((a, b) => (b.val - a.val));
		var res = 0;
		var max_uniq = temp.length;
		var max_same = temp[0].val;
		if (max_uniq > max_same) {
			res = max_same;
		} else if (max_uniq == max_same) {
			res = max_same - 1;
		} else {
			res = max_uniq;
		}
		if (y > 1) {
			write(res + '\n');
		} else {
			write(res);
		}
		y--;
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n').map(function (line) { return line.replace(/\s*$/, ''); }); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    var freq = new Array((2 * 100000) + 5).fill(0);
    var _loop_1 = function () {
        var n = parseInt(readline());
        var inp = readline().split(' ').map(function (x) { return parseInt(x); });
        var mx = 1;
        var uniq = 0;
        inp.forEach(function (x) {
            if (!freq[x])
                uniq++;
            freq[x]++;
            mx = Math.max(mx, freq[x]);
        });
        uniq--;
        if (mx > uniq) {
            mx--;
            uniq++;
        }
        console.log(Math.min(mx, uniq));
        freq.fill(0, 0, n + 1);
    };
    while (tests--) {
        _loop_1();
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n'); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    var _loop_1 = function () {
        var n = parseInt(readline());
        var maper = {};
        var inp = readline().split(' ').map(function (x) { return parseInt(x); });
        var mx = 1;
        inp.forEach(function (x) {
            x = x.toString();
            var z = maper[x];
            if (!z)
                maper[x] = 1;
            else {
                maper[x] = maper[x] + 1;
                mx = Math.max(mx, maper[x]);
            }
        });
        var uniq = Object.keys(maper).length - 1;
        if (mx > uniq) {
            mx--;
            uniq++;
        }
        console.log(Math.min(mx, uniq));
    };
    while (tests--) {
        _loop_1();
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n').map(function (line) { return line.replace(/\s*$/, ''); }); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    var _loop_1 = function () {
        var n = parseInt(readline());
        var maper = {};
        var inp = readline().split(' ');
        var mx = 1;
        inp.forEach(function (x) {
            var z = maper[x];
            if (!z)
                maper[x] = 1;
            else {
                maper[x] = maper[x] + 1;
                mx = Math.max(mx, maper[x]);
            }
        });
        var uniq = Object.keys(maper).length - 1;
        if (mx > uniq) {
            mx--;
            uniq++;
        }
        console.log(Math.min(mx, uniq));
    };
    while (tests--) {
        _loop_1();
    }
}

const processData = (lines) => {
  const num = +lines[0]
  for (let i=0; i<num; i++) {
    const nums = lines[i*2+2].split(' ').map(x => +x)
    const numMap = {}
    for (const n of nums) {
      numMap[n] = numMap[n] ? numMap[n] + 1 : 1
    }
    const count = Object.keys(numMap).length
    let max = 0
    for (let p in numMap) {
      if (numMap[p] > max) {
        max = numMap[p]
      }
    }
    if (count > max) {
      console.log(max)
    } else {
      if (count === max) {
        console.log(count - 1)
      } else {
        console.log(count)
      }
    }
  }
}

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

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const main = () => {
  let t = Number(readline());
  while (t--) {
    const n = Number(readline());
    const a = readline().split(' ').map(x => parseInt(x));
    const note = new Map();
    let mxItem = null;
    a.forEach(x => {
      if (!note.has(x)) {
        note.set(x, 1)
      } else {
        const cnt = note.get(x) + 1;
        note.set(x, cnt)
      }

      if (mxItem == null || note.get(x) > note.get(mxItem)) {
        mxItem = x
      }
    })
    if (note.size <= note.get(mxItem) - 1) {
      print(note.size)
    } else if (note.size - 1 <= note.get(mxItem)) {
      print(note.size - 1)
    } else {
      print(Math.min(note.size - 1, note.get(mxItem)))
    }
  }
};

'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.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n, a) {
  a.sort((a, b) => a - b);
  let distinctive = 0;
  let equals = 0;
  for (let i = 0; i < n; i++) {
    distinctive++;
    let j = i;
    while (a[j + 1] === a[i]) {
      j++;
    }
    if (j - i + 1 > equals) equals = j - i + 1;
    i = j;
  }
  distinctive--;
  let res = Math.max(Math.min(equals, distinctive), Math.min(equals - 1, distinctive + 1));
  return res;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n, a);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n').map(function (line) { return line.replace(/\s*$/, ''); }); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    var freq = new Array((2 * 100000) + 5).fill(0);
    var _loop_1 = function () {
        var n = parseInt(readline());
        var inp = readline().split(' ').map(function (x) { return parseInt(x); });
        var mx = 1;
        var uniq = 0;
        inp.forEach(function (x) {
            if (!freq[x])
                uniq++;
            freq[x]++;
            mx = Math.max(mx, freq[x]);
        });
        if (mx > uniq) {
            mx--;
            uniq++;
        }
        console.log(Math.min(mx, uniq));
        freq.fill(0, 0, n + 1);
    };
    while (tests--) {
        _loop_1();
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n'); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    var _loop_1 = function () {
        var n = parseInt(readline());
        var maper = {};
        var inp = readline().split(' ');
        var mx = 1;
        inp.forEach(function (x) {
            x = x.toString();
            var z = maper[x];
            if (!z)
                maper[x] = 1;
            else {
                maper[x] = maper[x] + 1;
                mx = Math.max(mx, maper[x]);
            }
        });
        var uniq = Object.keys(maper).length - 1;
        if (mx > uniq) {
            mx--;
            uniq++;
        }
        console.log(Math.min(mx, uniq));
    };
    while (tests--) {
        _loop_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.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n, a) {
  let res = 0;
  let equals = 0;
  let distinctive = 0;
  a.sort((a, b) => a - b);
  for (let i = 0; i < n; i++) {
    distinctive++;
    let j = i;
    while (a[j + 1] === a[i]) {
      j++;
    }
    if (j - i + 1 > equals) equals = j - i + 1;
    i = j;
  }
  if (distinctive > n / 2) {
    distinctive = Math.floor(n / 2);
  }
  res = Math.min(equals, distinctive);
  return res;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n, a);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

'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.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n, a) {
  let res = 0;
  let equals = 0;
  let distinctive = 0;
  a.sort((a, b) => a - b);
  for (let i = 0; i < n; i++) {
    distinctive++;
    let j = i;
    while (a[j + 1] === a[i]) {
      j++;
    }
    if (j - i + 1 > equals) equals = j - i + 1;
    i = j;
  }
  if (distinctive > n / 2) {
    distinctive = Math.floor(n / 2);
  }
  if (equals > n / 2) {
    equals = Math.floor(n / 2);
  }
  res = Math.min(equals, distinctive);
  return res;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n, a);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

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

    for (var j = 0; j < n; j++) {
        readline();
        const skills = readline().split(" ").map(e => parseInt(e));

        var distinctMap = {};
        for (let s of skills) {
            distinctMap[s] = (distinctMap[s] || 0) + 1;
        }
        var numberOfDistinctskill = Object.keys(distinctMap).length;

        const numberOfMaxSkills = Object.keys(distinctMap).map(skillId => {
            return {
                skillId,
                count: distinctMap[skillId]
            }
        }).sort((a,b) => b.count - a.count)[0].count;

        const maxSize = Math.floor(skills.length / 2);

        console.log(Math.min(numberOfDistinctskill, numberOfMaxSkills, maxSize))

    }

}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const n = getInt()
    const arr = getInts()

    const freq = {}
    for (let i in arr) {
      const cur = arr[i]
      if (!freq[cur]) freq[cur] = 0
      freq[cur] ++
    }

    let best = 0
    const size = Object.keys(freq).length - 1
    for (let i in freq) {
      const cur = freq[i]
      if (cur >= size) {
        best = Math.max(parseInt((cur + size) / 2), best)
      } else {
        best = Math.max(cur, best)
      }
    }

    print(best)
  }
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const n = getInt()
    const arr = getInts()

    const freq = {}
    for (let i in arr) {
      const cur = arr[i]
      if (!freq[cur]) freq[cur] = 0
      freq[cur] ++
    }

    let best = 0
    const size = Object.keys(freq).length - 1
    for (let i in freq) {
      const cur = freq[i]
      if (cur >= size) {
        best = Math.max(cur === size + 2 ? size + 1 : size, best)
      } else {
        best = Math.max(cur, best)
      }
    }

    print(best)
  }
}

var n = +readline();

for (var i = 0; i < n; i ++) {
    var x = +readline();
    var kol = [];

    var f = readline().split(' ').map(Number);
    for (var j = 0; j < f.length; j++) {
        kol[j] = kol[j] + 1 || 1;
    }

    var s = [...new Set(f)];
    var mx = 0;
    for (var z = 0; z < s.length; z ++) {
        mx = Math.max(mx, Math.min(kol[s[z]], s.length - 1));
    }

    write(mx + '\n');
}

var n = +readline();

for (var i = 0; i < n; i ++) {
    var x = +readline();
    var kol = [];

    var f = readline().split(' ').map(Number);
    for (var j = 0; j < f.length; j++) {
        kol[f[j]] = kol[f[j]] + 1 || 1;
    }

    var s = [...new Set(f)];
    var mx = 0;
    for (var z = 0; z < s.length; z ++) {
        mx = Math.max(mx, Math.min(kol[s[z]], s.length - 1));
    }

    write(mx + '\n');
}

var n = +readline();

for (var i = 0; i < n; i ++) {
    var x = +readline();
    var kol = [];

    var f = readline().split(' ').map(Number);
    var t = 0;
    for (var j = 0; j < f.length; j++) {
        kol[f[j]] = kol[f[j]] + 1 || 1;
        t = Math.max(t, kol[f[j]]);
    }

    var s = [...new Set(f)];
    write(t + '\n');
    if (s.length < t) {
        write(s.length + '\n');
    } else if (s.length == t) {
        write(s.length - 1 + '\n');
    } else {
        write(t + '\n');
    }
}


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

var m = [];
var checked = [];
for (var i = 0; i < n; i++) {
    m[i] = readline().split('').map(Number);
    checked[i] = false;
}

for (var q = 0; q < arr.length; q++) {
    if (checked[q]) continue;
    var comp = new Set();
    var toView = [q];
    checked[q] = true;
    comp.add(q);
    while (toView.length) {
        var el = toView.splice(0,1)[0];
        checked[el] = true;
        for (var i = 0; i < n; i++) {
            if (m[el][i] == 1 && !comp.has(i)) {
                toView.push(i);
                comp.add(i);
            }
        }
    }
    var sortVar = [];
    for (var item of comp.values()) sortVar.push(arr[item]);
    sortVar.sort(function(a,b) {return a-b});
    var copy = arr.slice();
    var j = 0;
    for (var i = 0; i < arr.length; i++) {
		var pos = sortVar.indexOf(arr[i]);
		if (pos >= 0) copy[i] = sortVar[j++];
    }
    arr = copy.slice();
}
write(arr.join(' '));

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], 10);
	};
	return tokens;
}

function printValues() {
	var parts = [];
	for (var i = 0; i < arguments.length; i += 2) {
		parts.push(arguments[i]+' = '+arguments[i+1]);
	}
	print(parts.join(', '));
}

function main() {
	var n = parseInt(readline(), 10),
      perm = tokenizeIntegers(readline()),
      matrix = [];
  for (var i = 0; i < n; ++i) {
    matrix.push(trim(readline()).split(''));
  }
  var used = new Array(n),
      indices;
  function explore(pos) {
    used[pos] = true;
    indices.push(pos);
    for (var i = 0; i < n; ++i) {
      if (!used[i] && matrix[pos][i] == 1) {
        explore(i);
      }
    }
  }
  function compare(a, b) {
    return a-b;
  }
  for (var i = 0; i < n; ++i) {
    if (used[i]) {
      continue;
    }
    indices = [];
    explore(i);
    var sub = [];
    for (var j = 0; j < n; ++j) {
      sub.push(perm[indices[j]]);
    }
    indices.sort(compare);
    sub.sort(compare);
    //print('indices: '+indices.join(' '));
    //print('sub: '+sub.join(' '));
    for (var j = 0; j < n; ++j) {
      perm[indices[j]] = sub[j];
    }
  }
  print(perm.join(' '));
}

main();

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

var m = [];
var checked = [];
for (var i = 0; i < n; i++) {
    m[i] = readline().split('').map(Number);
    checked[i] = false;
}

for (var q = 0; q < arr.length; q++) {
    if (checked[q]) continue;
    var comp = new Set();
    var toView = [q];
    checked[q] = true;
    comp.add(q);
    while (toView.length) {
        var el = toView.splice(0,1)[0];
        checked[el] = true;
        for (var i = 0; i < n; i++) {
            if (m[el][i] == 1 && !comp.has(i)) {
                toView.push(i);
                comp.add(i);
            }
        }
    }
    var sortVar = [];
    for (var item of comp.values()) sortVar.push(arr[item]);
    sortVar.sort();
    var copy = arr.slice();
    var j = 0;
    for (var i = 0; i < arr.length; i++) {
		var pos = sortVar.indexOf(arr[i]);
		if (pos >= 0) copy[i] = sortVar[j++];
    }
    arr = copy.slice();
}
write(arr.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));

const MOD = 1e9 + 7;

function expmod( base, exp, mod ){
	if (exp == 0) return 1;
	if (exp % 2 == 0){
		return Math.pow( expmod( base, (exp / 2), mod), 2) % mod;
	}
	else {
		return (base * expmod( base, (exp - 1), mod)) % mod;
	}
}

function expmod2(b, e, m) {
	let ans = 1;
	for (let i = 0; i < e; i++)
		ans = (ans * b) % m;
	return ans;
}

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let a = [];
		a[0] = rna();
		a[1] = rna();

		const mp = new Map();
		for (let i = 0; i < n; i++)
			mp.set(a[0][i], a[1][i]);

		let cnt = 0;
		for (const elm of mp.keys()) {
			let x = elm;
			while (mp.has(x)) {
				let nxt = mp.get(x);
				mp.delete(x);
				x = nxt;
				if (x == elm) {
					cnt++;
					break;
				}
			}
		}

		ans = expmod2(2, cnt, MOD);
		console.log(ans);
	}
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
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 ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
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) => JSON.stringify(a) == JSON.stringify(b);
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 = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };
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; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 06/13/21 noon
 * https://codeforces.com/contest/1534/problem/C
 */
const MOD = 1e9 + 7;
const solve = (n, a, b) => {
    let pos = Array(n).fill(0);
    let visit = Array(n).fill(0);
    for (let i = 0; i < n; i++) pos[a[i] - 1] = b[i] - 1;
    // pr(pos);
    let res = 1;
    for (let i = 0; i < n; i++) {
        if (visit[i]) continue;
        visit[i] = 1;
        for (let t = pos[i]; t != i; t = pos[t]) visit[t] = 1; // find process
        res = res * 2 % MOD;
    }
    pr(res);
};

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], input[i + 2]);
            i += 3;
        }
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
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 ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
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) => JSON.stringify(a) == JSON.stringify(b);
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 = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };
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; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 06/13/21 noon
 * https://codeforces.com/contest/1534/problem/C
 */
const MOD = 1e9 + 7;
const solve = (n, a, b) => {
    let ia = Array(n).fill(0);
    let ib = Array(n).fill(0);
    for (let i = 0; i < n; i++) ia[a[i] - 1] = i;
    for (let i = 0; i < n; i++) ib[b[i] - 1] = i;
    // pr(ia, ib);
    let ds = new DJSet(n);
    // pr(ds.getParent())
    for (let i = 0; i < n; i++) ds.union(ia[i], ib[i]);
    // pr(ds.getParent())
    let res = 1;
    let cnt = ds.count();
    for (let i = 0; i < cnt; i++) {
        res = res * 2 % MOD;
    }
    pr(res);
};

function DJSet(n) {
    let parent = Array(n).fill(-1);
    return { find, union, equiv, count, getParent }
    function find(x) {
        return parent[x] < 0 ? x : parent[x] = find(parent[x]);
    }
    function equiv(x, y) {
        return find(x) == find(y);
    }
    function union(x, y) {
        x = find(x);
        y = find(y);
        if (x != y) {
            if (parent[x] < parent[y]) [x, y] = [y, x];
            parent[x] += parent[y];
            parent[y] = x;
        }
        return x == y;
    }
    function count() {
        let cnt = 0;
        for (const u of parent) {
            if (u < 0) cnt++;
        }
        return cnt;
    }
    function getParent() {
        return parent;
    }
}

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], input[i + 2]);
            i += 3;
        }
    });
};

main()

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => ((await getLineGen.next()).value);
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for (let sc = 0; sc < nsc; sc++) {
        const n = parseInt(await getLine());
        const a = (await getLine()).split(' ').map(num => parseInt(num));
        const b = (await getLine()).split(' ').map(num => parseInt(num));
        let ncycles = 0;
        const pos = new Array(n);
        for(let i = 0; i < n; i++) {
            pos[a[i]] = i;
        }
        const was = new Array(n);
        for(let i = 0; i < n; i++) {
            if (!was[i]) {
                ncycles++;
                let curi = i;
                while (!was[curi]) {
                    was[curi] = true;
                    curi = pos[b[curi]];
                }
            }
        }
        let res = 1;
        const MOD = 1000000000 + 7;
        for(let i = 1; i<=ncycles; i++) {
            res = (res * 2) % MOD;
        }
        console.log(res);
    }
}

solve();

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

let MOD = 1e9 + 7;
let MN = 4e5 + 1;

let adj = Array(MN);
let gone = Array(MN).fill(false);

function dfs (loc) {
	gone[loc] = true;
	for (const v of adj[loc]) {
		if (!gone[v])
			dfs(v);
	}
}

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let a =[];
		a[0] = rna();
		a[1] = rna();

		for (let i = 0; i < n; i++) {
			adj[a[0][i]] = [a[1][i]];
			gone[i] = false;
		}

		let ans = 1;
		for (let i = 1; i <= n; i++) {
			if (!gone[i]) {
				dfs(i);
				ans = ans * 2 % MOD;
			}
		}

		console.log(ans);
	}
}

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

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

const MOD = 1e9 + 7;

function modpow(b, e) {
	if (e == 1) return b;
	if (e == 0) return 1;
	p = modpow(b, Math.floor(e / 2), MOD);
	q = modpow(b, e - 2 * Math.floor(e / 2), MOD);
	return p * p % MOD * q % MOD;
}

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let a = [];
		a[0] = rna();
		a[1] = rna();

		const mp = new Map();
		for (let i = 0; i < n; i++)
			mp.set(a[0][i], a[1][i]);

		let cnt = 0;
		for (const elm of mp.keys()) {
			let x = elm;
			while (mp.has(x)) {
				let nxt = mp.get(x);
				mp.delete(x);
				x = nxt;
				if (x == elm) {
					cnt++;
					break;
				}
			}
		}

		ans = modpow(2, cnt);
		console.log(ans);
	}
}

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

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

const MOD = 1e9 + 7;

function expmod( base, exp, mod ){
	if (exp == 0) return 1;
	if (exp % 2 == 0){
		return Math.pow( expmod( base, (exp / 2), mod), 2) % mod;
	}
	else {
		return (base * expmod( base, (exp - 1), mod)) % mod;
	}
}

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let a = [];
		a[0] = rna();
		a[1] = rna();

		const mp = new Map();
		for (let i = 0; i < n; i++)
			mp.set(a[0][i], a[1][i]);

		let cnt = 0;
		for (const elm of mp.keys()) {
			let x = elm;
			while (mp.has(x)) {
				let nxt = mp.get(x);
				mp.delete(x);
				x = nxt;
				if (x == elm) {
					cnt++;
					break;
				}
			}
		}

		ans = expmod(2, cnt, MOD);
		console.log(ans);
	}
}

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

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

const MOD = 1e9 + 7;

function expmod( base, exp, mod ){
	if (exp == 0) return 1;
	if (exp % 2 == 0){
		return Math.pow( expmod( base, (exp / 2), mod), 2) % mod;
	}
	else {
		return (base * expmod( base, (exp - 1), mod)) % mod;
	}
}

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let a = [];
		a[0] = rna();
		a[1] = rna();

		let cnt = 0;
		let mp = new Map();
		for (let i = 0; i < n; i++)
			mp.set(a[0][i], a[1][i]);

		for (const elm of mp.keys()) {
			let x = elm;
			while (mp.has(x)) {
				let nxt = mp.get(x);
				mp.delete(x);
				x = nxt;
				if (x == elm) {
					cnt++;
					break;
				}
			}
		}

		ans = expmod(2, cnt, MOD);
		console.log(ans);
	}
}

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

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

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let a = [];
		a[0] = rna();
		a[1] = rna();

		let cnt = 0;
		let mp = new Map();
		for (let i = 0; i < n; i++)
			mp.set(a[0][i], a[1][i]);

		for (let i = 0; i < n; i++) {
			let x = mp.get(a[0][i]);
			let first = x;
			while (mp.has(x)) {
				let y = mp.get(x);
				mp.delete(x);
				x = y;
				if (x == first) {
					cnt++; break;
				}
			}
		}

		ans = Math.pow(2, cnt);
		console.log(ans);
	}
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
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 ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
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) => JSON.stringify(a) == JSON.stringify(b);
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 = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };
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 solve = (n, a, b) => {
    // pr(n, a, b)
    let res = 0;
    for (let x = n - 1, t = 1; x >= 1 && x > t; x--, t += 3) {
        // pr(res, x, t)
        res += x - t;
    }
    pr(res);
};

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], input[i + 2]);
            i += 3;
        }
    });
};

main()


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

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

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

		let ans = true;
		for (let i = 0; ans && i < n; i++) {
			let dvsbl = true;
			for (let k = 2; dvsbl && k <= i + 2 ; k++) {
				dvsbl = dvsbl && a[i] % k == 0;
			}
			ans = !dvsbl;
		}

		console.log(ans ? '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();

		let ans = true;
		for (let i = 0; ans && i < Math.min(n, 22); i++) {
			let found = false;
			for (let k = 2; !found && k <= i + 2 ; k++) {
				found = a[i] % k;
			}
			ans = found;
		}

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

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

const diVisibleConfusion = (arr, n)=>{
    let doesExsit = false;

    for(let i = 0; i<n; ++i){
        let isNotDivisible = false;
        if(i < 22){
            for(let j = 2; j <= i + 2; j++){
                if(arr[i] % j != 0){
                    isNotDivisible = true;
                    break;
                }
            }
        }
        else{
            for(let j = 2; j <= 22; j++){
                if(arr[i] % j != 0){
                    isNotDivisible = true;
                    break;
                }
            }

        }
        if(!isNotDivisible){
            doesExsit = true;
            break;
        }
    }
    return doesExsit;
}
function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline())
        const arr = readline().split(' ').map(el=>parseInt(el));
        if(diVisibleConfusion(arr, n)){
            console.log("NO");
        }
        else{
            console.log("YES");
        }
    }
}

const readline = require('readline')

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

function solve(n, arr) {
    // let ff = false
    for (let i = 0; i < n; i++) {
        let f = false
        for (let j = 2; j <= i + 1 + 1; j++) {
            if (arr[i] % j) {
                f = true
                break
            }
        }
        if (!f) {
            return 'NO'
            // ff = true
            // break
        }
    }
    // if (!ff) {}
    return 'YES'
}

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

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

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

		ans = a[0]&1 ? 'YES' : 'NO'
	console.log(ans);
	}
}