You are given an array $$$a$$$ of $$$2n$$$ distinct integers. You want to arrange the elements of the array in a circle such that no element is equal to the the arithmetic mean of its $$$2$$$ neighbours.More formally, find an array $$$b$$$, such that: $$$b$$$ is a permutation of $$$a$$$.For every $$$i$$$ from $$$1$$$ to $$$2n$$$, $$$b_i \neq \frac{b_{i-1}+b_{i+1}}{2}$$$, where $$$b_0 = b_{2n}$$$ and $$$b_{2n+1} = b_1$$$. It can be proved that under the constraints of this problem, such array $$$b$$$ always exists.

The first line of input contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of testcases. The description of testcases follows. The first line of each testcase contains a single integer $$$n$$$ $$$(1 \leq n \leq 25)$$$. The second line of each testcase contains $$$2n$$$ integers $$$a_1, a_2, \ldots, a_{2n}$$$ $$$(1 \leq a_i \leq 10^9)$$$ — elements of the array. Note that there is no limit to the sum of $$$n$$$ over all testcases.

For each testcase, you should output $$$2n$$$ integers, $$$b_1, b_2, \ldots b_{2n}$$$, for which the conditions from the statement are satisfied.

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

/**
 * 05/28/21 morning
 * https://codeforces.com/contest/1526/problem/A
 */

const solve = (n, a) => {
    stin(a);
    for (let i = 1; i + 1 < n; i += 2) {
        swap(a, i, i + 1);
    }
    // pr(test(a));
    pr(a.join(" "))
};

const test = (a) => {
    let n = a.length;
    for (let i = 1; i + 1 < n; i++) {
        if (a[i - 1] + a[i + 1] >> 1 == a[i]) {
            pr(a[i - 1], a[i + 1], a[i - 1] + a[i + 1] >> 1, a[i])
            return false;
        }
    }
    return true;
}

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(2 * input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i] * 2;
        }else{
            var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
            var start = 0;
            var end = e - 1;
            var ans = '';
            while(start < end){
                ans += k[start] + ' ';
                start++;
                if(start > end){
                    break;
                }
                ans += k[end] + ' ';
                end--;
                if(start > end){
                    break;
                }
            }
            console.log(ans);
        }
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf8');

// declare global variables
var input_stdin = "";
var chunks = "";

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {

    //for local environment windows
    if(data.trim() == 'end' ){
        chunks = input_stdin.split("\n");
        start();
    }

    input_stdin += data;

});

// standard input is done and stored into an array
process.stdin.on('end', function () {
//process.on('SIGINT', function(){
    chunks = input_stdin.split("\n");
    main();
});

function main(){
   var s=1;
   var t=parseInt(chunks[0]);
   var result=[];
   while(t--){
       var n=parseInt(chunks[s++]);
       var arr=chunks[s++].split(" ").map(Number);
       arr.sort((a,b)=>b-a);
       var f=0;
       var l=2*n-1;
       var ans="";
       for(var i=0;i<n;i++){
           ans+=arr[f]+" "+arr[l]+" ";
           f++;
           l--;
       }
        result.push(ans);

   }
    console.log(result.join("\n"));
}

//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 size = 2 * N;
		var list = nextIntArray(size);
		list .sort(function(a,b){
			return a - b;
		});
		var output = [];
		for(var i = 0; i < N; i++){
			output.push(list[i]);
			output.push(list[i + N]);
		}

		for(var i = 0; i < size; i++){
			var L = output[(i - 1 + size) % size];
			var R = output[(i + 1) % size];
			if((L + R) / 2 == output[i]){
				myerr(i + ":ng");
			}
		}
		myout(myconv(output, 8));
	}
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    var ans=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort(function(a, b){return a - b});
    for(var i=0;i<n;i++){
        ans.push(arr2[i]);
        var j=parseInt(i);
        var k=parseInt(n);
        var s=j+k;
        //write(s);
        ans.push(arr2[s]);
    }
    print(ans.join(" "));
}

var t = +readline();
while (t--) {
  var n = parseInt(readline());
  var arr = readline()
    .split(" ")
    .map((val) => {
      return parseInt(val);
    });
  arr.sort((a, b) => {
    return a - b;
  });
  var ans = [];
  for (var i = 0; i < n; i++) {
    ans.push(arr[i]);
    ans.push(arr[2*n-1-i]);
  }
  print(ans.join(" "));
}

var t = +readline();
while (t--) {
  var n = parseInt(readline());
  var arr = readline()
    .split(" ")
    .map((val) => {
      return parseInt(val);
    });
  arr.sort((a, b) => {
    return a - b;
  });
  var ans = [];
  var end = 2 * n - 1;
  for (var i = 0; i < n; i++) {
    ans.push(arr[i]);
    ans.push(arr[end]);
    end--;
  }
  print(ans.join(" "));
}

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

/**
 * 05/28/21 morning
 * https://codeforces.com/contest/1526/problem/A
 */

const solve = (n, a) => {
    for (let i = 1; i + 1 < n; i++) {
        if (a[i - 1] + a[i + 1] >> 1 == a[i]) {
            swap(a, i - 1, i);
        }
    }
    // pr(test(a));
    pr(a.join(" "))
};

const test = (a) => {
    let n = a.length;
    for (let i = 1; i + 1 < n; i++) {
        if (a[i - 1] + a[i + 1] >> 1 == a[i]) {
            pr(a[i - 1], a[i + 1], a[i - 1] + a[i + 1] >> 1, a[i])
            return false;
        }
    }
    return true;
}

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(2 * input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

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

/**
 * 05/28/21 morning
 * https://codeforces.com/contest/1526/problem/A
 */
const solve = (n, a) => {
    let res = [];
    let tot = n / 2;
    while (tot--) {
        res.push(a.shift());
        res.push(a.pop());
    }
    // pr(res)
    // pr(test(res));
    pr(res.join(" "))
};

const test = (a) => {
    let n = a.length;
    for (let i = 1; i + 1 < n; i++) {
        if (a[i - 1] + a[i + 1] >> 1 == a[i]) {
            pr(a[i - 1], a[i + 1], a[i - 1] + a[i + 1] >> 1, a[i])
            return false;
        }
    }
    return true;
}

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(2 * input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

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

/**
 * 05/28/21 morning
 * https://codeforces.com/contest/1526/problem/A
 */
const solve = (n, a) => {
    // pr(n, a);
    for (let i = 2; i < n - 1; i++) {
        swap(a, i - 1, i);
    }
    // pr(a)
    pr(a.join(" "))
};

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(2 * input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    var ans=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        ans.push(arr2[i]);
        var j=parseInt(i);
        var k=parseInt(n);
        var s=j+k;
        //write(s);
        ans.push(arr2[s]);
    }
    print(ans.join(" "));
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    var ans=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        ans.push(arr2[i]);
        var j=parseInt(i);
        var k=parseInt(n);
        var s=j+k;
        ans.push(arr2[s]);
    }
    print(ans.join(" "));
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    var ans=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        ans.push(arr2[i]);
        ans.push(arr2[i+n]);
    }
    print(ans.join(" "));
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    var m=2*n-1;
    for(var i=0;i<n;i++){
        write(arr2[i]);
        write(" ");
        write(arr2[m]);
        m--;
        write(" ");
    }
    print("\n");
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        write(arr2[i]);
        write(" ");
        var m=n+i;
        write(arr2[m]);
        write(" ");
    }
    print("\n");
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        write(arr2[i]);
        write(" ");
        var m=n-i-1;
        write(arr2[m]);
        write(" ");
    }
    print("\n");
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        var m=(2*n)-i-1;
        write(arr2[m]);
        write(" ");
        write(arr2[i]);
        write(" ");
    }
    print("\n");
}

var t= readline(parseInt());
while(t--){
    var n=readline(parseInt());
    var arr1=readline().split(' ');
    var arr2=[];
    for(var i=0;i<2*n;i++){
        arr2.push(arr1[i]);
    }
    arr2.sort();
    for(var i=0;i<n;i++){
        write(arr2[i]);
        write(" ");
        var m=(2*n)-i-1;
        write(arr2[m]);
        write(" ");
    }
    print("\n");
}

var t = parseInt(readline());
while(t--){
    var n = parseInt(readline());
    var arr = readline().split();
    arr.sort(function(a, b){return a - b});
    var ans=[];
    for(var i=0;i<n;i++){
        ans.push(arr[i]);
        ans.push(arr[2*n-1-i]);
    }
    print(ans.join(" "));
}

var t = parseInt(readline());
while(t--){
    var n = parseInt(readline());
    var arr = readline().split();
    arr.sort(function(a, b){return a - b});
    var ans=[];
    for(i=0;i<n;i++){
        ans.push(arr[i]);
        ans.push(arr[2*n-1-i]);
    }
    print(ans.join(" "));
}

var t = parseInt(readline());
while(t--){
    var n = parseInt(readline());
    var arr = readline().split();
    arr.sort(function(a, b){return a - b});
    var ans=[];
    for(i=0;i<n;i++){
        ans.push(arr[i],arr[2*n-1-i]);
    }
    print(ans.join(" "));
}

var t = +readline();
while (t--) {
  var n = parseInt(readline());
  var arr = readline()
    .split(" ")
    .map((val) => {
      return parseInt(val);
    });
  arr.sort((a, b) => {
    return a - b;
  });
  var ans = [];
  var end = 2 * n - 1;
  for (var i = 0; i < n; i++) {
    ans.push(arr[i]);
    ans.push(arr[end]);
    end--;
  }
  print(ans);
}


You have three piles of candies: red, green and blue candies:  the first pile contains only red candies and there are $$$r$$$ candies in it,  the second pile contains only green candies and there are $$$g$$$ candies in it,  the third pile contains only blue candies and there are $$$b$$$ candies in it. Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.

The first line contains integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a separate line of the input. It contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^8$$$) — the number of red, green and blue candies, respectively.

Print $$$t$$$ integers: the $$$i$$$-th printed integer is the answer on the $$$i$$$-th test case in the input.

NoteIn the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

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

  const t = parseInt(arr.shift())

  for(let j = 0; j < t; j++) {
    const a = arr[j].split(' ').map(a => parseInt(a)).sort((a, b) => b - a)

    let count = 0

    if(a[0] >= (a[1] + a[2])) {
      count = a[1] + a[2]
    }
    else {
      let diff = a[0] - a[1]
      count += diff
      a[0] -= diff
      a[2] -= diff

      diff = a[0] - a[2]
      count += diff
      a[0] -= diff
      a[1] -= diff
    }

    if(a[0] == a[1] && a[1] == a[2]) {
      if(a[0] % 2 == 0) count += (a[0] / 2) * 3
      else count += ((a[0] - 1) / 2) * 3 + 1
    }

    console.log(count)

  }
})

"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let input_stdin = '';

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

process.stdin.on('end', function () {
    let chunks = '';
    chunks = input_stdin.split('\n');
    start(chunks);
});

function start(input) {
    let q = +input.shift();
    while(q--) {
        const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);

        if(a + b <= c) {
            console.log(a + b);
        } else {
            console.log(c + Math.floor((a - c + b)/2));
        }
    }
}

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

  main(lines);
});

function main(lines) {
  const N = Number(lines.shift());
  const arr = lines.map(row => row.split(' ').map(Number));
  let diff;

  arr.forEach(row => {
    row.sort((a, b) => a - b);

    diff = Math.min(row[0], row[2] - row[1]);
    row[0] -= diff;
    row[1] += diff;

    console.log(
      Math.min(
        row[1] + Math.ceil(row[0] / 2),
        row[2] + Math.floor(row[0] / 2)
      )
    );
  });
}

var n = Number(readline());
for(var i=0;i<n;i++){
 var a = readline().split(" ").map( l => Number(l) ).sort(function(a,b){return a-b;});
      if(a[0]<=a[2]-a[1]) print(a[0]+a[1]);
 else print(Math.floor((a[0]+a[1]+a[2])/2));
}

"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let input_stdin = '';

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

process.stdin.on('end', function () {
    let chunks = '';
    chunks = input_stdin.split('\n');
    start(chunks);
});

function start(input) {
    let q = +input.shift();
    while(q--) {
        const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);

        if(a + b <= c) {
            console.log(a + b);
        } else {
            console.log(c - Math.floor((a - c + b)/2));
        }
    }
}

"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let input_stdin = '';

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

process.stdin.on('end', function () {
    let chunks = '';
    chunks = input_stdin.split('\n');
    start(chunks);
});

function start(input) {
    let q = +input.shift();
    console.log(input);
    while(q--) {
        const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);

        if(a + b <= c) {
            console.log(a + b);
        } else {
            console.log(c + Math.floor((a - c + b)/2));
        }
    }
}

"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let input_stdin = '';

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

process.stdin.on('end', function () {
    let chunks = '';
    chunks = input_stdin.split('\n');
    start(chunks);
});

function start(input) {
    let q = +input.shift();
    console.log(input);
    while(q--) {
        const [a,b,c] = input.shift().split(' ').map(Number).sort((x, y) => x - y);

        if(a + b <= c) {
            console.log(a + b);
        } else {
            console.log(c - Math.floor((a - c + b)/2));
        }
    }
}

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

function main() {
  const {EOL} = require('os');
  const lines = buffer.split(EOL);

  const N = Number(lines.shift());
  const arr = lines.map(row => row.split(' ').map(Number));

  arr.forEach(row => {
    row.sort((a, b) => a - b);
    console.log(row[0] + Math.min(row[1], row[2] - row[0]));
  });
}

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

function main() {
  const {EOL} = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  const N = Number(lines.shift());
  const arr = lines.map(row => row.split(' ').map(Number));

  arr.forEach(row => {
    row.sort((a, b) => a - b);
    console.log(row[0] + Math.min(row[1], row[2] - row[0]));
  });
}

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

  return lines;
});

function main(lines) {
  const N = Number(lines.shift());
  const arr = lines.map(row => row.split(' ').map(Number));
  let diff;

  arr.forEach(row => {
    row.sort((a, b) => a - b);

    diff = Math.min(row[0], row[2] - row[1]);
    row[0] -= diff;
    row[1] += diff;

    console.log(
      Math.min(
        row[1] + Math.ceil(row[0] / 2),
        row[2] + Math.floor(row[0] / 2)
      )
    );
  });
}

var n = Number(readline());
for(var i=0;i<n;i++){
 var a = readline().split(" ").map( l => Number(l) ).sort();
      if(a[0]<=a[2]-a[1]) print(a[0]+a[1]);
 else print(Math.floor((a[0]+a[1]+a[2])/2));
}

var n = Number(readline());
for(var i=0;i<n;i++){
 var a = readline().split(" ").map( l => Number(l) ).sort();
 if(a[0]<a[2]-a[1]) print(a[0]+a[1]);
 else print(Math.floor((a[0]+a[1]+a[2])/2));
}


It is given a positive integer $$$n$$$. In $$$1$$$ move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are automatically removed.E.g. if one removes from the number $$$32925$$$ the $$$3$$$-rd digit, the resulting number will be $$$3225$$$. If one removes from the number $$$20099050$$$ the first digit, the resulting number will be $$$99050$$$ (the $$$2$$$ zeroes going next to the first digit are automatically removed).What is the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive? It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$n$$$ ($$$25 \le n \le 10^{18}$$$). It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 0$$$) — the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive.

NoteIn the first test case, it is already given a number divisible by $$$25$$$.In the second test case, we can remove the digits $$$1$$$, $$$3$$$, and $$$4$$$ to get the number $$$75$$$.In the third test case, it's enough to remove the last digit to get the number $$$325$$$.In the fourth test case, we can remove the three last digits to get the number $$$50$$$.In the fifth test case, it's enough to remove the digits $$$4$$$ and $$$7$$$.

'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 solve(s,x)
{
    let n=s.length
    let j=1
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]===x[j])
        {
            j--
            if(j===-1)
                return Number(n-i-2)
        }
    }
    return Number(30)
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        let s=readline()
        let ans=Number(30)
        ans=Math.min(ans,Number(solve(s,"25")))
        ans=Math.min(ans,Number(solve(s,"75")))
        ans=Math.min(ans,Number(solve(s,"00")))
        ans=Math.min(ans,Number(solve(s,"50")))
        console.log(ans)
    }
}

var thisisveryeasyhahahah = function(s, t){
    s = s.split('').map(Number);
    t = t.split('').map(Number);
    var cnt = 0;
    while(s.length > 0 && t.length > 0){
        if(s[s.length - 1] == t[t.length - 1]){
            t.pop();
        }else{
            cnt++;
        }
        s.pop();
    }
    return cnt;
};
let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t; i++){
        var s = lines[i];
        console.log(Math.min(thisisveryeasyhahahah(s, '00'), Math.min(thisisveryeasyhahahah(s, '25'), Math.min(thisisveryeasyhahahah(s, '50'), thisisveryeasyhahahah(s, '75')))));
    }
});

var tocount = function(s, t){
    var count = 0;
    s = s.split('').map(Number);
    t = t.split('').map(Number);
    var l = s.length;
    while(s.length > 0 && t.length > 0){
        if(s[s.length - 1] == t[t.length - 1]){
            t.pop();
        }else{
            count++;
        }
        s.pop();
    }
    if(t.length === 0){
        return count;
    }
    return l;
};
let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var s = lines[i];
        console.log(Math.min(tocount(s, '00'), Math.min(tocount(s, '25'), Math.min(tocount(s, '50'), tocount(s,'75')))));
    }
});

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

		n = n.split('').reverse().join('');

		function pos (x, i = -1) {
			while (++i < n.length) {
				if (n[i] == x)
					break;
			}
			return i;
		}

		const ans1 = Math.min(pos('2', pos('5')), pos('7', pos('5')));
		const ans2 = Math.min(pos('0', pos('0')), pos('5', pos('0')));

		const ans = Math.min(ans1, ans2) - 1;

		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 INF = 20;

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

		n = n.split('').reverse().join('');

		let ans1, ans2;
		for (let i = 0; i < n.length; i++) {
			if (n[i] == '0' && ans1 === undefined) {
				ans1 = INF;
				for (let j = i+1; j < n.length; j++) {
					if (n[j] == '0' || n[j] == '5') {
						ans1 = j-1;
						break;
					}
				}
			}

			if (n[i] == '5' && ans2 == undefined) {
				ans2 = INF;
				for (let j = i+1; j < n.length; j++) {
					if (n[j] == '2' || n[j] == '7') {
						ans2 = j-1;
						break;
					}
				}
			}
		}

		ans1 = ans1 == undefined ? INF : ans1;
		ans2 = ans2 == undefined ? INF : ans2;

		const ans = Math.min(ans1, ans2);

		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 calcTurns(findIn, num) {
    let digitIndex = 1;
    let turns = 0;
    findIn.split('').reverse().forEach(digit => {
        if (digitIndex < 0) {
            return;
        }
        if (digit === num[digitIndex]) {
            digitIndex--;
        } else {
            turns += 1;
        }
    });
    return digitIndex === -1 ? turns : Infinity;
}

function main() {
    const n = parseInt(readline());
    for (let i = 0; i < n; i++) {
        const num = readline();
        console.log(Math.min(calcTurns(num, '00'), calcTurns(num, '25'), calcTurns(num, '50'), calcTurns(num, '75')));
    }
}

// dist/FinalCode/Common/InputOutputClass.js
var Input = function() {
  function Input2(inputData) {
    var _this = this;
    this.SettleStream = function() {
      var re = /\s+/;
      _this.inputWords = _this.inputStream.split(re);
      _this.inputWordsLength = _this.inputWords.length;
    };
    this.getLength = function() {
      return _this.inputWordsLength;
    };
    this.getEveryWord = function() {
      return _this.inputWords;
    };
    this.getNextWord = function() {
      _this.inputWordsCount++;
      if (_this.inputWordsLength < _this.inputWordsCount) {
        return "";
      }
      return _this.inputWords[_this.inputWordsCount - 1];
    };
    this.getNextString = function() {
      return _this.getNextWord();
    };
    this.getNextBigInt = function() {
      return BigInt(_this.getNextWord());
    };
    this.getNextNumber = function() {
      return Number(_this.getNextWord());
    };
    this.getNextInt = function() {
      return parseInt(_this.getNextWord(), 10);
    };
    this.getNextFloat = function() {
      return parseFloat(_this.getNextWord());
    };
    this.inputWordsCount = 0;
    this.inputStream = inputData;
  }
  Input2.prototype.SetStream = function(chunk) {
    this.inputStream += chunk;
  };
  Input2.prototype.getNextIntArray = function(elementCount) {
    var resultArray = new Array(elementCount);
    for (var idx = 0; idx < elementCount; idx++) {
      resultArray[idx] = this.getNextInt();
    }
    return resultArray;
  };
  return Input2;
}();
var InputOutputClass_default = Input;
var writeLine = function(outputElement) {
  var _internalWrite = function(_internalOutputElement) {
    process.stdout.write(_internalOutputElement);
  };
  _internalWrite(String(outputElement) + "\n");
};

// dist/main.js
var rw = new InputOutputClass_default("");
process.stdin.resume();
process.stdin.setEncoding("utf-8");
process.stdin.on("data", function(chunk) {
  rw.SetStream(chunk);
});
process.stdin.on("end", function() {
  rw.SettleStream();
  mainFunc();
});
var mainFunc = function() {
  testCases();
};
var testCases = function() {
  var test = rw.getNextInt();
  for (var i = 0; i < test; i++) {
    solveCase();
  }
};
var solveCase = function() {
  var n = rw.getNextString();
  var answer = n.length + 1e3;
  for (var i = n.length - 1; i >= 0; i--) {
    for (var j = i - 1; j >= 0; j--) {
      var a = Number(n[i]);
      var b = Number(n[j]);
      if ((b * 10 + a) % 25 === 0) {
        if (answer > n.length - j - 2) {
          answer = n.length - j - 2;
        }
      }
    }
  }
  writeLine(answer);
};

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        main()
        process.exit(0)
    }
})

function solve(num) {
    const lastN = num.lastIndexOf('0')
    const lastF = num.lastIndexOf('5')
    let tmp, arr = [];
    // 25
    if (lastF !== -1) {
        tmp = num.slice(0, lastF).lastIndexOf('2')
        if (tmp !== -1) {
            arr.push(((num.length - 1 - lastF) + (lastF - tmp - 1)))
        }
    }

    // 00
    if (lastN !== -1) {
        tmp = num.slice(0, lastN).lastIndexOf('0')
        if (tmp !== -1) {
            arr.push(((num.length - 1 - lastN) + (lastN - tmp - 1)))
        }
    }
    // 50
    if (lastN !== -1) {
        tmp = num.slice(0, lastN).lastIndexOf('5')
        if (tmp !== -1) {
            arr.push(((num.length - 1 - lastN) + (lastN - tmp - 1)))
        }
    }
    // 75
    if (lastF !== -1) {
        tmp = num.slice(0, lastF).lastIndexOf('7')
        if (tmp !== -1) {
            arr.push(((num.length - 1 - lastF) + (lastF - tmp - 1)))
        }
    }
    console.log(Math.min(...arr))
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

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 str = lines[l++].trim()
        output[i] = solve(str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(str) {
    const target = ['00', '25', '50', '75']
    let ans = str.length
    for (let i = 0; i < target.length; i++) {
        let k = 1
        for (let j = str.length - 1; j >= 0; j--) {
            // console.log(target[i][k], str[j], str)
            if (str[j] === target[i][k]) {
                if (k === 0) {
                    ans = Math.min(ans, str.length - j - 2)
                    // console.log('found', str, target[i], str.length - j - 2)
                    break
                }
                k--
            }
        }
    }
    return ans
}

var t = parseInt(readline())

  function solve() {
    var n = readline();
    var len = n.length;
    var ans = len;
    for (var i = 0; i < len; ++i) {
      for (var j = i + 1; j < len; ++j) {
        var t = parseInt(n[i] + n[j])
        if (t % 25 == 0) {
          ans = Math.min(ans, len - (i + 2));
        }
      }
    }
    return ans
  }

  while (t--) {
    print(solve());
  }

//brute force
//time complexity o(n^2)

var t = parseInt(readline())

for(var T = 1 ; T <= t; ++T){
	solve();
}

function solve(){
	var n = readline();
	var len = n.length;
	var ans = len;
	for(var i=0; i<len;++i){
		for(var j=i+1;j<len;++j){
			var t = parseInt(n[i]) * 10 + parseInt(n[j]);
			if(t%25==0){
				ans = Math.min(ans, len-(i + 2));
			}
		}
	}
	print(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 solve(s,x)
{
    let n=s.length
    let j=0
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]===x[j])
        {
            j++
            if(j===2)
                return Number(Number(n)-Number(i)-Number(2))
        }
    }
    return Number(30)
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        var s=readline()
        var ans=Number(30)
        var x=Number(solve(s,"25"))
        if(ans>x)
           ans=x;
        x=Number(solve(s,"00"))
        if(ans>x)
            ans=x;
        x=Number(solve(s,"75"))
        if(ans>x)
            ans=x;
        x=Number(solve(s,"50"))
        if(ans>x)
            ans=x;
        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 solve(s,x)
{
    let n=s.length
    let j=0
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]===x[j])
        {
            j++
            if(j===2)
                return Number(Number(n)-Number(i)-Number(2))
        }
    }
    return Number(30)
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        let s=readline()
        let ans=Number(30)
        let x=Number(solve(s,"25"))
        if(ans>x)
           ans=x;
        x=Number(solve(s,"00"))
        if(ans>x)
            ans=x;
        x=Number(solve(s,"75"))
        if(ans>x)
            ans=x;
        x=Number(solve(s,"50"))
        if(ans>x)
            ans=x;
        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 solve(s,x)
{
    let n=s.length
    let j=0
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]===x[j])
        {
            j++
            if(j===2)
                return Number(n-i-2)
        }
    }
    return Number(30)
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        let s=readline()
        let ans=Number(30)
        let x=Number(solve(s,"25"))
        if(ans>x)
           ans=x;
        x=Number(solve(s,"00"))
        if(ans>x)
            ans=x
        x=Number(solve(s,"75"))
        if(ans>x)
            ans=x
        x=Number(solve(s,"25"))
        if(ans>x)
            ans=x
        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 solve(s,x)
{
    let n=s.length
    let j=0
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]===x[j])
        {
            j++
            if(j===2)
                return Number(n-i-2)
        }
    }
    return Number(30)
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        let s=readline()
        let ans=Number(30)
        ans=Math.min(ans,Number(solve(s,"25")))
        ans=Math.min(ans,Number(solve(s,"75")))
        ans=Math.min(ans,Number(solve(s,"00")))
        ans=Math.min(ans,Number(solve(s,"50")))
        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 solve(s,x)
{
    let n=s.length
    let j=0
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]==x[j])
        {
            j++;
            if(j==2)
                return n-i-2
        }
    }
    return 30
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        let s=readline()
        let ans=30
        ans=Math.min(ans,solve(s,"25"))
        ans=Math.min(ans,solve(s,"00"))
        ans=Math.min(ans,solve(s,"75"))
        ans=Math.min(ans,solve(s,"50"))
        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 solve(s,x)
{
    let n=s.length
    let j=0
    for(let i=n-1;i>=0;i--)
    {
        if(s[i]==x[j])
        {
            j++;
            if(j==2)
                return n-i-2
        }
    }
}
function main() {
    let t=Number(readline())
    for(let i=0;i<t;i++)
    {
        let s=readline()
        let ans=solve(s,"25")
        ans=Math.min(ans,solve(s,"00"))
        ans=Math.min(ans,solve(s,"75"))
        ans=Math.min(ans,solve(s,"50"))
        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 getNumberState(arr, lastDigitVal) {
    const valueMap = {
        0: [0, 5],
        5: [2, 7]
    }
    return arr.reduce((acc, digit) => {
        const { lastDigit, isAnswerFound, turns } = acc;
        if (isAnswerFound) {
            return acc;
        }
        if (lastDigit !== null) {
            return valueMap[lastDigit].includes(digit) ? {...acc, isAnswerFound: true} : {...acc, turns: turns + 1};
        } else {
            const isSuitableLastDigit = lastDigitVal !== undefined ? digit === lastDigitVal : digit === 5 || digit === 0;
            return isSuitableLastDigit ? {...acc, lastDigit: digit } : {...acc, turns: turns + 1};
        }

    }, {lastDigit: null, isAnswerFound: false, turns: 0});
}

function calcTurns(str) {
    const arr = str.split('').reverse().map(Number);
    let state = getNumberState(arr);
    return state.isAnswerFound ? state.turns : getNumberState(arr, state.lastDigit === 0 ? 5 : 0).turns;
}

function main() {
    const n = parseInt(readline());
    for (let i = 0; i < n; i++) {
        console.log(calcTurns(readline()));
    }
}

var t = parseInt(readline())

for(var T = 1 ; T <= t; ++T){
	solve();
}

function solve(){
	var n = parseInt(readline());
	var str = String(n);
	var len = parseInt(str.length);
	var ans = len;
	for(var i=0; i<len;++i){
		for(var j=i+1;j<len;++j){
			var t = parseInt(n[i]) * 10 + parseInt(n[j]);
			if(t%25==0){
				ans = Math.min(ans, len-(i + 2));
			}
		}
	}
	print(ans);
}


Bakry got bored of solving problems related to xor, so he asked you to solve this problem for him.You are given an array $$$a$$$ of $$$n$$$ integers $$$[a_1, a_2, \ldots, a_n]$$$.Let's call a subarray $$$a_{l}, a_{l+1}, a_{l+2}, \ldots, a_r$$$ good if $$$a_l \, \& \, a_{l+1} \, \& \, a_{l+2} \, \ldots \, \& \, a_r > a_l \oplus a_{l+1} \oplus a_{l+2} \ldots \oplus a_r$$$, where $$$\oplus$$$ denotes the bitwise XOR operation and $$$\&$$$ denotes the bitwise AND operation.Find the length of the longest good subarray of $$$a$$$, or determine that no such subarray exists.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — elements of the array.

Print a single integer — the length of the longest good subarray. If there are no good subarrays, print $$$0$$$.

NoteIn the first case, the answer is $$$2$$$, as the whole array is good: $$$5 \& 6 = 4 > 5 \oplus 6 = 3$$$.In the third case, the answer is $$$4$$$, and one of the longest good subarrays is $$$[a_2, a_3, a_4, a_5]$$$: $$$1\& 3 \& 3 \&1 = 1 > 1\oplus 3 \oplus 3\oplus 1 = 0$$$.

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        console.log(solve(n, arr))
    }
// })()
})

function solve(n, arr) {
    const limit = 20

    let ans = 0
    for (let j = 0; j < limit; j++) {
        let cur = []
        const mask = ~((1 << (j + 1)) - 1)
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] & (1 << j)) {
                cur.push(arr[i] & mask)
            }

            if (!(arr[i] & (1 << j)) || i === n - 1) {
                const xor = []
                const map = {
                    0: -1
                }
                if (cur.length < ans) {
                    cur = []
                    continue
                }
                for (let k = 0; k < cur.length; k++) {
                    xor[k] = k ? xor[k - 1] ^ cur[k] : cur[k]
                    if (!(xor[k] in map)) {
                        map[xor[k]] = k
                    }
                    if (xor[k] in map) {
                        const len = k - map[xor[k]]
                        if (!(len & 1)) {
                        // console.log(xor[k], k, map[xor[k]], len)
                            ans = Math.max(ans, len)
                        }
                    }
                }
                cur = []
            }
        }
    }
    return ans
}

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        console.log(solve(n, arr))
    }
// })()
})

function solve(n, arr) {
    const limit = 25

    let ans = 0
    for (let j = 0; j < limit; j++) {
        let cur = []
        const mask = ~((1 << (j + 1)) - 1)
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] & (1 << j)) {
                cur.push(arr[i] & mask)
            }

            if (!(arr[i] & (1 << j)) || i === n - 1) {
                const xor = []
                const map = {}
                // if (cur.length) {
                //     console.log(cur, i)
                // }
                for (let k = 0; k < cur.length; k++) {
                    xor[k] = k ? xor[k - 1] ^ cur[k] : cur[k]
                    if (!(xor[k] in map)) {
                        map[xor[k]] = k
                    }
                    if (xor[k] in map) {
                        const len = k - map[xor[k]] + 1
                        if (!(len & 1)) {
                            ans = Math.max(ans, len)
                        }
                    }
                }
                cur = []
            }
        }
    }
    return ans
}


This is the easy version of the problem. The only difference between the two versions is the constraint on $$$n$$$. You can make hacks only if all versions of the problem are solved.A forest is an undirected graph without cycles (not necessarily connected).Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from $$$1$$$ to $$$n$$$, and they would like to add edges to their forests such that:   After adding edges, both of their graphs are still forests.  They add the same edges. That is, if an edge $$$(u, v)$$$ is added to Mocha's forest, then an edge $$$(u, v)$$$ is added to Diana's forest, and vice versa. Mocha and Diana want to know the maximum number of edges they can add, and which edges to add.

The first line contains three integers $$$n$$$, $$$m_1$$$ and $$$m_2$$$ ($$$1 \le n \le 1000$$$, $$$0 \le m_1, m_2 < n$$$) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest. Each of the next $$$m_1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edges in Mocha's forest. Each of the next $$$m_2$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edges in Diana's forest.

The first line contains only one integer $$$h$$$, the maximum number of edges Mocha and Diana can add (in each forest). Each of the next $$$h$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edge you add each time. If there are multiple correct answers, you can print any one of them.

NoteIn the first example, we cannot add any edge.In the second example, the initial forests are as follows.We can add an edge $$$(2, 4)$$$.

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
function createHeuristicFindSet(e) {
  const t = new Array(e + 1),
    n = new Array(e + 1)
  let i = e
  return {
    init: function (e) {
      ;(i = e), n.fill(1, i + 1, 1)
      for (let e = 1; e <= i; ++e) t[e] = e
    },
    root: r,
    merge: function (e, i) {
      const s = r(e),
        o = r(i)
      if (s === o) return s
      if (n[s] > n[o]) return (t[o] = s), (n[s] += n[o]), s
      return (t[s] = o), o
    },
  }
  function r(e) {
    return t[e] === e ? e : (t[e] = r(t[e]))
  }
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readLineAsNumber() {
    return Number(this.readLine())
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(String(e))
  }
  println(e) {
    stdout.write(String(e)), stdout.write('\n')
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(t => {
      stdin.on('data', t => e.push(t)),
        stdin.on('end', function () {
          const n = e.join('').split(os.EOL)
          t(n)
        })
    })
  }
}
async function __main__(e) {
  const t = new InputAndOutput()
  await t.init(), e(t)
}
function solve() {
  return -1
}
const MAX_N = 100010,
  findset1 = createHeuristicFindSet(MAX_N),
  findset2 = createHeuristicFindSet(MAX_N),
  pos1 = new Array(MAX_N).fill(0),
  pos2 = new Array(MAX_N).fill(0)
__main__(function (e) {
  for (let t = 1; t <= 1; ++t) {
    const [t, n, i] = e.readIntegersOfLine()
    findset1.init(t), findset2.init(t)
    for (let t = 0; t < n; ++t) {
      const [t, n] = e.readIntegersOfLine()
      findset1.merge(t, n)
    }
    for (let t = 0; t < i; ++t) {
      const [t, n] = e.readIntegersOfLine()
      findset2.merge(t, n)
    }
    e.println(t - 1 - Math.max(n, i))
    const r = Math.min(Math.floor(Math.random() * t) + 1, t)
    for (let n = 1; n <= t; ++n) {
      const t = findset1.root(n),
        i = findset1.root(r),
        s = findset2.root(n),
        o = findset2.root(r)
      t !== i &&
        s !== o &&
        (findset1.merge(t, i), findset2.merge(s, o), e.println(r + ' ' + n))
    }
    let s = 0
    for (let e = 1; e <= t; ++e) {
      const t = findset1.root(e),
        n = findset1.root(r)
      t !== n && (findset1.merge(t, n), (pos1[s++] = e))
    }
    let o = 0
    for (let e = 1; e <= t; ++e) {
      const t = findset2.root(e),
        n = findset2.root(r)
      t !== n && (findset2.merge(t, n), (pos2[o++] = e))
    }
    for (let t = 0, n = Math.min(s, o); t < n; ++t) {
      const n = pos1[t],
        i = pos2[t]
      e.println(n + ' ' + i)
    }
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
function createHeuristicFindSet(e) {
  const t = new Array(e + 1),
    n = new Array(e + 1)
  let r = e
  return {
    init: function (e) {
      ;(r = e), n.fill(1, r + 1, 1)
      for (let e = 1; e <= r; ++e) t[e] = e
    },
    root: i,
    merge: function (e, r) {
      const s = i(e),
        o = i(r)
      if (s === o) return s
      if (n[s] > n[o]) return (t[o] = s), (n[s] += n[o]), s
      return (t[s] = o), o
    },
  }
  function i(e) {
    return t[e] === e ? e : (t[e] = i(t[e]))
  }
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readLineAsNumber() {
    return Number(this.readLine())
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(String(e))
  }
  println(e) {
    stdout.write(String(e)), stdout.write('\n')
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(t => {
      stdin.on('data', t => e.push(t)),
        stdin.on('end', function () {
          const n = e.join('').split(os.EOL)
          t(n)
        })
    })
  }
}
async function __main__(e) {
  const t = new InputAndOutput()
  await t.init(), e(t)
}
function solve() {
  return -1
}
__main__(function (e) {
  const t = 100010,
    n = createHeuristicFindSet(t),
    r = createHeuristicFindSet(t)
  for (let t = 1; t <= 1; ++t) {
    const [t, i, s] = e.readIntegersOfLine()
    n.init(t), r.init(t)
    for (let t = 0; t < i; ++t) {
      const [t, r] = e.readIntegersOfLine()
      n.merge(t, r)
    }
    for (let t = 0; t < s; ++t) {
      const [t, n] = e.readIntegersOfLine()
      r.merge(t, n)
    }
    e.println(t - 1 - Math.max(i, s))
    const o = Math.min(Math.floor(Math.random() * t) + 1, t)
    for (let i = 1; i <= t; ++i) {
      const t = n.root(i),
        s = n.root(o),
        u = r.root(i),
        c = r.root(o)
      t !== s &&
        u !== c &&
        (n.merge(t, s), r.merge(u, c), e.println(o + ' ' + i))
    }
    const u = []
    for (let e = 1; e <= t; ++e) {
      const t = n.root(e),
        r = n.root(o)
      t !== r && (n.merge(t, r), u.push(e))
    }
    const c = []
    for (let e = 1; e <= t; ++e) {
      const t = r.root(e),
        n = r.root(o)
      t !== n && (r.merge(t, n), c.push(e))
    }
    for (let t = 0, n = Math.min(u.length, c.length); t < n; ++t) {
      const n = u[t],
        r = c[t]
      e.println(n + ' ' + r)
    }
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
function createHeuristicFindSet(e) {
  const t = new Array(e + 1),
    n = new Array(e + 1)
  let r = e
  return {
    init: function (e) {
      ;(r = e), n.fill(1, r + 1, 1)
      for (let e = 1; e <= r; ++e) t[e] = e
    },
    root: i,
    merge: function (e, r) {
      const o = i(e),
        s = i(r)
      if (o === s) return o
      if (n[o] > n[s]) return (t[s] = o), (n[o] += n[s]), o
      return (t[o] = s), s
    },
  }
  function i(e) {
    return t[e] === e ? e : (t[e] = i(t[e]))
  }
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readLineAsNumber() {
    return Number(this.readLine())
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(t => {
      stdin.on('data', t => e.push(t)),
        stdin.on('end', function () {
          const n = e.join('').split(os.EOL)
          t(n)
        })
    })
  }
}
async function __main__(e) {
  const t = new InputAndOutput()
  await t.init(), e(t)
}
function solve() {
  return -1
}
__main__(function (e) {
  const t = 100010,
    n = createHeuristicFindSet(t),
    r = createHeuristicFindSet(t)
  for (let t = 1; t <= 1; ++t) {
    const [t, i, o] = e.readIntegersOfLine()
    n.init(t), r.init(t)
    for (let t = 0; t < i; ++t) {
      const [t, r] = e.readIntegersOfLine()
      n.merge(t, r)
    }
    for (let t = 0; t < o; ++t) {
      const [t, n] = e.readIntegersOfLine()
      r.merge(t, n)
    }
    const s = [],
      u = Math.floor(Math.random() * t) + 1
    for (let e = 1; e <= t; ++e) {
      const t = n.root(e),
        i = n.root(u),
        o = r.root(e),
        c = r.root(u)
      t !== i && o !== c && (n.merge(t, i), r.merge(o, c), s.push([u, e]))
    }
    const c = []
    for (let e = 1; e <= t; ++e) {
      const t = n.root(e),
        r = n.root(u)
      t !== r && (n.merge(t, r), c.push(e))
    }
    const a = []
    for (let e = 1; e <= t; ++e) {
      const t = r.root(e),
        n = r.root(u)
      t !== n && (r.merge(t, n), a.push(e))
    }
    for (let e = 0, t = Math.min(c.length, a.length); e < t; ++e)
      s.push([c[e], a[e]])
    e.print(s.length + '\n')
    for (const t of s) e.print(t.join(' ') + '\n')
  }
})

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 mxN = 1005;

class dsu {
	constructor (n) {
		this.components = n;
		this.data = Array(n).fill(-1);
	}
	unite (a, b) {
		a = this.find(a);
		b = this.find(b);
		this.data[a] += this.data[b];
		this.data[b] = a;
		this.components--;
	}
	find (a) {
		return this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);
	}
	size (a) {
		return -this.data[this.find(a)];
	}
	getcomponents () {
		return this.components;
	}
}

function main () {
	const [n, m1, m2] = rna();

	const d1 = new dsu(n);
	const d2 = new dsu(n);

	for (let i = 0; i < m1; i++) {
		let [u, v] = rna();
		u--; v--;
		d1.unite(u, v);
	}

	for (let i = 0; i < m2; i++) {
		let [u, v] = rna();
		u--; v--;
		d2.unite(u, v);
	}

	let ans = [];
	for (let i = 0; i < n; i++) {
		for (let j = i + 1; j < n; j++) {
			if (d1.find(i) != d1.find(j) && d2.find(i) != d2.find(j)) {
				d1.unite(i, j);
				d2.unite(i, j);
				ans.push([i+1, j+1]);
			}
		}
	}

	console.log(ans.length);
	for (const edg of ans) {
		console.log(edg.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 mxN = 1005;

const f = Array.from(Array(2), x => []);

function getf (id, x) {
	if (x == f[id][x]) return x;
	return f[id][x] = getf(id, f[id][x]);
}

function main () {
	const [n, m1, m2] = rna();

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

	for (let i = 0; i < m1; i++) {
		let [u, v] = rna();
		u--; v--;
		u = getf(0, u);
		v = getf(0, v);
		f[0][u] = v;
	}

	for (let i = 0; i < m2; i++) {
		let [u, v] = rna();
		u--; v--;
		u = getf(1, u);
		v = getf(1, v);
		f[1][u] = v;
	}

	let ans = [];
	for (let i = 0; i < n; i++) {
		for (let j = i + 1; j < n; j++) {
			if (getf(0, i) != getf(0, j) && getf(1, i) != getf(1, j)) {
				f[0][getf(0, i)] = getf(0, j);
				f[1][getf(1, i)] = getf(1, j);
				ans.push([i+1, j+1]);
			}
		}
	}

	console.log(ans.length);
	for (const edg of ans) {
		console.log(edg.join(' '));
	}
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
function createHeuristicFindSet(e) {
  const t = new Array(e + 1),
    n = new Array(e + 1)
  let r = e
  return {
    init: function (e) {
      ;(r = e), n.fill(1, r + 1, 1)
      for (let e = 1; e <= r; ++e) t[e] = e
    },
    root: i,
    merge: function (e, r) {
      const s = i(e),
        o = i(r)
      if (s === o) return s
      if (n[s] > n[o]) return (t[o] = s), (n[s] += n[o]), s
      return (t[s] = o), o
    },
  }
  function i(e) {
    return t[e] === e ? e : (t[e] = i(t[e]))
  }
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readLineAsNumber() {
    return Number(this.readLine())
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(String(e))
  }
  println(e) {
    stdout.write(String(e)), stdout.write('\n')
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(t => {
      stdin.on('data', t => e.push(t)),
        stdin.on('end', function () {
          const n = e.join('').split(os.EOL)
          t(n)
        })
    })
  }
}
async function __main__(e) {
  const t = new InputAndOutput()
  await t.init(), e(t)
}
function solve() {
  return -1
}
__main__(function (e) {
  const t = 100010,
    n = createHeuristicFindSet(t),
    r = createHeuristicFindSet(t)
  for (let t = 1; t <= 1; ++t) {
    const [t, i, s] = e.readIntegersOfLine()
    n.init(t), r.init(t)
    for (let t = 0; t < i; ++t) {
      const [t, r] = e.readIntegersOfLine()
      n.merge(t, r)
    }
    for (let t = 0; t < s; ++t) {
      const [t, n] = e.readIntegersOfLine()
      r.merge(t, n)
    }
    e.println(t - 1 - Math.max(i, s))
    const o = Math.floor(Math.random() * t) + 1
    for (let i = 1; i <= t; ++i) {
      const t = n.root(i),
        s = n.root(o),
        u = r.root(i),
        c = r.root(o)
      t !== s &&
        u !== c &&
        (n.merge(t, s), r.merge(u, c), e.println(o + ' ' + i))
    }
    const u = []
    for (let e = 1; e <= t; ++e) {
      const t = n.root(e),
        r = n.root(o)
      t !== r && (n.merge(t, r), u.push(e))
    }
    const c = []
    for (let e = 1; e <= t; ++e) {
      const t = r.root(e),
        n = r.root(o)
      t !== n && (r.merge(t, n), c.push(e))
    }
    for (let t = 0, n = Math.min(u.length, c.length); t < n; ++t) {
      const n = u[t]
      e.println(o + ' ' + n)
    }
  }
})


You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the string $$$t$$$ in the string $$$s$$$ in the minimum number of moves, and also calculate how many different sequences of moves of the minimum length exist.Two sequences of moves are considered different if the sets of indices at which the removed occurrences of the string $$$t$$$ in $$$s$$$ begin differ. For example, the sets $$$\{1, 2, 3\}$$$ and $$$\{1, 2, 4\}$$$ are considered different, the sets $$$\{2, 4, 6\}$$$ and $$$\{2, 6\}$$$ — too, but sets $$$\{3, 5\}$$$ and $$$\{5, 3\}$$$ — not.For example, let the string $$$s =$$$ "abababacababa" and the string $$$t =$$$ "aba". We can remove all occurrences of the string $$$t$$$ in $$$2$$$ moves by cutting out the occurrences of the string $$$t$$$ at the $$$3$$$th and $$$9$$$th positions. In this case, the string $$$s$$$ is an example of the form "ab...bac...ba". It is also possible to cut occurrences of the string $$$t$$$ at the $$$3$$$th and $$$11$$$th positions. There are two different sequences of minimum length moves.Since the answer can be large, output it modulo $$$10^9 + 7$$$.

The first line of the input contains a single integer $$$q$$$ ($$$1 \le q \le 50$$$) — the number of test cases. The descriptions of the sets follow. The first line of each set contains a non-empty string $$$s$$$ ($$$1 \le |s| \le 500$$$) consisting of lowercase Latin letters. The second line of each set contains a non-empty string $$$t$$$ ($$$1 \le |t| \le 500$$$) consisting of lowercase Latin letters. It is guaranteed that the sum of string lengths $$$s$$$ over all test cases does not exceed $$$500$$$. Similarly, it is guaranteed that the sum of string lengths $$$t$$$ over all test cases does not exceed $$$500$$$.

For each test case print two integers — the minimum number of moves and the number of different optimal sequences, modulo $$$10^9 + 7$$$.

8

abababacababa

aba

ddddddd

dddd

xyzxyz

xyz

abc

abcd

abacaba

abaca

abc

def

aaaaaaaa

a

aaaaaaaa

aa

NoteThe first test case is explained in the statement.In the second case, it is enough to cut any of the four occurrences.In the third case, string $$$s$$$ is the concatenation of two strings $$$t =$$$ "xyz", so there is a unique optimal sequence of $$$2$$$ moves.In the fourth and sixth cases, the string $$$s$$$ initially contains no occurrences of the string $$$t$$$.In the fifth case, the string $$$s$$$ contains exactly one occurrence of the string $$$t$$$.

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 s1 = lines[l++]
        const s2 = lines[l++]
        output[i] = solve(s1, s2)
    }
    console.log(output.join('\n'))
// })()
})

function solve(s, t) {
    const ps = []
    for (let i = 0; i + t.length - 1 < s.length; i++) {
        if (s.slice(i, i + t.length) === t) ps.push(i)
    }
    if (!ps.length) return [0, 1].join(' ')
// console.log(ps)
    const dp = Array(ps.length).fill(Infinity)
    const count = Array(ps.length).fill(1)
    let min = Infinity
    for (let i = 0; i < ps.length; i++) {
        for (let j = i - 1; j >= 0; j--) {
            if (ps[j] + t.length - 1 >= ps[i]) continue
            let has = 0
            for (let k = j + 1; k < i; k++) {
                if (ps[j] + t.length - 1 < ps[k] && ps[k] + t.length - 1 < ps[i]) {
                    has = 1
                    break
                }
            }
            if (has) continue
            // dp[i] = Math.min(dp[i], dp[j] + 1)
            // count[i] = add(count[i], count[j])
            if (dp[j] + 1 < dp[i]) {
                dp[i] = dp[j] + 1
                count[i] = count[j]
            } else if (dp[j] + 1 === dp[i]) {
                count[i] = add(count[i], count[j])
            }
        }
        if (dp[i] === Infinity) {
            dp[i] = 1
            // count[i] = 1
        }
        if (ps[i] + t.length - 1 >= ps[ps.length - 1]) {
            min = Math.min(min, dp[i])
        }
    }
    let ans = 0
    for (let i = 0; i < ps.length; i++) {
        if (ps[i] + t.length - 1 >= ps[ps.length - 1]
                && dp[i] === min) {
            ans = add(ans, count[i])
        }
    }
// console.log(dp, count)
    return min + ' ' + ans
}
function add(a, b) {
    return (a + b) % (1e9 + 7)
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read(),
        t = read();
  const n = s.length,
        m = t.length;
  const MOD = 10 ** 9 + 7;
  const mod = num => num % MOD;
  const p = new Array(n).fill(0);
  for (let i = 0; i <= n - m; i++) {
    let flag = 1;
    for (let j = 0; j < m; j++) {
      if (s[i + j] !== t[j]) {
        flag = 0;
        break;
      }
    }
    p[i + m - 1] = flag;
  }
  const dp = [];
  for (let i = 0; i <= n - m; i++) {
    if (!p[i + m - 1]) continue;
    let ans = [Infinity, Infinity];
    for (let j = 0; j < i; j++) {
      if (dp[j] && dp[j][2] >= i - 1) {
        if (dp[j][0] < ans[0]) {
          ans = [...dp[j]];
        } else if (dp[j][0] === ans[0]) {
          ans[1] = mod(ans[1] + dp[j][1]);
        }
      }
    }
    if (ans[0] === Infinity) ans = [1, 1, n - 1];else {
      ans[0]++;
      ans[2] = n - 1;
    }
    for (let j = i + m * 2 - 1; j < n; j++) {
      if (p[j]) {
        ans[2] = j - 1;
        break;
      }
    }
    dp[i + m - 1] = ans;
  }
  let res = 0,
      max = Infinity;
  for (let i = 0; i < n; i++) {
    if (dp[i] && dp[i][2] === n - 1) {
      if (dp[i][0] < max) {
        max = dp[i][0];
        res = dp[i][1];
      } else if (dp[i][0] === max) {
        res = mod(res + dp[i][1]);
      }
    }
  }
  if (max === Infinity) return `0 1`;
  return `${max} ${res}`;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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 s1 = lines[l++]
        const s2 = lines[l++]
        output[i] = solve(s1, s2)
    }
    console.log(output.join('\n'))
// })()
})

function solve(s, t) {
    const ps = []
    for (let i = 0; i + t.length - 1 < s.length; i++) {
        if (s.slice(i, i + t.length) === t) ps.push(i)
    }
    if (!ps.length) return [0, 1].join(' ')
// console.log(ps)
    const dp = Array(ps.length).fill(Infinity)
    const count = Array(ps.length).fill(1)
    let ans = 0
    for (let i = 0; i < ps.length; i++) {
        for (let j = i - 1; j >= 0; j--) {
            if (ps[j] + t.length - 1 >= ps[i]) continue
            let has = 0
            for (let k = j + 1; k < i; k++) {
                if (ps[j] + t.length - 1 < ps[k] && ps[k] + t.length - 1 < ps[i]) {
                    has = 1
                    break
                }
            }
            if (has) continue
            // dp[i] = Math.min(dp[i], dp[j] + 1)
            // count[i] = add(count[i], count[j])
            if (dp[j] + 1 < dp[i]) {
                dp[i] = dp[j] + 1
                count[i] = count[j]
            } else if (dp[j] + 1 === dp[i]) {
                count[i] = add(count[i], count[j])
            }
        }
        if (dp[i] === Infinity) {
            dp[i] = 1
            // count[i] = 1
        }
        if (ps[i] + t.length - 1 >= ps[ps.length - 1]) {
            ans = add(ans, count[i])
        }
    }
// console.log(dp, count)
    return dp[ps.length - 1] + ' ' + ans
}
function add(a, b) {
    return (a + b) % (1e9 + 7)
}