//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();
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) => {
    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"));
}

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

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


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

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

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

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


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

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

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


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

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

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


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