Hr0d1y has $$$q$$$ queries on a binary string $$$s$$$ of length $$$n$$$. A binary string is a string containing only characters '0' and '1'.A query is described by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \leq l_i \lt r_i \leq n)$$$. For each query, he has to determine whether there exists a good subsequence in $$$s$$$ that is equal to the substring $$$s[l_i\ldots r_i]$$$.   A substring $$$s[i\ldots j]$$$ of a string $$$s$$$ is the string formed by characters $$$s_i s_{i+1} \ldots s_j$$$. String $$$a$$$ is said to be a subsequence of string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some characters without changing the order of the remaining characters. A subsequence is said to be good if it is not contiguous and has length $$$\ge 2$$$. For example, if $$$s$$$ is "1100110", then the subsequences $$$s_1s_2s_4$$$ ("1100110") and $$$s_1s_5s_7$$$ ("1100110") are good, while $$$s_1s_2s_3$$$ ("1100110") is not good. Can you help Hr0d1y answer each query?

The first line of the input contains a single integer $$$t$$$ ($$$1\leq t \leq 100$$$) — the number of test cases. The description of each test case is as follows. The first line contains two integers $$$n$$$ ($$$2 \leq n \leq 100$$$) and $$$q$$$ ($$$1\leq q \leq 100$$$) — the length of the string and the number of queries.  The second line contains the string $$$s$$$. The $$$i$$$-th of the next $$$q$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \leq l_i \lt r_i \leq n$$$).

For each test case, output $$$q$$$ lines. The $$$i$$$-th line of the output of each test case should contain "YES" if there exists a good subsequence equal to the substring $$$s[l_i...r_i]$$$, and "NO" otherwise. You may print each letter in any case (upper or lower).

NoteIn the first test case,   $$$s[2\ldots 4] = $$$ "010". In this case $$$s_1s_3s_5$$$ ("001000") and $$$s_2s_3s_6$$$ ("001000") are good suitable subsequences, while $$$s_2s_3s_4$$$ ("001000") is not good.  $$$s[1\ldots 3] = $$$ "001". No suitable good subsequence exists.  $$$s[3\ldots 5] = $$$ "100". Here $$$s_3s_5s_6$$$ ("001000") is a suitable good subsequence.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    let [len, q] = readLine().split(" ").map(Number);
    const str = readLine();
    const queries = [];
    while (q--) {
      const _q = readLine().split(" ").map(Number);
      queries.push(_q);
    }
    let [store, c0, c1] = [[], 0, 0];
    for (let i = 0; i < len; i++) {
      const n = str[i];
      if (n === "0") c0++;
      else c1++;
      store[i] = { c0, c1 };
    }
    for (let [start, end] of queries) {
      if (
        (str[start - 1] === "0" && store[start - 1].c0 > 1) ||
        (str[start - 1] === "1" && store[start - 1].c1 > 1) ||
        (str[end - 1] === "0" && Math.abs(store[end - 1].c0 - store[len - 1].c0) >= 1) ||
        (str[end - 1] === "1" && Math.abs(store[end - 1].c1 - store[len - 1].c1) >= 1)
      ) {
        console.log(`YES`);
      } else console.log(`NO`);
    }
  }
}

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

    B();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,q] = ti(readline().split(' '));
        let s = readline().split('');
        for(let i = 0; i < q; i++){
            let [l,r] = ti(readline().split(' '));
            l -= 1;
            r -= 1;
            let cr = s[r];
            let cl = s[l];
            let flag = false;
            for(let j = r+1; j < n; j++){
                if(s[j] === cr){
                    flag = true;
                    break;
                }
            }

            if(!flag){
                for(let j = 0; j < l; j++){
                    if(s[j] === cl){
                        flag = true;
                        break;
                    }
                }
            }

            if(flag)
                console.log('YES');
            else
                console.log('NO');
        }
    }
}


Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j.Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most  (at most  pairs). Help Iahub, find any suitable array.

The first line contains three integers n (1 ≤  n ≤ 1000), m (1 ≤ m ≤  100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.

On the first line of the output print an integer p, the size of the array (p can be at most ). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices. If there are multiple correct answers, you can print any.

NoteConsider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var k=+l[2];
var a=[];
for(var i=0;i<n;i++){
	a[i]=readline().split(' ').map(function(v){return +v});
}

var ans=[];
if(k){
	for(var ii=m-1;ii>=0;ii--){
		for(var i=0;i<ii;i++){
			var flg=false;
			for(var j=0;j<n;j++){
				var arr=a[j];
				if(arr[i]<arr[i+1]){
					flg=true;
					var temp=arr[i];
					arr[i]=arr[i+1];
					arr[i+1]=temp;
				}
			}
			if(flg){
				ans.push((i+2)+' '+(i+1));
			}
		}
	}
}else{
	for(var ii=m-1;ii>=0;ii--){
		for(var i=0;i<ii;i++){
			var flg=false;
			for(var j=0;j<n;j++){
				var arr=a[j];
				if(arr[i]>arr[i+1]){
					flg=true;
					var temp=arr[i];
					arr[i]=arr[i+1];
					arr[i+1]=temp;
				}
			}
			if(flg){
				ans.push((i+1)+' '+(i+2));
			}
		}
	}
}
print(ans.length);
for(var i=0;i<ans.length;i++){
	print(ans[i])
}

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var arrayNum = integers[0], count = integers[1], direction = integers[2];

	print(count*(count-1)/2);

	if (direction == 0) {
		for (var i = 1; i <= count; i += 1) {
			for (var j = i+1; j <= count; j += 1) {
				print([i, j].join(' '));
			}
		}
	}
	else {
		for (var i = count; i >= 1; i -= 1) {
			for (var j = i-1; j >= 1; j -= 1) {
				print([i, j].join(' '));
			}
		}
	}
}

main();

var input = readline().split(' ');
var n = parseInt(input[0]), m=parseInt(input[1]), k=parseInt(input[2]);
for(var i=1; i<=n; i++) readline();
var answer = ''+m*(m-1)/2+'\n';
for(var i=1; i<=m; i++)
{
for(var j=i+1; j<=m; j++)
{
answer+=k?j+' '+i+'\n':i+' '+j+'\n';
}
}
print(answer);

var input = readline().split(' ');
var n = parseInt(input[0]), m=parseInt(input[1]), k=parseInt(input[2]);
for(var i=1; i<=n; i++) readline();
var answer = ''+m*(m-1)/2+'\n';
for(var i=1; i<=m; i++)
{
for(var j=i+1; j<=m; j++)
{
answer+=k?i+' '+j+'\n':j+' '+i+'\n';
}
}
print(answer);


Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has a number consisting of n digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it d. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation k times: find the minimum x (1 ≤ x < n) such that dx = 4 and dx + 1 = 7, if x is odd, then to assign dx = dx + 1 = 4, otherwise to assign dx = dx + 1 = 7. Note that if no x was found, then the operation counts as completed and the array doesn't change at all.You are given the initial number as an array of digits and the number k. Help Petya find the result of completing k operations.

The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 109) — the number of digits in the number and the number of completed operations. The second line contains n digits without spaces representing the array of digits d, starting with d1. It is guaranteed that the first digit of the number does not equal zero.

In the single line print the result without spaces — the number after the k operations are fulfilled.

NoteIn the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477.In the second sample: 4478 → 4778 → 4478.

// n = 7;
// k = 4;
// inp_str = '4727447';

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
			//console.log('i=',i);
				if ( (i+1) % 2 == 0){
					//console.log('i=5',str);
					if (i-1>=0 && str[i-1]=='4'){
						if ( (j%2==0) != (k%2 == 0)){
							str = str.replaceAt(i,'7');
							//console.log('aa=',str);
						}
						//console.log('aa=',str);
						return str;
					}
					//console.log(str);
					str = str.replaceAt(i,'7');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i--;
				}
				else{
					if (i+2 < n && str[i+2]=='7'){
						if ( (j%2==0) != (k%2 == 0)){
							str = str.replaceAt(i+1,'4');
						}
						return str;
					}

					str = str.replaceAt(i+1,'4');
					//if (i-1 >=0) i= i - 2;
					//if (i < n - 2) i--;
					i++;
				}
				j++;
				//console.log('j=',j);
				//console.log('str=',str);
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
//print(k,' ',n);
//console.log(transform(inp_str, k));
print(transform(inp_str, k));

var input = readline().split('\n');
line1 = input[0].split(' ');
n = line1[0];
k = line1[1];
inp_str = input[1];

//n = 7;
//k = 4;
//inp_str = '4727447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					//console.log(str);
					str = str.replaceAt(i+1,'4');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i++;
				}
				else{
					str = str.replaceAt(i,'7');
					//if (i-1 >=0) i= i - 2;
					if (i < n - 2) i--;
				}
				j++;
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
print(input[1]);
print(input[0]);
print(input);
//print(k,' ',n);
//console.log(transform(inp_str, k));
//print(transform(inp_str, k));

var input = readline().split('\n');
line1 = input[0].split(' ');
n = line1[0];
k = line1[1];
inp_str = input[1];

//n = 7;
//k = 4;
//inp_str = '4727447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					//console.log(str);
					str = str.replaceAt(i+1,'4');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i++;
				}
				else{
					str = str.replaceAt(i,'7');
					//if (i-1 >=0) i= i - 2;
					if (i < n - 2) i--;
				}
				j++;
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
print(input[1]);
print(input[0]);
//print(k,' ',n);
//console.log(transform(inp_str, k));
//print(transform(inp_str, k));

var input = readline().split('\n');
line1 = input[0].split(' ');
n = line1[0];
k = line1[1];
inp_str = input[1];

//n = 7;
//k = 4;
//inp_str = '4727447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					//console.log(str);
					str = str.replaceAt(i+1,'4');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i++;
				}
				else{
					str = str.replaceAt(i,'7');
					//if (i-1 >=0) i= i - 2;
					if (i < n - 2) i--;
				}
				j++;
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
print(input[1]);
print(k,' ',n);
//console.log(transform(inp_str, k));
//print(transform(inp_str, k));

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

//n = 3;
//k = 1000000000;
//inp_str = '447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					if (i-1>=0 && str[i-1]=='4'){
						if ( (j%2==0 ^ k%2 == 0) ==1){
							str = str.replaceAt(i,'7');
						}
						return str;
					}
					//console.log(str);
					str = str.replaceAt(i,'7');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i--;
				}
				else{

					if (i+2 < n && str[i+2]=='7'){
						if ( (j%2==0 ^ k%2 == 0) ==1){
							str = str.replaceAt(i+1,'4');
						}
						return str;
					}

					str = str.replaceAt(i+1,'4');
					//if (i-1 >=0) i= i - 2;
					//if (i < n - 2) i--;
					i++;
				}
				j++;
				//console.log('j=',j);
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
//print(k,' ',n);
//console.log(transform(inp_str, k));
print(transform(inp_str, k));

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

//n = 3;
//k = 1000000000;
//inp_str = '447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					if (i+2 < n && str[i+2]=='7'){
						if ( (j%2==0 ^ k%2 == 0) ==1){
							str = str.replaceAt(i,'7');
						}
						return str;
					}
					//console.log(str);
					str = str.replaceAt(i+1,'4');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i++;
				}
				else{
					if (i-1>=0 && str[i-1]=='4'){
						if ( (j%2==0 ^ k%2 == 0) ==1){
							str = str.replaceAt(i+1,'4');
						}
						return str;
					}

					str = str.replaceAt(i,'7');
					//if (i-1 >=0) i= i - 2;
					//if (i < n - 2) i--;
					i--;
				}
				j++;
				//console.log('j=',j);
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
//print(k,' ',n);
//console.log(transform(inp_str, k));
print(transform(inp_str, k));

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

//n = 7;
//k = 4;
//inp_str = '4727447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					//console.log(str);
					str = str.replaceAt(i+1,'4');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i++;
				}
				else{
					str = str.replaceAt(i,'7');
					//if (i-1 >=0) i= i - 2;
					if (i < n - 2) i--;
				}
				j++;
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
//print(k,' ',n);
//console.log(transform(inp_str, k));
print(transform(inp_str, k));

// n = 7;
// k = 4;
// inp_str = '4727447';

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
			//console.log('i=',i);
				if ( (i+1) % 2 == 0){
					//console.log('i=5',str);
					if (i-1>=0 && str[i-1]=='4'){
						if ( (j%2==0) == (k-1%2 == 0)){
							str = str.replaceAt(i,'7');
							//console.log('aa=',str);
						}
						//console.log('aa=',str);
						return str;
					}
					//console.log(str);
					str = str.replaceAt(i,'7');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i--;
				}
				else{
					if (i+2 < n && str[i+2]=='7'){
						if ( (j%2==0) != (k-1%2 == 0)){
							str = str.replaceAt(i+1,'4');
						}
						return str;
					}

					str = str.replaceAt(i+1,'4');
					//if (i-1 >=0) i= i - 2;
					//if (i < n - 2) i--;
					i++;
				}
				j++;
				//console.log('j=',j);
				//console.log('str=',str);
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
//print(k,' ',n);
//console.log(transform(inp_str, k));
print(transform(inp_str, k));

// n = 7;
// k = 4;
// inp_str = '4727447';

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
			//console.log('i=',i);
				if ( (i+1) % 2 == 0){
					//console.log('i=5',str);
					if (i-1>=0 && str[i-1]=='4'){
						if ( (j%2==0) == (k%2 == 0)){
							str = str.replaceAt(i,'7');
							//console.log('aa=',str);
						}
						//console.log('aa=',str);
						return str;
					}
					//console.log(str);
					str = str.replaceAt(i,'7');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i--;
				}
				else{
					if (i+2 < n && str[i+2]=='7'){
						if ( (j%2==0) != (k%2 == 0)){
							str = str.replaceAt(i+1,'4');
						}
						return str;
					}

					str = str.replaceAt(i+1,'4');
					//if (i-1 >=0) i= i - 2;
					//if (i < n - 2) i--;
					i++;
				}
				j++;
				//console.log('j=',j);
				//console.log('str=',str);
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
//print(k,' ',n);
//console.log(transform(inp_str, k));
print(transform(inp_str, k));

var input = readline().split(' ');
n = input[0];
k = input[1];
var inp_str = readline();

//n = 7;
//k = 4;
//inp_str = '4727447';

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

function transform(str, k){
	//for (i = 0; i < str.length; i ++)
	i = 0;
	j = 0;
	//while (j < k){
		while (i < n - 1 && j < k){
			//console.log('i=',i);
			if (str[i] == '4' && str[i+1] == '7'){
				if (i % 2 == 0){
					//console.log(str);
					str = str.replaceAt(i+1,'4');
					//console.log(str[i+1]);
					//console.log('i=',i);
					i++;
				}
				else{
					str = str.replaceAt(i,'7');
					//if (i-1 >=0) i= i - 2;
					if (i < n - 2) i--;
				}
				j++;
			}
			else i++;
		}
		//if (i == str.length) return str;
		//k++;
	//}
	return str;
}
print(input[1]);
print(input[0]);
print(input);
//print(k,' ',n);
//console.log(transform(inp_str, k));
//print(transform(inp_str, k));


Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point $$$(x_1,y_1)$$$ to the point $$$(x_2,y_2)$$$.He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly $$$1$$$ unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by $$$1$$$ unit.   For example, if the box is at the point $$$(1,2)$$$ and Wabbit is standing at the point $$$(2,2)$$$, he can pull the box right by $$$1$$$ unit, with the box ending up at the point $$$(2,2)$$$ and Wabbit ending at the point $$$(3,2)$$$.Also, Wabbit can move $$$1$$$ unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly $$$1$$$ unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.Wabbit can start at any point. It takes $$$1$$$ second to travel $$$1$$$ unit right, left, up, or down, regardless of whether he pulls the box while moving.Determine the minimum amount of time he needs to move the box from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$. Note that the point where Wabbit ends up at does not matter.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$: the number of test cases. The description of the test cases follows. Each of the next $$$t$$$ lines contains four space-separated integers $$$x_1, y_1, x_2, y_2$$$ $$$(1 \leq x_1, y_1, x_2, y_2 \leq 10^9)$$$, describing the next test case.

For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$.

NoteIn the first test case, the starting and the ending points of the box are $$$(1,2)$$$ and $$$(2,2)$$$ respectively. This is the same as the picture in the statement. Wabbit needs only $$$1$$$ second to move as shown in the picture in the statement.In the second test case, Wabbit can start at the point $$$(2,1)$$$. He pulls the box to $$$(2,1)$$$ while moving to $$$(3,1)$$$. He then moves to $$$(3,2)$$$ and then to $$$(2,2)$$$ without pulling the box. Then, he pulls the box to $$$(2,2)$$$ while moving to $$$(2,3)$$$. It takes $$$4$$$ seconds.

const solve = (data) => {
    let x1 = data[0][0];
    let y1 = data[0][1];
    let x2 = data[0][2];
    let y2 = data[0][3];
    if (y1 == y2) {
        if (x1 == x2) {
            return 0;
        } else {
            return Math.abs(x2 - x1);
        }
    } else {
        if (x1 == x2) {
            return Math.abs(y2 - y1);
        } else {
            let h = Math.abs(x2 - x1);
            let v = Math.abs(y2 - y1);
            return h + 2 + v;
        }
    }
};

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 = Number(input[0][0]);
        let i = 1;
        while (t > 0) {
            let data = input.slice(i, i + 1);
            console.log(solve(data));
            t--;
            i++;
        }
    });

};

main()

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

let lineNum = 0;
let countOfData = null;
let data = [];
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line;
    return;
  }

  data.push(line.split(' ').map(i => +i));

  if(lineNum - 1 === countOfData) {
    goToSolution(data);
  }

});

function goToSolution(datas) {
  for(let data of datas) {
    let seconds = 0;
    seconds += Math.max(data[0], data[2]) - Math.min(data[0], data[2]);
    seconds += Math.max(data[1], data[3]) - Math.min(data[1], data[3]);
    if(data[0] !== data[2] && data[1] !== data[3]) seconds += 2;
    console.log(seconds);
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    let [x1, y1, x2, y2] = readLine().split(" ").map(Number);
    const [xDiff, yDiff] = [Math.abs(x1 - x2), Math.abs(y1 - y2)];
    const diff = xDiff + yDiff;

    if (xDiff === 0 || yDiff === 0) {
      console.log(diff);
    } else {
      console.log(diff + 2);
    }
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var x1 = one[0];
		var y1 = one[1];
		var x2 = one[2];
		var y2 = one[3];
		if(x1 == x2){
			output[i] = Math.abs(y1 - y2);
		}else if(y1 == y2){
			output[i] = Math.abs(x1 - x2);
		}else{
			output[i] = Math.abs(y1 - y2) + Math.abs(x1 - x2) + 2;
		}
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      let a = data[i].trim().split(' ').map(Number);
      // const n = data[i] * 1;
      // const k = a[1];
      // let s = data[i + 1].trim().split(' ').map(Number);
      // s.sort((a, b) => b - a);
      let [x1, y1, x2, y2] = a;
      if (x1 === x2 && y1 === y2) {
        console.log(0);
      } else if (x1 === x2) {
        console.log(Math.abs(y1 - y2));
      } else if (y1 === y2) {
        console.log(Math.abs(x1 - x2));
      } else {
        console.log(Math.abs(x1 - x2) + Math.abs(y1 - y2) + 2);
      }
      i += 1;
    }
}

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = $()
  while (t--) {
    let [x1, y1, x2, y2] = $(4);
    if (x1 == x2 || y1 == y2) log(abs(x2 - x1) + abs(y2 - y1));
    else log(abs(x2 - x1) + abs(y2 - y1) + 2);
  }
}

let readline = require('readline');
let rl = readline.createInterface({input: process.stdin, output: process.stdout});
let lines = [];
let index = 0;
rl.on('line', line => lines.push(line));
rl.on('close', line => main());

function read() {
  return lines[index++];
}

function main(){
 let t = Number(read());
  while (t--) {
    let line = read();
    let [x1 , y1, x2, y2] = line.split(' ').map(Number);
    if (x1 === x2 && y1 === y2) {
      console.log('0')
    } else {
      console.log(Math.abs(x1 - x2) + Math.abs(y1 - y2) + (x1 !== x2 && y1 !== y2 ? 2 : 0))
    }
  }
}

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 => string.trim());

    main();
});

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

function main() {
    const numCases = readLine();
    for (let i = 0; i < numCases; i++) {
        const input = readLine().split(' ');
        if (input[0] === input[2]) {
            console.log(Math.abs(input[1] - input[3]));
        } else if (input[1] === input[3]){
            console.log(Math.abs(input[0] - input[2]));
        } else {
            console.log(Math.abs(input[0] - input[2]) + Math.abs(input[1] - input[3]) + 2);
        }
    }
}

var inputs = parseInt(readline());

for(var i =0;i<inputs;i++)
{
	var params = readline().split(" ").map(x => parseInt(x));
	var dist = 0;
	if(!(params[0]===params[2] || params[1]===params[3])) {
		dist+=2;}
	dist+=Math.abs(params[0]-params[2]) + Math.abs(params[1]-params[3]);
	print(dist);

}

/* Description probleme et solution
......
..Problem.....
A. Box is Pull
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x1,y1) to the point  (x2,y2)

He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.

For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).

Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.

Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.

Determine the minimum amount of time he needs to move the box from (x1,y1) to (x2,y2). Note that the point where Wabbit ends up at does not matter.

Input
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤1000): the number of test cases. The description of the test cases follows.

Each of the next t lines contains four space-separated integers x1,y1,x2,y2 (1≤x1,y1,x2,y2≤109), describing the next test case.

Output
For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x1,y1) to (x2,y2).

Example
inputCopy
2
1 2 2 2
1 1 2 2
outputCopy
1
4

Note
In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.

In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.

.......

....Solution...
......

Fin Description */

//definition des variables
var testCasesNumber = readline();
var listOfPoints = [];
var minX=0;
var maxX=0;
var minY=0;
var maxY=0;

//Saisie des données

for (var i = 0; i < testCasesNumber; i++) {
    listOfPoints.push(readline().split(' '));
    }
//Traitement ==> calcul du temps minimal requis
for (var i = 0; i < testCasesNumber; i++) {
    minX=Math.min(parseInt(listOfPoints[i][0]),parseInt(listOfPoints[i][2]));
    maxX=Math.max(parseInt(listOfPoints[i][0]),parseInt(listOfPoints[i][2]));
    minY=Math.min(parseInt(listOfPoints[i][1]),parseInt(listOfPoints[i][3]));
    maxY=Math.max(parseInt(listOfPoints[i][1]),parseInt(listOfPoints[i][3]));
    var time = 0;

time =maxX - minX;
time =time + (maxY- minY);
if (minX!=maxX && minY!=maxY){
time+=2;
}
print(time);
}

const solve = (data) => {
    let x1 = data[0][0];
    let y1 = data[0][1];
    let x2 = data[0][2];
    let y2 = data[0][3];
    if (y1 == y2) {
        if (x1 == x2) {
            return 0;
        } else {
            return Math.abs(x2 - x1);
        }
    } else {
        if (x1 == x2) {
            return Math.abs(y2 - y1);
        } else {
            let h = Math.abs(x2 - x1) + 1;
            let v = Math.abs(y2 - y1);
            return h + (h - 1) + v;
        }
    }
};

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 = Number(input[0][0]);
        let i = 1;
        while (t > 0) {
            let data = input.slice(i, i + 1);
            console.log(solve(data));
            t--;
            i++;
        }
    });

};

main()

const solve = (data) => {
    let x1 = data[0][0];
    let y1 = data[0][1];
    let x2 = data[0][2];
    let y2 = data[0][3];
    if (y1 == y2) {
        if (x1 == x2) {
            return 0;
        } else {
            return Math.abs(x2 - x1);
        }
    } else {
        if (x1 == x2) {
            return Math.abs(y2 - y1);
        } else {
            let h = Math.abs(x2 - x1) + 1;
            let v = Math.abs(y2 - y1);
            return h + 3 + v;
        }
    }
};

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 = Number(input[0][0]);
        let i = 1;
        while (t > 0) {
            let data = input.slice(i, i + 1);
            console.log(solve(data));
            t--;
            i++;
        }
    });

};

main()


You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!   Initially Zmei Gorynich has $$$x$$$ heads. You can deal $$$n$$$ types of blows. If you deal a blow of the $$$i$$$-th type, you decrease the number of Gorynich's heads by $$$min(d_i, curX)$$$, there $$$curX$$$ is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows $$$h_i$$$ new heads. If $$$curX = 0$$$ then Gorynich is defeated. You can deal each blow any number of times, in any order.For example, if $$$curX = 10$$$, $$$d = 7$$$, $$$h = 10$$$ then the number of heads changes to $$$13$$$ (you cut $$$7$$$ heads off, but then Zmei grows $$$10$$$ new ones), but if $$$curX = 10$$$, $$$d = 11$$$, $$$h = 100$$$ then number of heads changes to $$$0$$$ and Zmei Gorynich is considered defeated.Calculate the minimum number of blows to defeat Zmei Gorynich!You have to answer $$$t$$$ independent queries.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of queries. The first line of each query contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 100$$$, $$$1 \le x \le 10^9$$$) — the number of possible types of blows and the number of heads Zmei initially has, respectively. The following $$$n$$$ lines of each query contain the descriptions of types of blows you can deal. The $$$i$$$-th line contains two integers $$$d_i$$$ and $$$h_i$$$ ($$$1 \le d_i, h_i \le 10^9$$$) — the description of the $$$i$$$-th blow.

For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich.  If Zmei Gorynuch cannot be defeated print $$$-1$$$.

NoteIn the first query you can deal the first blow (after that the number of heads changes to $$$10 - 6 + 3 = 7$$$), and then deal the second blow.In the second query you just deal the first blow three times, and Zmei is defeated. In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop fighting?

const MEMORY = [];
let MEMORY_INDEX = 0;
function print() {
   console.log.apply(null, arguments);
}
function readline() {
   return MEMORY[MEMORY_INDEX++];
}

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

RL.on('line', (line) => {
   MEMORY.push(line);
});

RL.on('close', solve);

function solve() {
   const T = Number.parseInt(readline(), 10);
   for (let I = 0; I < T; ++I) {
      let [n, x] = readline().split(' ').map(num => Number.parseInt(num, 10));
      let d;
      let h;
      let maxD = -1;
      let maxDiff = -1;
      for (let i = 0; i < n; ++i) {
         [d, h] = readline().split(' ').map(num => Number.parseInt(num, 10));
         if (d > maxD) {
            maxD = d;
         }
         if (d - h > 0 && d - h > maxDiff) {
            maxDiff = d - h;
         }
      }
      if (maxD >= x) {
         print(1);
         continue;
      }
      if (maxDiff < 1) {
         print(-1);
      } else {
         print(Math.ceil((x - maxD) / maxDiff) + 1);
      }
   }
}

let stdinArr = [];
const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
rl.on('line', (line) => {
  stdinArr.push(line.trim().split(' ').map((item) => Number(item.trim())));
}).on('close', () => {
  zmeiGorynich(stdinArr);
})

function zmeiGorynich(stdinArr) {
  let queryNum = stdinArr[0][0];
  let curIndex = 1;
  while (queryNum--) {
    let n = stdinArr[curIndex][0];
    let x = stdinArr[curIndex][1];
    let typeArr = stdinArr.slice(curIndex + 1, curIndex + n + 1);
    console.log(singleQuery(x, typeArr));
    curIndex += (n + 1);
  }
}

function singleQuery(x, typeArr) {
  let maxItem = null;
  let maxBlow = 0;
  let maxType = 0;
  let typeArrLen = typeArr.length;
  for( let i = 0; i < typeArrLen; i++) {
    let item = typeArr[i];
    let d = item[0];
    let h = item[1];
    if (x <= d) {
      // 一击毙命
      return 1;
    }
    let cur = x - d + h;
    if (cur < x) {
      maxItem = item;
    }
    let blow = d-h;
    if (blow > 0 && blow > maxBlow) {
      maxBlow = blow;
    }
    maxType = d > maxType ? d : maxType
  }
  if (maxItem === null) {
    return -1;
  }
  // 减少到可以一击毙命
  let count = (x - maxType) / maxBlow;
  return Math.ceil(count) + 1;
}

let lineCount = 0;
let queriesTotal;
let queriesNum = 0;
let isType = false;
let typeArr = [];
let n; // 拥有的技能个数
let x; // 原始头数

/*const readLine = require('./tools');
readLine(str, (line) => {
  singleLine(line, () => {
    console.log('-----end')
  })
});*/

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
rl.on('line', (line) => {
  singleLine(line, () => {
    rl.close();
  })
});

function singleLine(line, close) {
  if (lineCount === 0) {
    queriesTotal = Number(line.trim());
  } else {
    let lines = line.trim().split(' ').map((item) => Number(item.trim()));
    let first = lines[0];
    let second = lines[1];
    if (!isType) {
      n = first;
      x = second;
      isType = true;
    } else {
      typeArr.push({
        d: first,
        h: second
      });
      if (typeArr.length === n) {
        console.log(zmeiGorynich(x, typeArr));
        isType = false;
        typeArr = [];
        queriesNum++;
      }
    }
  }
  if (queriesNum === queriesTotal) {
    close();
  }
  lineCount ++;
}

function zmeiGorynich(x, typeArr) {
  let maxItem = null;
  let maxBlow = 0;
  let maxType = 0;
  let typeArrLen = typeArr.length;
  for( let i = 0; i < typeArrLen; i++) {
    let item = typeArr[i];
    let {d, h} = item;
    if (x <= d) {
      // 一击毙命
      return 1;
    }
    let cur = x - d + h;
    if (cur < x) {
      maxItem = item;
    }
    let blow = d-h;
    if (blow > 0 && blow > maxBlow) {
      maxBlow = blow;
    }
    maxType = d > maxType ? d : maxType
  }
  if (maxItem === null) {
    return -1;
  }

  // 减少到可以一击毙命
  let count = (x - maxType) / maxBlow;
  return Math.ceil(count) + 1;
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();

    while (T --> 0) {
        var input = rdArN();
        var n = input[0];
        var x = input[1];

        var maxD = -Infinity;
        var maxP = -Infinity;
        var maxOPOP = -Infinity;
        for (var i = 0; i < n; ++i) {
            var input = rdArN();
            var d = input[0];
            var h = input[1];

            maxD = Math.max(maxD, d);
            if (maxP < d - h) {
                maxP = d - h;
                maxOPOP = d;
            }
        }

        if (maxD >= x) {
            pr(1);
        } else {
            if (maxP <= 0) {
                pr(-1);
            } else {
                var res1 = Math.ceil((x-maxD)/maxP) + 1;
                var res2 = Math.ceil((x-maxOPOP)/maxP) + 1;
                pr(Math.min(res1, res2))
            }
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

let lineCount = 0;
let queriesTotal;
let queriesNum = 0;
let isType = false;
let typeArr = [];
let n; // 拥有的技能个数
let x; // 原始头数

// const readLine = require('./tools');
// readLine(str, (line) => {
//   singleLine(line, () => {
//     console.log('-----end')
//   })
// });

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
rl.on('line', (line) => {
  singleLine(line, () => {
    rl.close();
  })
});

function singleLine(line, close) {
  if (lineCount === 0) {
    queriesTotal = Number(line.trim());
  } else {
    let lines = line.trim().split(' ').map((item) => Number(item.trim()));
    let first = lines[0];
    let second = lines[1];
    if (!isType) {
      n = first;
      x = second;
      isType = true;
    } else {
      typeArr.push({
        d: first,
        h: second
      });
      if (typeArr.length === n) {
        console.log(zmeiGorynich(x, typeArr));
        isType = false;
        typeArr = [];
        queriesNum++;
      }
    }
  }
  if (queriesNum === queriesTotal) {
    close();
  }
  lineCount ++;
}

function zmeiGorynich(x, typeArr) {
  let maxItem = null;
  let maxBlow = 0;
  let maxType = 0;
  typeArr.forEach((item) => {
    let {d, h} = item;

    if (x <= d) {
      // 一击毙命
      return 1;
    }
    let cur = x - d + h;
    if (cur < x) {
      maxItem = item;
    }
    let blow = d-h;
    if (blow > 0 && blow > maxBlow) {
      maxBlow = blow;
    }
    maxType = d > maxType ? d : maxType
  });
  if (maxItem === null) {
    return -1;
  }

  // 减少到可以一击毙命
  let count = (x - maxType) / maxBlow;
  return Math.ceil(count) + 1;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0;
let queriesTotal;
let queriesNum = 0;
let isType = false;
let typeArr = [];
let n;
let x;
rl.on('line', function(line){
  if (lineCount === 0) {
    queriesTotal = Number(line.trim());
  } else {
    let lines = line.trim().split(' ').map((item) => Number(item.trim()));
    let first = lines[0];
    let second = lines[1];
    if (!isType) {
      n = first;
      x = second;
      isType = true;
    } else {
      typeArr.push({
        d: first,
        h: second
      });
      if (typeArr.length === n) {
        console.log(zmeiGorynich(x, typeArr));
        isType = false;
        typeArr = [];
        queriesNum++;
      }
    }
  }
  if (queriesNum === queriesTotal) {
    rl.close();
  }
  lineCount ++;
});

function zmeiGorynich(x, typeArr) {
  let minLast = x;
  let maxItem = null;
  let maxBlow = 0;
  let maxType = 0;
  typeArr.forEach((item) => {
    let {d, h} = item;
    let cur = minLast - d + h;
    if (cur < minLast) {
      minLast = cur;
      maxItem = item;
    }
    let blow = d-h;
    if (blow > 0 && blow > maxBlow) {
      maxBlow = blow;
    }
    maxType = d > maxType ? d : maxType
  });
  if (maxItem === null) {
    return -1;
  }
  if (minLast <= 0) {
    // 一击毙命
    return 1;
  }

  // 减少到可以一击毙命
  let count = (x - maxType) / maxBlow;
  return Math.ceil(count) + 1;
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();

    while (T --> 0) {
        var input = rdArN();
        var n = input[0];
        var x = input[1];

        var maxD = -Infinity;
        var maxP = -Infinity;
        for (var i = 0; i < n; ++i) {
            var input = rdArN();
            var d = input[0];
            var h = input[1];

            maxD = Math.max(maxD, d);
            maxP = Math.max(maxP, d - h);
        }

        if (maxD > x) {
            pr(1);
        } else {
            if (maxP < 0) {
                pr(-1);
            } else {
                x -= maxD;
                pr(Math.ceil(x/maxP) + 1)
            }
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();

    while (T --> 0) {
        var input = rdArN();
        var n = input[0];
        var x = input[1];

        var maxD = -Infinity;
        var maxP = -Infinity;
        var maxOPOP = -Infinity;
        for (var i = 0; i < n; ++i) {
            var input = rdArN();
            var d = input[0];
            var h = input[1];

            maxD = Math.max(maxD, d);
            if (maxP < d - h) {
                maxP = d - h;
                maxOPOP = d;
            }
        }

        if (maxD >= x) {
            pr(1);
        } else {
            if (maxP < 0) {
                pr(-1);
            } else {
                var res1 = Math.ceil((x-maxD)/maxP) + 1;
                var res2 = Math.ceil((x-maxOPOP)/maxP) + 1;
                pr(Math.min(res1, res2))
            }
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();

    while (T --> 0) {
        var input = rdArN();
        var n = input[0];
        var x = input[1];

        var maxD = -Infinity;
        var maxP = -Infinity;
        var maxOPOP = -Infinity;
        for (var i = 0; i < n; ++i) {
            var input = rdArN();
            var d = input[0];
            var h = input[1];

            maxD = Math.max(maxD, d);
            if (maxP < d - h) {
                maxP = d - h;
                maxOPOP = d;
            }
        }

        if (maxD > x) {
            pr(1);
        } else {
            if (maxP < 0) {
                pr(-1);
            } else {
                var res1 = Math.ceil((x-maxD)/maxP) + 1;
                var res2 = Math.ceil((x-maxOPOP)/maxP) + 1;
                pr(Math.min(res1, res2))
            }
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();


Berland crossword is a puzzle that is solved on a square grid with $$$n$$$ rows and $$$n$$$ columns. Initially all the cells are white.To solve the puzzle one has to color some cells on the border of the grid black in such a way that:   exactly $$$U$$$ cells in the top row are black;  exactly $$$R$$$ cells in the rightmost column are black;  exactly $$$D$$$ cells in the bottom row are black;  exactly $$$L$$$ cells in the leftmost column are black. Note that you can color zero cells black and leave every cell white.Your task is to check if there exists a solution to the given puzzle.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The only line of each testcase contains $$$5$$$ integers $$$n, U, R, D, L$$$ ($$$2 \le n \le 100$$$; $$$0 \le U, R, D, L \le n$$$).

For each testcase print "YES" if the solution exists and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteHere are possible solutions to testcases $$$1$$$, $$$2$$$ and $$$4$$$:

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u === 0 && (r === n || l === n)) return console.log('NO')
        if (l === 0 && (u === n || d === n)) return console.log('NO')
        if (d === 0 && (r === n || l === n)) return console.log('NO')
        if (r === 0 && (u === n || d === n)) return console.log('NO')

        if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')
        if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')

        if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')
        if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')
        if (n === 2 && (r + l + u + d) === 1) return console.log('NO')

        if ((n - 1) === u && (l === 0 && r === 0)) return console.log('NO')
        if ((n - 1) === d && (l === 0 && r === 0)) return console.log('NO')
        if ((n - 1) === l && (u === 0 && d === 0)) return console.log('NO')
        if ((n - 1) === r && (u === 0 && d === 0)) return console.log('NO')

        if (u === n && d === (n-1) && (l < 2 && r < 2)) return console.log('NO')
        if (d === n && u === (n-1) && (l < 2 && r < 2)) return console.log('NO')

        if (r === n && l === (n-1) && (u < 2 && d < 2)) return console.log('NO')
        if (l === n && r === (n-1) && (u < 2 && d < 2)) return console.log('NO')

        if ((n - 1) === u && (n - 1) === d && (l+r<2)) return console.log('NO')
        if ((n - 1) === l && (n - 1) === r && (u+d<2)) return console.log('NO')

        // if (l === 0 && (u === n || d === n)) return console.log('NO')
        // if (d === 0 && (r === n || l === n)) return console.log('NO')
        // if (r === 0 && (u === n || d === n)) return console.log('NO')

        console.log('YES')
        // var a = readline().split('').map((x, iii) => {
        //     return x
        // })

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, U, R, D, L] = rna();

		let ans;
		for (let mask = 1; mask <= 16; mask++) {
			let [rU, rR, rD, rL] = [U, R, D, L];

			if (mask & 1) {
				rU--;
				rL--;
			}
			if (mask & 2) {
				rL--;
				rD--;
			}
			if (mask & 4) {
				rD--;
				rR--;
			}
			if (mask & 8) {
				rR--;
				rU--;
			}
			if (Math.min(rU, rL, rD, rR) >= 0 && Math.max(rU, rL, rD, rR) <= n-2) {
				ans = true;
			}
		}

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

'use-strict'

const { PassThrough } = require("stream");

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const [N,U,R,D,L] = readLine().split(' ').map(Number);

        const res = b(N,U,R,D,L);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function b(N,U,R,D,L){
    let [rU, rR, rD, rL] = [U,R,D,L];
    for(let mask = 0; mask <= 16; mask++){
        [rU, rR, rD, rL] = [U,R,D,L];
        if (mask & 1){
            rU-= 1;
            rL-= 1;
        }
        if (mask & 2){
            rL-= 1;
            rD-= 1;
        }
        if (mask & 4){
            rD-= 1;
            rR-= 1;
        }
        if (mask & 8){
            rR-= 1;
            rU-=1;
        }
        if (Math.min(rU,rR,rD,rL) >= 0 && Math.max(rU,rR,rD,rL) <= N - 2){
            return 'YES'
        }
    }
    return 'NO';
}

module.exports = b;

const checkBit = (n, mask) => {
  return (n & mask) !== 0 ? 1 : 0;
};

const solve = (n, U, R, D, L) => {
  for (let i = 0; i < 2 ** 4; i++) {
    const ul = checkBit(i, 1 << 3);
    const ur = checkBit(i, 1 << 2);
    const dr = checkBit(i, 1 << 1);
    const dl = checkBit(i, 1 << 0);
    const edge = [U - ul - ur, R - ur - dr, D - dr - dl, L - dl - ul];
    if (edge.every(e => e >= 0 && e <= n - 2)) return true;
  }
  return false;
};

const main = () => {
  let test = readInt();
  while (test--) {
    const [n, U, R, D, L] = readListInt();
    if (solve(n, U, R, D, L)) console.log("YES");
    else console.log("NO");
  }
};

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 => string.trim());
  main();
});

const readLine = () => {
  return inputString[currentLine++];
};

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
   for (var m = 1; m < input.length; m++) {
        var arr = input[m].split(" ").map((i) => {
            return Number(i);
        });
        var n = arr[0];
        var list = arr.slice(1);
        var patterns = [];
        for (let num = 0; num < 16; num++) {
            var binary = num.toString(2);
            binary = "0".repeat(4 - binary.length) + binary;
            patterns.push(binary);
        }

        var flag = false;
        for (var pattern of patterns) {
            for (var i = 0; i < list.length; i++) {
                var corner = Number(pattern[i]) + Number(pattern[(i + 1) % list.length]);
                if (list[i] > corner + (n - 2) || list[i] < corner) {
                    break;
                }
            }
            if (i === list.length) {
                flag = true;
                break;
            }
        }
        if (flag) {
            console.log("YES");
        } else {
            console.log("NO");
        }
   }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u === 0 && (r === n || l === n)) return console.log('NO')
        if (l === 0 && (u === n || d === n)) return console.log('NO')
        if (d === 0 && (r === n || l === n)) return console.log('NO')
        if (r === 0 && (u === n || d === n)) return console.log('NO')

        if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')
        if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')

        if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')
        if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')
        if (n === 2 && (r + l + u + d) === 1) return console.log('NO')

        if ((n - 1) === u && (l === 0 && r === 0)) return console.log('NO')
        if ((n - 1) === d && (l === 0 && r === 0)) return console.log('NO')
        if ((n - 1) === l && (u === 0 && d === 0)) return console.log('NO')
        if ((n - 1) === r && (u === 0 && d === 0)) return console.log('NO')

        if (u === n && d === (n-1) && (l < 2 && r < 2)) return console.log('NO')
        if (d === n && u === (n-1) && (l < 2 && r < 2)) return console.log('NO')

        if (r === n && l === (n-1) && (u < 2 && d < 2)) return console.log('NO')
        if (l === n && r === (n-1) && (u < 2 && d < 2)) return console.log('NO')

        // if (l === 0 && (u === n || d === n)) return console.log('NO')
        // if (d === 0 && (r === n || l === n)) return console.log('NO')
        // if (r === 0 && (u === n || d === n)) return console.log('NO')

        console.log('YES')
        // var a = readline().split('').map((x, iii) => {
        //     return x
        // })

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u === 0 && (r === n || l === n)) return console.log('NO')
        if (l === 0 && (u === n || d === n)) return console.log('NO')
        if (d === 0 && (r === n || l === n)) return console.log('NO')
        if (r === 0 && (u === n || d === n)) return console.log('NO')

        if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')
        if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')

        if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')
        if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')
        if (n === 2 && (r + l + u + d) === 1) return console.log('NO')

        if ((n - 1) === u && (l === 0 && r === 0)) return console.log('NO')
        if ((n - 1) === d && (l === 0 && r === 0)) return console.log('NO')
        if ((n - 1) === l && (u === 0 && d === 0)) return console.log('NO')
        if ((n - 1) === r && (u === 0 && d === 0)) return console.log('NO')

        // if (l === 0 && (u === n || d === n)) return console.log('NO')
        // if (d === 0 && (r === n || l === n)) return console.log('NO')
        // if (r === 0 && (u === n || d === n)) return console.log('NO')

        console.log('YES')
        // var a = readline().split('').map((x, iii) => {
        //     return x
        // })

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u === 0 && (r === n || l === n)) return console.log('NO')
        if (l === 0 && (u === n || d === n)) return console.log('NO')
        if (d === 0 && (r === n || l === n)) return console.log('NO')
        if (r === 0 && (u === n || d === n)) return console.log('NO')

        if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')
        if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')

        if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && (r + l + u + d) === 5) return console.log('NO')
        if (n === 2 && (l === 0 || r === 0 || d === 0 || u === 0) && (r + l + u + d) === 3) return console.log('NO')

        // if (l === 0 && (u === n || d === n)) return console.log('NO')
        // if (d === 0 && (r === n || l === n)) return console.log('NO')
        // if (r === 0 && (u === n || d === n)) return console.log('NO')

        console.log('YES')
        // var a = readline().split('').map((x, iii) => {
        //     return x
        // })

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u === 0 && (r === n || l === n)) return console.log('NO')
        if (l === 0 && (u === n || d === n)) return console.log('NO')
        if (d === 0 && (r === n || l === n)) return console.log('NO')
        if (r === 0 && (u === n || d === n)) return console.log('NO')

        if (u === n && d === n && (l < 2 || r < 2)) return console.log('NO')
        if (l === n && r === n && (u < 2 || d < 2)) return console.log('NO')

        if (n === 2 && (l === 2 || r === 2 || d === 2 || u === 2) && r + l + u + d === 5) return console.log('NO')

        // if (l === 0 && (u === n || d === n)) return console.log('NO')
        // if (d === 0 && (r === n || l === n)) return console.log('NO')
        // if (r === 0 && (u === n || d === n)) return console.log('NO')

        console.log('YES')
        // var a = readline().split('').map((x, iii) => {
        //     return x
        // })

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [n, u, r, d, l] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u === 0 && (r === n || l === n)) return console.log('NO')
        if (l === 0 && (u === n || d === n)) return console.log('NO')
        if (d === 0 && (r === n || l === n)) return console.log('NO')
        if (r === 0 && (u === n || d === n)) return console.log('NO')

        if (u === n && d === n && (l<2 || r<2)) return console.log('NO')
        if (l === n && r === n && (u<2 || d<2)) return console.log('NO')

        // if (l === 0 && (u === n || d === n)) return console.log('NO')
        // if (d === 0 && (r === n || l === n)) return console.log('NO')
        // if (r === 0 && (u === n || d === n)) return console.log('NO')

        console.log('YES')
        // var a = readline().split('').map((x, iii) => {
        //     return x
        // })

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, U, R, D, L] = rna();

		let l = 0, r = 0, u = 0, d = 0, lr = 0, ud = 0;

		if (U == n) l++, r++;
		if (U == n-1) lr++;

		if (D == n) l++, r++;
		if (D == n-1) lr++;

		if (L == n) u++, d++;
		if (L == n-1) ud++;

		if (R == n) u++, d++;
		if (R == n-1) ud++;

		const ok = L >= l && R >= r && U >= u && D >= d && L+R >= lr && U+D >= ud && U+L+R+D <= 4*(n-1);

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

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, U, R, D, L] = rna();

		let l = 0, r = 0, u = 0, d = 0, lr = 0, ud = 0;

		if (U == n) l++, r++;
		if (U == n-1) lr++;

		if (D == n) l++, r++;
		if (D == n-1) lr++;

		if (L == n) u++, d++;
		if (L == n-1) ud++;

		if (R == n) u++, d++;
		if (R == n-1) ud++;

		const ok = L >= l && R >= r && U >= u && D >= d && L+R >= lr && U+D >= ud;

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

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

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

function main () {
	let T = rn();
	while (T--) {
		const [n, u, r, d, l] = rna();

		function check(u, l, r) {
			let ok = true;
			if (u == n) ok = ok && l > 0 && r > 0;
			if (u == n-1) ok = ok && l + r > 0;
			return ok;
		}

		let ok = check(u, l, r) &&
			check(l, u, d) &&
			check(r, u, d) &&
			check(d, l, r);

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

'use-strict'

const { PassThrough } = require("stream");

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const [N,U,R,D,L] = readLine().split(' ').map(Number);

        const res = b(N,U,R,D,L);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function b(N,U,R,D,L){
    let [rU, rR, rD, rL] = [U,R,D,L];
    console.log(rU, rR, rD, rL)
    for(let mask = 0; mask <= 16; mask++){
        [rU, rR, rD, rL] = [U,R,D,L];
        console.log(rU, rR, rD, rL, mask)
        if (mask & 1){
            rU-= 1;
            rL-= 1;
        }
        if (mask & 2){
            rL-= 1;
            rD-= 1;
        }
        if (mask & 4){
            rD-= 1;
            rR-= 1;
        }
        if (mask & 8){
            rR-= 1;
            rU-=1;
        }
        if (Math.min(rU,rR,rD,rL) >= 0 && Math.max(rU,rR,rD,rL) <= N - 2){
            return 'YES'
        }
    }
    return 'NO';
}

module.exports = b;

'use-strict'

const { PassThrough } = require("stream");

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const [N,U,R,D,L] = get_ints();

        const res = b(N,U,R,D,L);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function b(N,U,R,D,L){
    const u = U - 2;
    const r = R - 2;
    const d = D - 2;
    const l = L - 2;
    if(u>= 0 && u<= N - 2 && r >= 0 && r <= N - 2 && d >= 0 && d <= N- 2 && l >= 0 && l <= N - 2){
        return 'YES'
    } else{
        return 'NO';
    }
}

const solve = (n, U, R, D, L) => {
  const edge = [U, R, D, L];
  if (edge.some(e => e > n)) return false;
  if (edge.every(e => e < n)) return true;

  let cU = 0,
    cR = 0,
    cD = 0,
    cL = 0;

  [U, D].forEach(e => {
    if (e === n) {
      cL += 1;
      cR += 1;
    }
  });

  [L, R].forEach(e => {
    if (e === n) {
      cU += 1;
      cD += 1;
    }
  });

  return U >= cU && D >= cD && L >= cL && R >= cR;
};

const main = () => {
  let test = readInt();
  while (test--) {
    const [n, U, R, D, L] = readListInt();
    if (solve(n, U, R, D, L)) console.log("YES");
    else console.log("NO");
  }
};

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 => string.trim());
  main();
});

const readLine = () => {
  return inputString[currentLine++];
};

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};


A subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the classic scheme one can get from any station to any other one along the passages. The passages can be used to move in both directions. Between each pair of stations there is no more than one passage.Berland mathematicians have recently proved a theorem that states that any classic scheme has a ringroad. There can be only one ringroad. In other words, in any classic scheme one can find the only scheme consisting of stations (where any two neighbouring ones are linked by a passage) and this cycle doesn't contain any station more than once.This invention had a powerful social impact as now the stations could be compared according to their distance from the ringroad. For example, a citizen could say "I live in three passages from the ringroad" and another one could reply "you loser, I live in one passage from the ringroad". The Internet soon got filled with applications that promised to count the distance from the station to the ringroad (send a text message to a short number...).The Berland government decided to put an end to these disturbances and start to control the situation. You are requested to write a program that can determine the remoteness from the ringroad for each station by the city subway scheme.

The first line contains an integer n (3 ≤ n ≤ 3000), n is the number of stations (and trains at the same time) in the subway scheme. Then n lines contain descriptions of the trains, one per line. Each line contains a pair of integers xi, yi (1 ≤ xi, yi ≤ n) and represents the presence of a passage from station xi to station yi. The stations are numbered from 1 to n in an arbitrary order. It is guaranteed that xi ≠ yi and that no pair of stations contain more than one passage. The passages can be used to travel both ways. It is guaranteed that the given description represents a classic subway scheme.

Print n numbers. Separate the numbers by spaces, the i-th one should be equal to the distance of the i-th station from the ringroad. For the ringroad stations print number 0.

/* TEST CASE
input
4
1 3
4 3
4 2
1 2
output
0 0 0 0
input
6
1 2
3 4
6 4
2 3
1 3
3 5
output
0 0 0 1 1 2

 */
function nonrecursiveDFS_detectCycle(G, s) {
    var n = G.n;
    var adj = G.adj;
    var visited = new Array(n + 1);
    var parent = new Array(n + 1);
    var next = new Array(n + 1);
    var stack = [];
    var cycleRoot, cycleLeaf;
    var v;

    // initialize array
    for (v = 1; v <= n; v++) {
    	next[v] = adj[v].length - 1;
    }

    // depth-first search using an explicit stack
    visited[s] = true;
    parent[s] = 0;
    stack.push(s);
    while (stack.length > 0) {
        v = stack[stack.length - 1];		// peek stack
        var i = next[v]--;

        // skip parent
        if (i >= 0 && adj[v][i] == parent[v]) {
        	i = next[v]--;
        }

        if (i < 0) {
            stack.pop();
        } else {
        	var neighbor = adj[v][i];
        	if (visited[neighbor]) {
        		cycleLeaf = v;
        		cycleRoot = neighbor;
        		break;
        	}
        	visited[neighbor] = true;
            parent[neighbor] = v;
            stack.push(neighbor);
        }
    }

    if (cycleLeaf != null) {
    	var rootParent = parent[cycleRoot];
        for (v = cycleLeaf; v != rootParent; v = parent[v]) {
        	G.distToRingRoad[v] = 0;
        }
    }
}

function nonrecursiveDFS_findDistToRingRoad(G) {
    var n = G.n;
    var adj = G.adj;
    var visited = new Array(n + 1);
    var next = new Array(n + 1);
    var stack = [];
    var s, v;

    for (v = 1; v <= n; v++) {
    	next[v] = adj[v].length - 1;
    }

    for (s = 1; s <= n; s++) {
    	if (G.distToRingRoad[s] == 0) {
            visited[s] = true;
            stack.push(s);

            while (stack.length > 0) {
                v = stack[stack.length - 1];		// peek stack
                var i = next[v]--;

                // skip visited one
                while (i >= 0 && (visited[adj[v][i]] || G.distToRingRoad[adj[v][i]] == 0)) {
                	i = next[v]--;
                }

                if (i < 0) {
                    stack.pop();
                } else {
                	var neighbor = adj[v][i];
            		G.distToRingRoad[neighbor] = G.distToRingRoad[v] + 1
                	visited[neighbor] = true;
                    stack.push(neighbor);
                }
            }
    	}
    }

}

function main() {
	var n = parseInt(readline());
	var G = {
				n: n,
				adj: new Array(n + 1),
				distToRingRoad: new Array(n + 1)
			};
	var i, u, v;

	for (v = 1; v <= n; v++) {
		G.adj[v] = [];
    	G.distToRingRoad[v] = Infinity;
	}

	for (i = 0; i < n; i++) {
		var splitted = readline().split(' ');
		u = parseInt(splitted[0]);
		v = parseInt(splitted[1]);
		G.adj[u].push(v);
		G.adj[v].push(u);
	}

	nonrecursiveDFS_detectCycle(G, 1);
	nonrecursiveDFS_findDistToRingRoad(G);
	G.distToRingRoad.shift();
	print(G.distToRingRoad.join(' '));
}

main();


Phoenix has a string $$$s$$$ consisting of lowercase Latin letters. He wants to distribute all the letters of his string into $$$k$$$ non-empty strings $$$a_1, a_2, \dots, a_k$$$ such that every letter of $$$s$$$ goes to exactly one of the strings $$$a_i$$$. The strings $$$a_i$$$ do not need to be substrings of $$$s$$$. Phoenix can distribute letters of $$$s$$$ and rearrange the letters within each string $$$a_i$$$ however he wants.For example, if $$$s = $$$ baba and $$$k=2$$$, Phoenix may distribute the letters of his string in many ways, such as:   ba and ba  a and abb  ab and ab  aa and bb But these ways are invalid:   baa and ba  b and ba  baba and empty string ($$$a_i$$$ should be non-empty) Phoenix wants to distribute the letters of his string $$$s$$$ into $$$k$$$ strings $$$a_1, a_2, \dots, a_k$$$ to minimize the lexicographically maximum string among them, i. e. minimize $$$max(a_1, a_2, \dots, a_k)$$$. Help him find the optimal distribution and print the minimal possible value of $$$max(a_1, a_2, \dots, a_k)$$$.String $$$x$$$ is lexicographically less than string $$$y$$$ if either $$$x$$$ is a prefix of $$$y$$$ and $$$x \ne y$$$, or there exists an index $$$i$$$ ($$$1 \le i \le min(|x|, |y|))$$$ such that $$$x_i$$$ < $$$y_i$$$ and for every $$$j$$$ $$$(1 \le j < i)$$$ $$$x_j = y_j$$$. Here $$$|x|$$$ denotes the length of the string $$$x$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case consists of two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$) — the length of string $$$s$$$ and the number of non-empty strings, into which Phoenix wants to distribute letters of $$$s$$$, respectively. The second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. It is guaranteed that the sum of $$$n$$$ over all test cases is $$$\le 10^5$$$.

Print $$$t$$$ answers — one per test case. The $$$i$$$-th answer should be the minimal possible value of $$$max(a_1, a_2, \dots, a_k)$$$ in the $$$i$$$-th test case.

NoteIn the first test case, one optimal solution is to distribute baba into ab and ab. In the second test case, one optimal solution is to distribute baacb into abbc and a.In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

'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++];
}
/**
    6
    4 2
    baba
    5 2
    baacb
    5 3
    baacb
    5 3
    aaaaa
    6 4
    aaxxzz
    7 1
    phoenix
**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        let [n, k] = readline().split(" ").map(x=> parseInt(x));
        let s = readline();

        s = s.split("").sort().join("");

        if(s[0] !== s[k-1]) {
            console.log(s[k-1]);
        } else {
            if(s[k] !== s[n-1]) {
                let output = [s[0]];
                for(let i=k;i<n;i++) {
                    output.push(s[i]);
                }

                console.log(output.join(""));
            } else {
                const output = new Array(k).fill([]);

                for(let i=0;i<n;i++) {
                    output[Math.floor(i % k)] = output[Math.floor(i % k)] + s[i];
                }

                console.log(output[0]);
            }
        }

    }
}

'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++];
}
/**
    6
    4 2
    baba
    5 2
    baacb
    5 3
    baacb
    5 3
    aaaaa
    6 4
    aaxxzz
    7 1
    phoenix
**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        let [n, k] = readline().split(" ").map(x=> parseInt(x));
        let s = readline();

        s = s.split("").sort().join("");

        if(s[0] !== s[k-1]) {
            console.log(s[k-1]);
        } else {
            if(s[k] !== s[n-1]) {
                let output = [s[0]];
                for(let i=k;i<n;i++) {
                    output.push(s[i]);
                }

                console.log(output.join(""));
            } else {
                console.log(s[0]+""+s[k]);
            }
        }

    }
}


Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.

In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week).

Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.

NoteIn the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.

nm = readline().split(' ').map(Number);
A = readline().split(' ').map(Number);
B = readline().split(' ').map(Number);
Ar = [];
ans = 0;
for(var i = 0;i<nm[0];i++) {
	Ar.push(Array(A[i],B[i],A[i]-B[i]));
}
Ar.sort((x,y) => {
	if(x[2] < y[2]) return -1;
	if(x[2] == y[2]) return 0;
	if(x[2] > y[2]) return 1;
});
for(var i=0;i<nm[1];i++) {
	ans += Ar[i][0];
}
for(var i=nm[1];i<nm[0];i++) {
	ans += ((a,b) => {if(a < b) return a; return b;})(Ar[i][0],Ar[i][1]);
}
print(ans);

var tmp = readline().split(' ');
var n = parseInt(tmp[0]);
var k = parseInt(tmp[1]);
var a = readline().split(' ').map(function(x) {
  return parseInt(x);
});
var b = readline().split(' ').map(function(x) {
  return parseInt(x);
});
var c = a.map(function(x, i) {
  return {
    i: i,
    d: a[i] - b[i]
  };
}).sort(function(a, b) {
  return a.d - b.d;
});
var r = 0;
for(var i = 0; i < n; i += 1) {
  if(i < k) {
    r += a[c[i].i];
  } else {
    r += Math.min(a[c[i].i], b[c[i].i]);
  }
}

print(r);