This problem is a simplified version of D2, but it has significant differences, so read the whole statement.Polycarp has an array of $$$n$$$ ($$$n$$$ is even) integers $$$a_1, a_2, \dots, a_n$$$. Polycarp conceived of a positive integer $$$k$$$. After that, Polycarp began performing the following operations on the array: take an index $$$i$$$ ($$$1 \le i \le n$$$) and reduce the number $$$a_i$$$ by $$$k$$$.After Polycarp performed some (possibly zero) number of such operations, it turned out that all numbers in the array became the same. Find the maximum $$$k$$$ at which such a situation is possible, or print $$$-1$$$ if such a number can be arbitrarily large.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains an even integer $$$n$$$ ($$$4 \le n \le 40$$$) ($$$n$$$ is even). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$$$ ($$$-10^6 \le a_i \le 10^6$$$). It is guaranteed that the sum of all $$$n$$$ specified in the given test cases does not exceed $$$100$$$.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 1$$$) — the maximum possible number that Polycarp used in operations on the array, or $$$-1$$$, if such a number can be arbitrarily large.

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


You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints:  The first team should consist of students with distinct skills (i.e. all skills in the first team are unique).  The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given):  $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same;  $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills;  $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills;  $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams;  $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.

NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.

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

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

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

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


User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≤ k ≤ n) where a1 = b1, a2 = b2, ..., ak - 1 = bk - 1 and ak < bk all holds.As known, permutation p is so sensitive that it could be only modified by swapping two distinct elements. But swapping two elements is harder than you think. Given an n × n binary matrix A, user ainta can swap the values of pi and pj (1 ≤ i, j ≤ n, i ≠ j) if and only if Ai, j = 1.Given the permutation p and the matrix A, user ainta wants to know the prettiest permutation that he can obtain.

The first line contains an integer n (1 ≤ n ≤ 300) — the size of the permutation p. The second line contains n space-separated integers p1, p2, ..., pn — the permutation p that user ainta has. Each integer between 1 and n occurs exactly once in the given permutation. Next n lines describe the matrix A. The i-th line contains n characters '0' or '1' and describes the i-th row of A. The j-th character of the i-th line Ai, j is the element on the intersection of the i-th row and the j-th column of A. It is guaranteed that, for all integers i, j where 1 ≤ i < j ≤ n, Ai, j = Aj, i holds. Also, for all integers i where 1 ≤ i ≤ n, Ai, i = 0 holds.

In the first and only line, print n space-separated integers, describing the prettiest permutation that can be obtained.

NoteIn the first sample, the swap needed to obtain the prettiest permutation is: (p1, p7).In the second sample, the swaps needed to obtain the prettiest permutation is (p1, p3), (p4, p5), (p3, p4).   A permutation p is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. The i-th element of the permutation p is denoted as pi. The size of the permutation p is denoted as n.

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

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


Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.

The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.

Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a.

4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a

n = Number(readline());
text = [];
replacment = [];
while (n--) {
    text.push(readline().toLowerCase());
}

var main = readline();
var char = readline();
var modify = [];

mainlow = main.toLowerCase();

var tmp = main;
for (var i = 0; i < text.length; i++) {
    k = main.length;
    while (k > 0) {
        var posLast = mainlow.substr(0, k).lastIndexOf(text[i]);
        if (posLast >= 0) {
            var j = 0;
            while (j < text[i].length) {
                modify[posLast + j++] = 1;
            }
            k = posLast + text[i].length - 1;
        } else k = 0;
    }
}

main = main.split('');
for (var i = 0; i < main.length; i++) {
    func = (main[i].toLowerCase() === main[i]) ? 'toLowerCase' : 'toUpperCase';
    if (modify[i] && main[i].toLowerCase() !== char) main[i] = char[func]();
    else if (modify[i] && main[i].toLowerCase() === char && char !== 'a') main[i] = ('a')[func]();
    else if (modify[i] && main[i].toLowerCase() === char && char === 'a') main[i] = ('b')[func]();
}
main = main.join('');

print(main);


When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a $$$2 \times n$$$ grid where each row is a permutation of the numbers $$$1,2,3,\ldots,n$$$.The goal of Little Alawn's puzzle is to make sure no numbers on the same column or row are the same (we'll call this state of the puzzle as solved), and to achieve this he is able to swap the numbers in any column. However, after solving the puzzle many times, Little Alawn got bored and began wondering about the number of possible solved configurations of the puzzle he could achieve from an initial solved configuration only by swapping numbers in a column.Unfortunately, Little Alawn got stuck while trying to solve this harder problem, so he was wondering if you could help him with it. Find the answer modulo $$$10^9+7$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 4 \cdot 10^5$$$). The next two lines of each test case describe the initial state of the puzzle grid. Each line will be a permutation of the numbers $$$1,2,3,\ldots,n$$$ and the numbers in each column and row will be pairwise distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4 \cdot 10^5$$$.

For each test case output a single integer, the number of possible solved configurations of the puzzle Little Alawn can achieve from an initial solved configuration only by swapping numbers in a column. As the answer can be very large, please output it modulo $$$10^9+7$$$. The answer for each test case should be on a separate line.

NoteThe two possible puzzle configurations for example $$$1$$$ are:  $$$[1,4,2,3]$$$ in the first row and $$$[3,2,1,4]$$$ in the second;  $$$[3,2,1,4]$$$ in the first row and $$$[1,4,2,3]$$$ in the second.

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


Ela likes Chess a lot. During breaks, she usually challenges her co-worker in DTL to some chess games. She's not an expert at classic chess, but she's very interested in Chess variants, where she has to adapt to new rules and test her tactical mindset to win the game.The problem, which involves a non-standard chess pieces type that is described below, reads: given $$$3$$$ white crickets on a $$$n \cdot n$$$ board, arranged in an "L" shape next to each other, there are no other pieces on the board. Ela wants to know with a finite number of moves, can she put any white cricket on the square on row $$$x$$$, column $$$y$$$?An "L"-shape piece arrangement can only be one of the below:    For simplicity, we describe the rules for crickets on the board where only three white crickets are. It can move horizontally, vertically, or diagonally, but only to a square in some direction that is immediately after another cricket piece (so that it must jump over it). If the square immediately behind the piece is unoccupied, the cricket will occupy the square. Otherwise (when the square is occupied by another cricket, or does not exist), the cricket isn't allowed to make such a move.See an example of valid crickets' moves on the pictures in the Note section.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains $$$n$$$ ($$$4 \le n \le 10^5$$$) — denotes the size of the chessboard. The second line of each test case contains 6 numbers: $$$r_1$$$, $$$c_1$$$, $$$r_2$$$, $$$c_2$$$, $$$r_3$$$, $$$c_3$$$ ($$$1 \le r_1, c_1, r_2, c_2, r_3, c_3 \le n$$$) — coordinates of the crickets. The input ensures that the three crickets are arranged in an "L" shape that the legend stated. The third line of each test case contains 2 numbers: $$$x$$$, $$$y$$$ ($$$1 \le x, y \le n$$$) — coordinates of the target square.

For each test case, print "YES" or "NO" to denotes whether Ela can put a cricket on the target square.

NoteHere's the solution for the first test case. The red square denotes where the crickets need to reach. Note that in chess horizontals are counted from bottom to top, as well as on this picture.


YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).

NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.

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

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

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

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