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

let currentLine = 0
let inputString = ''

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

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

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

// function main() {
//     /**
//      * INPUT TECHNIQUES
//      */

//     // Simple String Input
//     const strInput = readLine()

//     // Array Input
//     const arrInput = readLine().split(' ')

//     // Array Destructuring and Three variable input from a single line, separated by a space
//     const [a, b, c] = readLine.split(' ')

//     // If you need number separated by space just map each element of the array this way
//     const [x, y, z] = readLine.split(' ').map(Number)

//     /**
//      * OUTPUT TECHNIQUES
//      */

//     //  End by a new line "\n"
//     console.log("Hi")

//     // Don't end by new line character "\n"
//     process.stdout.write("Hi")

// }

function main() {
    let t = readLine();
    t = parseInt(t);

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

function solve() {
    const strInput = readLine();
    if (strInput.length < 2) {
        console.log("NO");
    } else {
        const first = strInput.substring(0, strInput.length / 2);
        const second = strInput.substring(strInput.length / 2, strInput.length);
        if (first == second) {
            console.log("YES");
        } else {
            console.log("NO");
        }
    }
}

    var len = readline();
    for(var i=0;i<+len;i++)
    {
     var inputData = readline();
     if(inputData.length%2 !=0)
     print("NO");
     else if((inputData.substring(0,(inputData.length/2)))  ==  (inputData.substring(inputData.length/2,inputData.length)))
      print("YES");
      else
       print("NO");
    }

var len = readline();
for(var i=0;i<+len;i++)
{
 var inputData = readline();
 if(inputData.length%2 !=0)
 print("NO");
// else if((inputData.length == 2) && (inputData[0]!=inputData[1]))
  //  print("NO");
 else if((inputData.substring(0,(inputData.length/2)))  ==  (inputData.substring(inputData.length/2,inputData.length)))
  print("YES");
  else
   print("NO");
}

q = +readline();
while (q--) {
  x = readline();
  if (x.length % 2 !== 0) {
    print("NO");
  } else {
    var first = x.slice(0, x.length / 2);
    var last = x.slice(x.length / 2, x.length);
    if (first === last) {
      print("YES");
    } else {
      print("NO");
    }
  }
}

q = +readline();
while (q--) {
  x = readline();
  if (x.length % 2 !== 0) {
    print("NO");
  } else {
    var first = x.slice(0, x.length / 2);
    var last = x.slice(x.length / 2, x.length);
    if (first.localeCompare(last) === 0) {
      print("YES");
    } else {
      print("NO");
    }
  }
}

c = +readline();
for (i = 0; i < c; i++) {
  x = readline();
  if (x.length % 2 === 0) {
    y = x.length;
    z = x.split("", y / 2).join("");
    q = x.substring(x.length, x.length / 2);
    if (q === z) {
      print("YES");
    } else {
      print("NO");
    }
  } else {
    print("NO");
  }
}

var strNumbers = parseInt(readline());

while(strNumbers--) {
    var str = (readline());
    var parts = [str.slice(0 , str.length / 2), str.slice(str.length / 2)];
    print(parts[0] == parts[1] ? 'YES' : 'NO');
}

var t = readline();
    for(var i = 0 ; i < t ; i++){
        var s = readline();
        if(s.length%2 !== 0){
            print('NO');
        }
        else{
            var s1 = s.slice(0 , s.length/2);
            var s2 = s.slice(s.length/2 , s.length);
            if(s1 == s2){
                print('YES');
            }
            else{
                print('NO');
            }
        }
    }

var testCase=+readline(),counter
for(var i=0;i<testCase;i++){
    var sequence=readline().split("")
    if(sequence.length%2!==0){
        print("No")
    }else{
       var a=sequence.slice(0,sequence.length/2).join("")
       var b=sequence.slice(sequence.length/2).join("")
       if(a===b){
           print("Yes")
       }else{
           print("No")
       }
    }
}

var t = parseInt(readline());

  function solve() {
    var input = readline().trim()
    if (input.length % 2 === 1) {
      return "NO"
    }
    var mid = input.length / 2
    var frist = input.slice(0, mid)
    var last = input.slice(mid)
    if (frist === last) {
      return "YES"
    } else {
      return "NO"
    }
  }

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[u] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z-1);
    b.splice(b.length,1)
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

const { readFileSync } = require("fs")

let s = readFileSync("./input.fd0138e687.txt","utf-8").match(/[a-z]+/g)

for ( let e of s )
    console.log(
        e.length % 2 === 0 &&
        e.slice(0,e.length/2) === e.slice(e.length/2) ? "YES" : "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++];
}
/* let arr = readLine().split(" ").map((x) => {return parseInt(x)});
let test = readLine();
while(test--)
{

}
*/
function main() {
    let test = readLine();
    while(test--)
    {
        let string = readLine();
        if (string.substr(0, string.length/2) === string.substr(string.length/2, string.length)){
            console.log("YES");
        }
        else
        {
            console.log("NO");
        }
    }
    return 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++];
}
/* let arr = readLine().split(" ").map((x) => {return parseInt(x)});
let test = readLine();
while(test--)
{

}
*/
function main() {
    let test = readLine();
    while(test--)
    {
        let string = readLine();
        if ((string.length)%2 === 1) {
            console.log("NO");
        }
        else{
            let string2 = string.substr(0, string.length/2);
            let string3 = string.substr(string.length/2, string.length);
            if (string2 === string3) {
                console.log("YES");
            }
            else
            {
                console.log("NO");
            }
        }
    }
    return 0;
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    const n = +(readline());
    for(let i =0; i<n; ++i){
        let s = readline();
        if(squareString(s)){
            console.log("YES")
        }
        else{
            console.log("NO")

        }
    }
}

const squareString = (s)=>{

    const n = s.length;
    const mid = Math.ceil(n/2);
    let i =0; j = mid;

    for(; i<mid && j<n; ++i,++j){
        if(s[i] != s[j])
            return false;
    }

    if(i!=mid || j!= n)
        return false;
    else
        return true;
}

var _line = '';
var _line_data;
var _current_line = 0;
process.stdin.on('data', function (input) {
    _line += input;
});
process.stdin.on('end', function () {
    _line_data = _line.split('\n').map(function (line) { return line.trim(); });
    main();
});
function readline() {
    if (_line_data.length <= _current_line) {
        throw Error('[ERROR] Nothing to read from stdin');
    }
    return _line_data[_current_line++];
}
function print(data, end) {
    if (end === void 0) { end = '\n'; }
    process.stdout.write("" + data + end);
}
// START
function main() {
    var cases = parseInt(readline());
    for (var i = 0; i < cases; i += 1) {
        var data = readline();
        var isSquared = true;
        for (var j = 0; j < data.length / 2; j += 1) {
            if (data.length % 2 !== 0 || data[j] !== data[j + Math.floor(data.length / 2)]) {
                isSquared = false;
                print("NO");
                break;
            }
        }
        if (isSquared) {
            print("YES");
        }
    }
}

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

let c = 0;

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

  const len = str.length;
  const mid = Math.ceil(len / 2);
  let ans = "YES";

  for (let i = 0; i < mid; i++) {
    if (str[i] !== str[i + mid]) {
      ans = "NO";
    }
  }

  console.log(ans);
  c++;
});

rl.on("close", () => {});

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

// LIBRARY START //

const isOdd = (x) => { return x & 1 }
const isEven = (x) => { return !(x & 1) }

const reverseText = (s) => { return s.split('').reverse().join('') }
const hasDuplicates = (str) => (/([a-z])\1/i).test(str)

const hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)

const isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);

const findAllIndicesOfChar = (str, char) => {
    str = str.split('')
    let indices = [];
    for (let i = 0; i < str.length; i++) {
        if (str[i] === char) indices.push(i);
    }
    return indices
}

const splitAt = index => x => [x.slice(0, index), x.slice(index)]

const isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)

const escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&')

const replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)

const findUnique = (str) => {
    return [...str].reduce((acc, curr) => {
        return acc.includes(curr) ? acc : acc + curr;
    }, "")
}

// LIBRARY END

const getresult = (str) => {

    if( isOdd(str.length) ) return 'NO'

    let idx = str.length / 2

    let s1 = str.substring(0, idx)
    let s2 = str.substring(idx)

    return s1 === s2 ? 'YES' : 'NO'
}

function main() {
    let testcases = parseInt( readline() )
    while( testcases-- ){

        let str = readline()
        console.log( getresult( str ) )
    }
}
//*/

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var S = next();
		if(S.length % 2 == 1){
			myout("NO");
			continue;
		}
		var L = S.substring(0, S.length / 2);
		var R = S.substring(S.length / 2, S.length);
		if(L == R){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('');
        if(k.length % 2 == 1){
            console.log('NO');
        }else{
            var a = '';
            var b = '';
            for(var l = 0; l < k.length / 2; l++){
                a += k[l];
            }
            for(var h = k.length / 2; h < k.length; h++){
                b += k[h];
            }
            if(a == b){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.nums();
	let ans = [];
	for(let  i = 0; i< t; i++){
		let s = nl.line();
		if (s.length % 2 == 0){
			let l = s.length;
			ans.push(s.substring(0, l/2) === s.substring(l/2));
		} else {
			ans.push(false);
		}
	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

process.stdin.on('end', sol);

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

  main(lines);
});

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let str;

  while (T--) {
    str = lines[index++];
    solve(str);
  }
}

function solve(str) {
  if (str.length % 2 === 0 && str.slice(0, str.length / 2) === str.slice(str.length / 2)) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}

// https://codeforces.com/problemset/problem/1619/A

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

const getLine = (function () {
  const getLineGen = (async function* () {
    for await (const line of rl) {
      yield line
    }
  })()
  return async () => {
    let next
    do {
      next = await getLineGen.next()
    } while (!next.done && next.value === '')
    return next.value
  }
})()

let solve = async () => {
  const strLine = parseInt(await getLine())
  for (let i = 0; i < strLine; i++) {
    const str = await getLine()
    let flag = true

    if (str.length % 2 != 0) {
      flag = false
    }
    for (let j = 0; j < str.length / 2; j++) {
      if (str[j] != str[j + str.length / 2]) {
        flag = false
      }
    }
    if (flag) {
      console.log('YES')
    } else {
      console.log('NO')
    }
  }
  //   process.exit()
  process.stdin.unref()
}

solve()

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  solve();
  // cmd: node cp.js < input.txt > output.txt
});
function solve() {
  let t = parseInt(readLine());
  while (t--) {
	   let inp = readLine();
     if(inp.length%2!==0){
       console.log("NO")
     }else if(inp.substring(0,inp.length/2)===inp.substring(inp.length/2, inp.length)){
       console.log("YES");
     }else{
       console.log("NO");
     }
  }
}

//------------------------------------------------------------------------------------

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
function main() {
  let num = parseInt(readline());
  while (num--) {
    let a = readline();
    if (a.length % 2 != 0) print("NO");
    else {
      let ltg = a.length / 2;
      let str1 = a.substring(0, ltg);
      let str2 = "";
      for (let i = ltg; i < a.length; i++) {
        str2 += a[i];
      }
      print(str1 == str2 ? "YES" : "NO");
    }
  }
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
let haveLineCount = false;
let lineCount;
rl.on('line', (line) => {
    if (!haveLineCount) {
        lineCount = parseInt(line.trim());
        haveLineCount = true;
    }
    else if (lineCount > 0) {
        let str = line.trim();
        if (str.length %2 != 0) {
            console.log('NO');
        }
        else {
            let half1 = str.substring(0,str.length/2);
            let half2 = str.substring(str.length/2);
            if (half1 == half2) {
                console.log('YES');
            }
            else {
                console.log('NO');
            }
        }
        lineCount--;
    }
    else {
        process.exit();
    }
})

'use-strict'

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 s = readLine();
const res = a(s);
console.log(res)
}
});

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

function a(s){
    if(s.length % 2 === 1) return 'NO'
    if(s.slice(0,s.length/2) !== s.slice(s.length/2)) return 'NO'
    return 'YES'
}

module.exports = a;

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

rl.once('line', (_) => {

  rl.on('line', (txt) => {
    // console.log(txt);
    const l = txt.length;
    const mid = (l/2).toFixed(0)
    if (l % 2 == 0 && txt.slice(0, mid) === txt.slice(mid)) {
      console.log("YES")
    }
    else {
      console.log("NO")
    }
  });
});

const readline = require("readline");

const input = [];

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let counter = 0;
rl.on("line", function (cmd) {
    counter++
   input.push(cmd);
});
rl.on("close", function (cmd) {
    for (let i=1;i<=input.length-1;i++){
      const str = input[i];
      if (str.length%2===1) {console.log("NO")}
      else{
        const string1 = str.substr(0,str.length/2)
        const string2 = str.substr(str.length/2,str.length-1)
        if (string1===string2) {console.log("YES")}
        else {console.log("NO")}
      }

    }

    process.exit(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 => {
        return string.trim();
    });

    main();
});

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

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i++) {
        let s = readline();
        if (s.length % 2 === 1) {
            console.log('NO');
        } else if (s.slice(0, s.length / 2) === s.slice(s.length / 2)) {
            console.log('YES');
        } else {
            console.log('NO');
        }
    }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
function main() {
  var num = parseInt(readline())
	while(num--){
        var a = readline()
        if(a.length % 2 != 0) print("NO")
        else{
            //print((a.substring(0, a.length/2)) == (a.substring(a.length/2,a.substring/2))?"YES":"NO")
            var ltg = a.length / 2
            var str1 = a.substring(0, ltg)
            var str2 = ''
            for(let i = ltg;i < a.length;i++){
                str2 += a[i]
            }
            print(str1 == str2?"YES":"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++];
}
function printLine(x) {
	// process.stdout.write("hello: "); // without auto '\n' (newline)
	console.log(x); // with auto '\n' (newline)
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
	const inputCount = readline();
	for (let i = 0; i < inputCount; i++) {
		exec(readline());
	}
}

function exec(input) {
	input = input.split("");
	if (input.length % 2 !== 0) {
		return printLine("NO");
	} else {
		const firstHalf = input.splice(0, input.length / 2);
		if (firstHalf.join("") === input.join("")) {
			printLine("YES");
		} else {
			printLine("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++];
}

function main() {
    let noOfTestCases = Number(readline());
    let testCaseArray = [];
    for (let i = 0; i < noOfTestCases; i++) {
        testCaseArray.push(readline());
    }

    for (let i = 0; i < noOfTestCases; i++) {
        checkSquare(testCaseArray[i])
    }
}

function checkSquare(B) {
    let len = B.length;
    if (len % 2 == 1) {
        console.log("NO");
        return;
    }
    let i = 0;
    while (i < len/2) {
        if(B[i] != B[i+len/2]) {
            console.log("NO");
            return;
        }
        i++;
    }
    console.log("YES")
}

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

let inputString = '';

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

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

    main(inputString);
});

function log(message){
    if(process.env.NODE_ENV === "debug"){
        console.log(message);
    }
}

function main(fileContents) {//input lines as an array
    // console.log(fileContents);
    fileContents.splice(0,1);
    fileContents.forEach(string => {
        if(string.length%2!==0){
            console.log("NO")
        }else{
            const indexOfHalf = string.length/2;
            const stringAsArr = string.split("")
            let isThereAMismath = false

            for(let i =0; i< indexOfHalf; i++){
                if(stringAsArr[i] !== stringAsArr[i+indexOfHalf]){
                    isThereAMismath =true;
                     break;
                }
            }

            if(isThereAMismath == false){
                console.log("YES");
            }else{
                console.log("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 s = rl();
		const n = s.length;

		let ans = false;
		if (s.slice(0, Math.floor(n/2)) == s.slice(Math.floor(n/2)))
			ans = true;

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

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

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

let count = -1
let inputArr = []

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

function solve(str) {
    const n = str.length
    if (str.slice(0, Math.floor(n / 2)) === str.slice(Math.floor(n / 2))) {
        console.log('YES')
    } else {
        console.log('NO')
    }
}

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

const readline = require('readline')

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

function solve(str) {
    if (str.length & 1) return false
    const limit = str.length / 2
    for (let i = 0; i < limit; i++) {
        if (str[i] !== str[limit + i]) return false
    }
    return true
}

var n = parseInt(readline());
while (n -- > 0) {
    var str = readline();
    var flag = str.length % 2 == 0;
    for (var i = 0; i < str.length / 2; i++) {
        flag = flag & (str[i] == str[i + str.length / 2]);
    }
    print(flag ? "YES" : "NO");
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r == j) {
    	    console.log(r)
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   p += a[u];
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline().split('');
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r == j) {
    	    console.log(r);
    	    console.log(j)
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r == j) {
    	    console.log(r);
    	    console.log(j)
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u];
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r == j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    	    console.log(r);
    	    console.log(j);
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    	    console.log(r)
    	    console.log(j)
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	console.log(r)
    	console.log(j)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    console.log(y)
    if(y == true) console.log('YES')
    else console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = '';
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	   else console.log(a[u])
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	console.log(p)
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    console.log(a)
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   if(a[i] !== '\r') p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline().split('');
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   p += a[u]
    	}
    	return p;
    }
    console.log(a)
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline().split('');
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	if(r == j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
                    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline();
    var y = false;
    for(var i=0;i<a.length;i++) {
    	var r = re(0, i)
    	var j = re(i+1, a.length-1)
    	console.log(r)
    	console.log(j)
    	if(r === j) {
    		y = true;
    		break;
    	}
    }
    function re(x,t) {
    	var p = ''
    	for(var u=x;u<=t;u++) {
    	   p += a[u]
    	}
    	return p;
    }
    y ? console.log('YES') : console.log('NO')
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z-1);
    b.splice(b.length,1)
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');

  console.log(a,b);

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z);
    b.splice(b.length,1)
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');

  console.log(a,b);

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z);
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');

  console.log(a,b);

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z);
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');
  f===g;
  console.log(f,g);

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z);
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');

  console.log(f,g);

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
  let s=[];

  for(let i=0;i<x;i++){
    let y=readline().split("");
    let z=y.length;
    let a=y.slice(0,z/2);
    let b=y.slice(z/2,z);
    let f=a.join("");
    let g=b.join("");
    if(f===g) s.push('YES');
    else if(f!==g) s.push('NO');

  //console.log(f,g);

  }

  for(let i=0;i<s.length;i++){
    console.log(s[i]);

  }
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];

for(let i=0;i<x;i++){
  let y=readline().split("");
  let z=y.length;
  let a=y.slice(0,z/2);
  let b=y.slice(z/2,z);
  let f=a.join("");
  let g=b.join("");
  if(f==g) s.push('YES');
  else s.push('NO');

//console.log(f,g);

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}

}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];

for(let i=0;i<x;i++){
  let y=readline().split("");
  let z=y.length;
  let a=y.slice(0,z/2);
  let b=y.slice(z/2,z);
  let f=a.join(",");
  let g=b.join(",");
  if(f=g) s.push('YES');
  else s.push('NO');

//console.log(a,b);

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];

for(let i=0;i<x;i++){
  let y=readline().split("");
  let z=y.length;
  let a=y.slice(0,z/2);
  let b=y.slice(z/2,z);
  let f=a.join(",");
  let g=b.join(",");
  if(f==g) s.push('YES');
  else s.push('NO');

//console.log(a,b);

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];

for(let i=0;i<x;i++){
  let y=readline().split("");
  let z=y.length;
  let a=y.slice(0,z/2);
  let b=y.slice(z/2,z);
  let c=a.join(",");
  let d=b.join(",");
  if(c===d) s.push('YES');
  else s.push('NO');

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

   "use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];

for(let i=0;i<x;i++){
  let y=readline().split("");
  let z=y.length;
  let a=y.slice(0,z/2);
  let b=y.slice(z/2,z);
  let c=a.join(",");
  let d=b.join(",");
  if(c==d) s.push('YES');
  else if(c!=d) s.push('NO');

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

"use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];
for(let i=0;i<x;i++){
  let y=readline().split("");
  let a=y.slice(0,y.length/2);
  let b=y.slice(y.length/2,y.length);
  let c=a.join(",");
  let d=b.join(",");
  if(c===d) s.push('YES');
  else if(c!==d) s.push('NO');

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

"use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];
for(let i=0;i<x;i++){
  let y=readline().split("");
  let a=y.slice(0,y.length/2);
  let b=y.slice(y.length/2,y.length);
  if(a.join(",")===b.join(",")) s.push('YES');
  else if(a.join(",")!==b.join(",")) s.push('NO');

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

"use strict";

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

const x=+readline();
let s=[];
for(let i=0;i<x;i++){
  let y=readline().split("");
  let a=y.slice(0,y.length/2);
  let b=y.slice(y.length/2,y.length);
  if(a.join(",")==b.join(",")) s.push('YES');
  else if(a.join(",")!=b.join(",")) s.push('NO');

}

for(let i=0;i<s.length;i++){
  console.log(s[i]);

}
}

const { readFileSync } = require("fs")

let [a,...s] = readFileSync("./input.fd0138e687.txt","utf-8").split(/\r\n/)

for ( let i = 0; i < s.length; ++i )
    console.log(
        (l=s[i].length) % 2 === 0 && s[i].slice(0,l/2) === s[i].slice(l/2) ? "YES" : "NO"
    )

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    const n = +(readline());
    console.log(n)
    for(let i =0; i<n; ++i){
        let s = readline();
        if(squareString(s)){
            console.log("YES")
        }
        else{
            console.log("NO")

        }
    }
}

const squareString = (s)=>{

    const n = s.length;
    const mid = Math.ceil(n/2);
    let i =0; j = mid;

    for(; i<mid && j<n; ++i,++j){
        if(s[i] != s[j])
            return false;
    }

    if(i!=mid || j!= n)
        return false;
    else
        return true;
}

var len = readline();
for(var i=0;i<+len;i++)
{
 var inputData = readline();
 if(inputData.length%2 !=0)
 print("NO");
 else if((inputData.length == 2) && (inputData[0]!=inputData[1]))
    print("NO");
 else if((inputData.substring(0,(inputData.length/2)-1))  ==  (inputData.substring(inputData.length/2,inputData.length-1)))
  print("YES");
  else
   print("NO");
}

var len = readline();
for(var i=0;i<+len;i++)
{
 var inputData = readline();
 if(inputData.length%2 !=0)
 print("NO");
 else if((inputData.substring(0,(inputData.length/2)-1))  ==  (inputData.substring(inputData.length/2,inputData.length-1)))
  print("YES");
  else
   print("NO");
}

var len = readline();
for(var i=0;i<+len;i++)
{
 var inputData = readline();
 if(inputData.length%2 !=0)
 print("NO");
 else if(inputData.substring(0,(inputData.length/2)-1)  ==  inputData.substring(inputData.length/2,inputData.length-1))
  print("YES");
  else
   print("NO");
}


var parts = [];
var numberOfParts = parseInt(readline());

for (var i = 0; i < numberOfParts; i++) {
    parts.push(readline());
}
var stopPage = parseInt(readline());

for (var i = 0; i < numberOfParts; i++) {
    var e = parseInt(parts[i].split(' ')[1]);

    if (stopPage <= e) {
        print(numberOfParts - i);
        break;
    }
}

let line = '';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (input) {
	line += (input.trim() + '\n');
});

process.stdin.on('end', function () {
	line = line.split(/\n/).map(l => l.replace(/\r/, ''));

	const n = Number(line[0]);
	const k = Number(line[n + 1]);
	let length = 0;

	for(let i = 1; i < line.length - 2; i++) {
		const [ s, e ] = line[i].split(' ');

		if (Number(s) <= k && k <= Number(e)) {
			break;
		} else {
			length++;
		}
	}

	console.log(n - length);

	process.exit(0);
});

const n = readline();
const segs = [];
for (var i = 0; i < n; i++) {
	segs.push(readline().split(" "));
}
var now = readline();
var result = 0;
for (var i = 0; i < n; i++) {
	if (Number(segs[i][1]) >= now) {
		result++;
	}
}
print(result);

var n = parseInt(readline())

var ar = []
for(var t=0;t<n;t++) {
    var a = readline().split(' ').map((v)=>(parseInt(v)))
    ar.push({s: a[0], e: a[1]})
}

var K = parseInt(readline())

var res = 0;
ar.forEach((it) => {

    if (K<it.s || (it.s<=K && K<=it.e)) {
        res++;
    }
})

print(res);

var ip = [], c = readline();
while(c) {
    ip.push(c.split(' '));
    c = readline();
}
var tc = parseInt(ip[0]), id = ip.pop(), p = 0;
for (var i = 1; i < ip.length; i++) {
    if (id <= parseInt(ip[i][1])){
        p = i;
        break;
    }
}
print(ip.length - p )

var n = parseInt(readline());
var segs = Array();
for(var i = 0; i < n; i++){
	segs.push(readline().split(' ').map(x => parseInt(x)));
}
var k = parseInt(readline());
var index = segs.findIndex(seg => (k >= seg[0] && k <= seg[1]));
print(n - index);

var chapterCounter = parseInt(readline());
var chapters = [];

for (var i = 0; i < chapterCounter; i++) {
  var chapter = readline().split(' ').map(function (num) {
    return parseInt(num);
  })
  chapters.push(chapter);
}

var index = parseInt(readline());

// var chapterCounter = 3
// var chapters = [[1,4],[5,9],[10,12]];
// var index = 9;

function main() {
  var chaptersFinished = 0;
  for (var i = 0; i < chapters.length; i++) {
    if (index < chapters[i][1] + 1) {
      return (chapterCounter - chaptersFinished + '');
    } else if (index === chapters[i][1] + 1) {
      return (chapterCounter - chaptersFinished - 1 + '');
    } else {
      chaptersFinished++;
    }
  }
  return 0;
}

write(main());

//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 N = nextInt();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = nextIntArray();
	}
	var K = nextInt();
	var output = 0;
	var ng = false;
	for(var i = 0; i < N; i++){
		if(list[i][0] <= K && K <= list[i][1]){
			ng = true;
		}
		if(ng){
			output++;
		}
	}
	myout(output);
}

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

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

  if (c <= lines) {
    chapters.push(d.split(' ').map(Number));
  }

  if (c > lines) {
    const k = +d;
    let ans = chapters.length;

    for (let i = 0; i < chapters.length; i++) {
      const [start, finish] = chapters[i];

      if (k >= start && k <= finish) {
        break;
      }

      ans--;
    }

    console.log(ans);
  }

  c++;
});

let input = [];

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

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

RL.on('close', () => {
    let n = parseInt(input[0]);

    let parts = [];
    for(let i = 0; i < n; i++){
        let pages = []; input[i+1].split(' ').forEach( j => pages.push(parseInt(j)) );
        parts.push(pages);
    }
    let k = parseInt(input[n+1]);

    for(let i = 0; i < n; i++){
        if(k >= parts[i][0] && parts[i][1] >= k){
            console.log(parts.length-i);
            break;
        }
    }
});


var s = readline().split(""),
	n = readline(),
	a = [], v;
for (var i in s) {
	if (a.indexOf(s[i]) == -1) {
		a.push(s[i]);
    }
}
if (n <= s.length) {
	v = n - ((a.length > n) ? n : a.length);
} else {
	v = "impossible"
}
print(v);

//function readline(){
//	yield "";
//}

var str = readline().split('');
var lena = 0;
var cnt = [];
for(var chr in str){
	if(!cnt[str[chr]]){
		lena++;
		cnt[str[chr]]=1;
	}
}
//console.log(cnt);
//console.log(typeof(cnt));
//console.log(lena);

var n = parseInt(readline());
if(lena >= n){
	print(0);
}else if(str.length < n){
	print("impossible");
}else{
	print(n - lena);
}

var s = readline().split('');
var n = parseInt(readline());

if(s.length<n)
print('impossible');
else{
    var uniques = s.reduce(function(singles,char){
        if(singles.indexOf(char)==-1)
            singles.push(char);
        return singles;
    },[]);
    print(Math.max(0,n-uniques.length))
}

var str = readline().split('');
var lena = 0;
var cnt = [];
for(var chr in str){
	if(!cnt[str[chr]]){
		lena++;
		cnt[str[chr]]=1;
	}
}
var n = parseInt(readline());
if(lena >= n){
	print(0);
}else if(str.length < n){
	print("impossible");
}else{
	print(n - lena);
}

var str = readline(),
	n = parseInt(readline());
if (n > str.length)
	print("impossible");
else {
	var foo = str.replace(/(.)(?=.*\1)/g, "");
	print(str.length - foo.length);
}

var str = readline(),
	n = parseInt(readline());
if (n > str.length)
	print("impossible");
else {
	var g = str.replace(/(.)(?=.*\1)/g, ""),
	    e = str.length - g.length;
	    print((e > n) ? n : e);
	print();
}


var n = parseInt(readline())
var p = []
var q = []
for (i = 0; i < n; i++) {
  var line = readline().split(' ')
  p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}
  q[i] = p[i].x
  q[i+n] = p[i].y
}
p.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})
var ans = 0
for (aa in q) {
  var a=q[aa]
  var now = 0
  var ok = true
  for (bb in p) {
    b=p[bb]
    if (b.y > a && b.x > a) {
      ok = false
      break
    }
    if (b.y > a ) {
      now++
    }
  }
  if (!ok) {
    continue
  }
  if (now>n/2) {
    continue
  }
  var nowans = 0
  var ms = []
  for (bb in p) {
    b = p[bb]
    if (now+1 <= n/2 && b.x <= a && b.y < b.x) {
      now++;
      nowans+=b.y
      ms.push(b)
    } else if (b.y>a){
      nowans+=b.y
    } else {
      nowans+=b.x
    }
  }
  if (ans <=0 || (nowans*a < ans)) {
    ans = nowans*a
  }
}
print(ans)

var n = parseInt(readline())
var p = [], q=[]
for (i = 0; i < n; i++) {
  var line = readline().split(' ')
  p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}
  q.push(p[i].x, p[i].y)
}
p.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})
minh = p.reduce(function(a,b) { return Math.max(a, Math.min(b.x,b.y))}, 0)
print(Math.min.apply(Math,q.map(function(a) {
  var now = p.reduce(function(x,y) {
    return x + (y.y > a ? 1:0)
  }, 0)
  if (a < minh || now > n/2) {
    return Number.MAX_VALUE
  }
  return  p.reduce(function(x,b) {
      if (now+1 <= n/2 && b.x <= a && b.y < b.x) {
        now++;
        return x+b.y
      } else if (b.y>a){
        return x+b.y
      } else {
        return x+b.x
      }
  },0) * a
})))

var n = parseInt(readline())
var p = [], q=[]
for (i = 0; i < n; i++) {
  var line = readline().split(' ')
  p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}
  q.push(p[i].x, p[i].y)
}
p.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})
minh = p.reduce(function(a,b) { return Math.max(a, Math.min(b.x,b.y))}, 0)
print(Math.min.apply(Math,q.map(function(a) {
  var now = p.reduce(function(x,y) {
    if (y.y > a) {
      return x+1
    }
    return x
  }, 0)
  if (a < minh || now > n/2) {
    return Number.MAX_VALUE
  }
  return  p.reduce(function(x,b) {
      if (now+1 <= n/2 && b.x <= a && b.y < b.x) {
        now++;
        return x+b.y
      } else if (b.y>a){
        return x+b.y
      } else {
        return x+b.x
      }
  },0) * a
})))

var n = parseInt(readline())
var p = []
var q = []
for (i = 0; i < n; i++) {
  var line = readline().split(' ')
  p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}
  q[i] = p[i].x
  q[i+n] = p[i].y
}
p.sort(function(a,b) { return (b.y-b.x) - (a.y-a.x)})
var ans = 0
for (aa in q) {
  var a=q[aa]
  var now = 0
  var ok = true
  for (bb in p) {
    b=p[bb]
    if (b.y > a && b.x > a) {
      ok = false
      break
    }
    if (b.y > a ) {
      now++
    }
  }
  if (!ok) {
    continue
  }
  if (now>n/2) {
    continue
  }
  var nowans = 0
  for (bb in p) {
    b = p[bb]
    if (now < n/2 && b.y <= a && b.x <= a && b.y < b.x) {
      now++;
      nowans+=b.y
    } else if (b.y>a){
      nowans+=b.y
    } else {
      nowans+=b.x
    }
  }
  if (ans <=0 || (nowans*a < ans)) {
    ans = nowans*a
  }
}
print(ans)

var n = parseInt(readline())
var p = []
var q = []
for (i = 0; i < n; i++) {
  var line = readline().split(' ')
  p[i] = {x:parseInt(line[0]), y:parseInt(line[1])}
  q.push(p[i].x, p[i].y)
}
p.sort(function(a,b) { return (b.x-b.y) - (a.x-a.y)})
minh = p.reduce(function(a,b) { return Math.max(a, Math.min(b.x,b.y))}, 0)
var ans = 0
var all = q.map(function(a) {
  var now = p.reduce(function(x,y) {
    return x + y.y > a ? 1:0
  }, 0)
  if (a < minh || now > n/2) {
    return Number.MAX_VALUE
  }
  return  p.reduce(function(x,b) {
      if (now+1 <= n/2 && b.x <= a && b.y < b.x) {
        now++;
        return x+b.y
      } else if (b.y>a){
        return x+b.y
      } else {
        return x+b.x
      }
  },0) * a
})
print(Math.min.apply(Math, all))


'use strict';

var fs = require('fs');

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

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

class SegTree {
  constructor(l, r) {
    this.l = l;
    this.r = r;
    this.root = this._newNode(l, r);
    this.update = this._update.bind(this, this.root);
    this.query = this._query.bind(this, this.root);
  }

  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return {
      val,
      l,
      r,
      left,
      right
    };
  }

  _update(node, x, y, z) {
    if (!node) return;
    const {
      l,
      r
    } = node;

    if (l === x && r === y) {
      node.val[z % 3]++;
      return;
    }

    const mid = Math.floor((l + r) / 2);

    if (!node.left) {
      node.left = this._newNode(l, mid);
      node.right = this._newNode(mid + 1, r);
    }

    if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);

    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i];
  }

  _query(node, x, y, z) {
    if (y < x) return 0;
    if (!node) return 0;
    const {
      l,
      r
    } = node;
    if (l === x && r === y) return node.val[z];
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (y <= mid) res = this._query(node.left, x, y, z);else if (x > mid) res = this._query(node.right, x, y, z);else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z);
    return res;
  }

}

function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
      sum = 0,
      max = 0,
      min = 0;

  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0;
    pre[i + 1] = i + 1 - 2 * sum;
    max = Math.max(max, pre[i + 1]);
    min = Math.min(min, pre[i + 1]);
  }

  let res = 0;
  const segTree = new SegTree(min, max);

  for (let i = 0; i <= n; i++) {
    const cur = pre[i];
    res += segTree.query(min, cur, (cur % 3 + 3) % 3);
    segTree.update(cur, cur, (cur % 3 + 3) % 3);
  }

  return res;
}

// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\n')

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function main() {
  let t = Number(inputs[0]),
      __ = 1,
      res = [];

  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++]);
    let str = inputs[__++].trim();
    res.push(solve(n, str));
  }

  console.log(res.join('\n'));
}();

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

class SegTree {
  constructor(l, r) {
    this.l = l
    this.r = r
    this.root = this._newNode(l, r)
    this.update = this._update.bind(this, this.root)
    this.query = this._query.bind(this, this.root)
  }
  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return { val, l, r, left, right }
  }
  _update(node, x, y, z) {
    if (!node) return
    const { l, r } = node
    if (l === x && r === y) {
      node.val[z % 3]++
      return
    }
    const mid = Math.floor((l + r) / 2)
    if (!node.left) {
      node.left = this._newNode(l, mid)
      node.right = this._newNode(mid + 1, r)
    }
    if (y <= mid) this._update(node.left, x, y, z)
    else if (x > mid) this._update(node.right, x, y, z)
    else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)
    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]
  }
  _query(node, x, y, z) {
    if (y < x) return 0
    if (!node) return 0
    const { l, r } = node
    if (l === x && r === y) return node.val[z]
    let res = 0,
      mid = Math.floor((l + r) / 2)
    if (y <= mid) res = this._query(node.left, x, y, z)
    else if (x > mid) res = this._query(node.right, x, y, z)
    else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)
    return res
  }
}
function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
    sum = 0,
    max = 0,
    min = 0
  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0
    pre[i + 1] = i + 1 - 2 * sum
    max = Math.max(max, pre[i + 1])
    min = Math.min(min, pre[i + 1])
  }
  let res = 0
  const segTree = new SegTree(min, max)
  for (let i = 0; i <= n; i++) {
    const cur = pre[i]
    res += segTree.query(min, cur, ((cur % 3) + 3) % 3)
    segTree.update(cur, cur, ((cur % 3) + 3) % 3)
  }
  return res
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    let str = inputs[__++].trim()
    res.push(solve(n, str))
  }
  console.log(res.join('\n'))
})()


var f=readline();
for(var i=0;i<f;i++){
  var cnt=0;
  var t=readline();
  var y=readline();
  for(var j=0;j<y.length;j++){
    if(y[j]!=y[j+1]){
      cnt+=j+1;
    }
  }
  print(cnt);
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        let size = readline();
        let str = readline();

        let result = 1;
        for (let i = 1; i < size; i++) {
            if (str[i] === str[i - 1]) {
                result += 1;
            } else {
                result += i + 1;
            }
        }

        output(result);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    const cases = readline();

    for (let i = 0; i < cases; i++) {
        const size = readline();
        const n = readline();
        let total = 0;
        n.split('').forEach((digit, index) => {
            if (digit === n[index - 1]) {
                total++;
            } else {
                total += index + 1;
            }
        });
        output(total);
    }
}

let ryan = '';//.map(saer).sort(function(a, a){return a - a})
process.stdin.on('data', c => ryan += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = ryan.split(EOL);
    var n = lines[0], e = 0
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = Number(lines[i])
        }else{
            var k = lines[i].split('').map(Number)
            ,s = e;
            for(j = 1; j < e; j++){
                if(k[j] != k[j - 1]){
                    s += j
                }
            }
            console.log(s)
        }
    }

});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = Number(lines[i]);
        }else{
            var a = lines[i].split('').map(Number);
            var num = n;
            for(j = 1; j < n; j++){
                if(a[j] != a[j - 1]){
                    num += j;
                }
            }
            console.log(num);
        }
    }
});

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline().trim().split("");
    let cnt = 0;
    for (let i = n - 1; i >= 1; i--) {
      if (arr[i] !== arr[i - 1]) {
        cnt += i;
      }
    }
    console.log(cnt + n);
  }
};
solve();

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var n = readline();
  var a = readline();
  var cnt=1;
  for(var i=1;i<n;i++){
        if(a[i]!=a[i-1])
           cnt+=i+1;
        else
           cnt++;
  }

  console.log(cnt)

}

'use strict';

function solve(n, s) {
  let res = n;
  for (let i = 1; i < n; i++) {
    if (s[i] === s[i - 1]) continue;
    res += i;
  }
  return res;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const s = await read();
      res[i] = solve(n, s);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

var t = readline();
for(var j = 0; j < t; j++){
    var n = readline();
    var s = readline();
    var cnt = 0;
    for(var i = 1; i < s.length; i++){
        if(s[i]!=s[i-1]){
            cnt+=i;
        }
    }
    print(cnt+n);
}

var t = readline();
for(var j = 0; j < t; j++){
    var n = readline();
    var s = readline();
    var cnt = n;
    for(var i = 1; i < s.length; i++){
        if(s[i]!=s[i-1]){
            cnt+=i;
        }
    }
    print(cnt);
}

var t = readline();
while(t--){
    var n = readline();
    var s = readline();
    var cnt = n;
    for(var i = 1; i < s.length; i++){
        if(s[i]!=s[i-1]){
            cnt+=i;
        }
    }
    print(cnt);
}

var t = readline()
while(t--){
    var n = readline()
    var s = readline()
    var cnt = n
    for(var i = 1; i < s.length; i++){
        if(s[i]!=s[i-1]){
            cnt+=i
        }
    }
    print(cnt)
}

var t = readline()
while(t--){
    var n = readline()
    var s = readline()
    var cnt = n
    for(var i = 1; i < s.length; i++){
        if(s[i]!=s[i-1]){
            cnt+=i
        }
    }
    print(cnt+'\n')
}


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        let n, m, k, grid = [];
        [n, m, k] = readline().split(" ");
        for(let i = 0; i < Number(n); i++) {
            grid.push(readline());
        }
        if(ticks(grid, Number(n), Number(m), Number(k))) console.log("YES");
        else console.log("NO");
    }
}

function ticks(grid, n, m, k) {
    for(let x = 0; x < n; x++) {
        for(let y = 0; y < m; y++) {
            if(grid[x][y] == "*" && !(findAParent(grid, x, y, n, m, k)||createParent(grid, x, y, n, m, k))) {
                return false;
            }
        }
    }
    return true;
}

function createParent(grid, x, y, n, m, k) {
    //create right side children
    let rx = x, ry = y, numOfRSChilds = 0;
    while(0 < rx && ry < m - 1 && numOfRSChilds < k) {
        rx--;
        ry++;
        if(grid[rx][ry] == ".") return false;
        if(grid[rx][ry] == "*") numOfRSChilds++;
    }
    //create left side children
    let lx = x, ly = y, numOfLSChilds = 0;
    while(0 < lx && 0 < ly && numOfLSChilds < k) {
        lx--;
        ly--;
        if(grid[lx][ly] == ".") return false;
        if(grid[lx][ly] == "*") numOfLSChilds++;
    }
    return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == k);
}

function findAParent(grid, x, y, n, m, k) {
    //check the positive diagnol
    let rx = x, ry = y;
    while(rx < n - 1 && ry < m - 1) {
        rx++;
        ry++;
        if(grid[rx][ry] == "*" && parent(grid, rx, ry, n, m, Math.max(k, (rx - x)))) {
            return true;
        }
    }
    //check the negative diagnol
    let lx = x, ly = y;
    while(lx < n - 1 && 0 < ly) {
        lx++;
        ly--;
        if(grid[lx][ly] == "*" &&parent(grid, lx, ly, n, m, Math.max(k, (lx - x)))) return true;
    }
    return false;
}

function parent(grid, x, y, n, m, numOfChilds) {
    //create right side children
    let rx = x, ry = y, numOfRSChilds = 0;
    while(0 < rx && ry < m - 1 && numOfRSChilds < numOfChilds) {
        rx--;
        ry++;
        if(grid[rx][ry] == ".") return false;
        if(grid[rx][ry] == "*") numOfRSChilds++;
    }
    //create left side children
    let lx = x, ly = y, numOfLSChilds = 0;
    while(0 < lx && 0 < ly && numOfLSChilds < numOfChilds) {
        lx--;
        ly--;
        if(grid[lx][ly] == ".") return false;
        if(grid[lx][ly] == "*") numOfLSChilds++;
    }

    return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == numOfChilds);
}

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

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

function main () {
	let T = rn();
	while (T--) {
		let [n, m, k] = rna();
		let g = Array.from(Array(n), x => Array(m));

		for (let i in g) {
			g[i] = rl().split('');
		}

		for (let i in g) {
			for (let j in g[i]) {
				g[i][j] = g[i][j] == '*' ? 1 : 0;
			}
		}

		for (let i = n - 1; i >= k; i--) {
			for (let j = k; j < m - k; j++) {
				if (g[i][j]) {
					let d = 1;
					while(i-d >= 0 && j-d >= 0 && j+d < m && g[i-d][j-d] && g[i-d][j+d])
						d++;
					d--;
					if (d >= k) {
						while (d >= 0) {
							g[i-d][j-d] = g[i-d][j+d] = 2;
							d--;
						}
					}
				}
			}
		}

		let ans = true;
		for (let i in g)
			for (let j in g[i])
				ans = ans && g[i][j] != 1;

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

function main() {
    const t = Number(readline()), grid = [];
    let n, m, k;
    [n, m, k] = readline().split(" ");
    for(let i = 0; i < Number(n); i++) {
        grid.push(readline());
    }
    if(ticks(grid, Number(n), Number(m), Number(k))) console.log("YES");
    else console.log("NO");
}

function ticks(grid, n, m, k) {
    for(let x = 0; x < n; x++) {
        for(let y = 0; y < m; y++) {
            if(grid[x][y] == "*" && !(findAParent(grid, x, y, n, m, k)||createParent(grid, x, y, n, m, k))) {
                return false;
            }
        }
    }
    return true;
}

function createParent(grid, x, y, n, m, k) {
    //create right side children
    let rx = x, ry = y, numOfRSChilds = 0;
    while(0 < rx && ry < m - 1 && numOfRSChilds < k) {
        rx--;
        ry++;
        if(grid[rx][ry] == ".") return false;
        if(grid[rx][ry] == "*") numOfRSChilds++;
    }
    //create left side children
    let lx = x, ly = y, numOfLSChilds = 0;
    while(0 < lx && 0 < ly && numOfLSChilds < k) {
        lx--;
        ly--;
        if(grid[lx][ly] == ".") return false;
        if(grid[lx][ly] == "*") numOfLSChilds++;
    }
    return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == k);
}

function findAParent(grid, x, y, n, m, k) {
    //check the positive diagnol
    let rx = x, ry = y;
    while(rx < n - 1 && ry < m - 1) {
        rx++;
        ry++;
        if(grid[rx][ry] == "*" && parent(grid, rx, ry, n, m, Math.max(k, (rx - x)))) {
            return true;
        }
    }
    //check the negative diagnol
    let lx = x, ly = y;
    while(lx < n - 1 && 0 < ly) {
        lx++;
        ly--;
        if(grid[lx][ly] == "*" &&parent(grid, lx, ly, n, m, Math.max(k, (lx - x)))) return true;
    }
    return false;
}

function parent(grid, x, y, n, m, numOfChilds) {
    //create right side children
    let rx = x, ry = y, numOfRSChilds = 0;
    while(0 < rx && ry < m - 1 && numOfRSChilds < numOfChilds) {
        rx--;
        ry++;
        if(grid[rx][ry] == ".") return false;
        if(grid[rx][ry] == "*") numOfRSChilds++;
    }
    //create left side children
    let lx = x, ly = y, numOfLSChilds = 0;
    while(0 < lx && 0 < ly && numOfLSChilds < numOfChilds) {
        lx--;
        ly--;
        if(grid[lx][ly] == ".") return false;
        if(grid[lx][ly] == "*") numOfLSChilds++;
    }

    return (numOfRSChilds == numOfLSChilds) && (numOfRSChilds == numOfChilds);
}


'use strict';

function solve(n, a) {
  const l = new Array(n),
        r = new Array(n);
  const f = [1, 1];
  for (let i = 2; i < n; i++) f[i] = f[i - 1] * i;
  const segTree = new SegTree(n);
  let stack = [];
  for (let i = 0; i < n; i++) {
    if (!stack.length || a[stack[stack.length - 1]] > a[i]) {
      stack.push(i);
      l[i] = i;
    } else {
      const left = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);
      l[i] = stack[left];
    }
  }
  stack = [];
  for (let i = n - 1; i >= 0; i--) {
    if (!stack.length || a[stack[stack.length - 1]] > a[i]) {
      stack.push(i);
      r[i] = i;
    } else {
      const right = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);
      r[i] = stack[right];
    }
  }
  const indexs = [];
  for (let i = 0; i < n; i++) {
    if (l[i] === i || r[i] === i) segTree.update(i, i, 1);else indexs.push(i);
  }
  indexs.sort((x, y) => a[x] - a[y]);
  let res = 1;
  for (let i of indexs) {
    const left = l[i] + 1,
          right = r[i] - 1;
    res = mul(res, right - left + 1 - segTree.query(left, right));
    segTree.update(i, i, 1);
  }
  return res;
}
function binarySearch(arr, l, r, comp) {
  while (l < r) {
    const m = l + r >> 1;
    if (comp(m)) l = m + 1;else r = m;
  }
  return l;
}
const MOD = 10 ** 9 + 7;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, y, z) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      this._update(this.root, 0, n, x, y, z);
    };
    this.query = (x, y) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      return this._query(this.root, 0, n, x, y);
    };
  }
  _newNode(val = 0, left = null, right = null) {
    return {
      val,
      left,
      right,
      add: 0
    };
  }
  _down(node, l, r) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    const mid = Math.floor((l + r) / 2);
    left.add += node.add;
    left.val += node.add * (mid - l + 1);
    right.add += node.add;
    right.val += node.add * (r - mid);
    node.add = 0;
  }
  _up(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    node.val = left.val + right.val;
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.add += z;
      node.val += z * (r - l + 1);
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
    this._up(node);
  }
  _query(node, l, r, x, y) {
    if (y < x) return 0;
    if (!node) return 0;
    if (l === x && r === y) return node.val;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    this._down(node, l, r);
    if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = this._query(node.left, l, mid, x, mid) + this._query(node.right, mid + 1, r, mid + 1, y);
    this._up(node);
    return res;
  }
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();
    let mod = 10 ** 9 + 7;

    for (let test = 0; test < N; test++) {
        let size = Number(readline());
        let arr = readline().split(' ').map(Number);
        let pos = {};
        arr.forEach((num, i) => pos[num] = i);

        let result = 1;
        let left = pos[0] > pos[1] ? pos[1] : pos[0];
        let right = pos[0] > pos[1] ? pos[0] : pos[1];
        for (let i = 2; i < size; i++) {
            if (pos[i] > left && pos[i] < right) {
                result *= right - left + 1 - i;
            } else if (pos[i] < left) {
                left = pos[i];
            } else if (pos[i] > right) {
                right = pos[i];
            }
            result = result % mod;
        }

        output(result);
    }
}

'use strict';

function solve(n, a) {
  const l = new Array(n),
        r = new Array(n);
  const f = [1, 1];
  for (let i = 2; i < n; i++) f[i] = f[i - 1] * i;
  let stack = [];
  for (let i = 0; i < n; i++) {
    if (!stack.length || a[stack[stack.length - 1]] > a[i]) {
      stack.push(i);
      l[i] = i;
    } else {
      const left = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);
      l[i] = stack[left];
    }
  }
  stack = [];
  for (let i = n - 1; i >= 0; i--) {
    if (!stack.length || a[stack[stack.length - 1]] > a[i]) {
      stack.push(i);
      r[i] = i;
    } else {
      const right = binarySearch(stack, 0, stack.length - 1, j => a[stack[j]] > a[i]);
      r[i] = stack[right];
    }
  }
  const sum = [];
  for (let i = 0; i < n; i++) {
    var _sum;
    sum[i] = (_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0;
    if (l[i] === i || r[i] === i) sum[i]++;
  }
  let res = 1,
      pre = -1;
  for (let i = 0, j = 0; i < n; i = ++j) {
    if (l[i] === i || r[i] === i) continue;
    const arr = [i];
    while (j + 1 < n && r[j + 1] !== j + 1 && l[j + 1] !== j + 1) {
      j++;
      arr.push(j);
    }
    arr.sort((x, y) => a[x] - a[y]);
    pre = i - 1;
    for (let k of arr) {
      res = mul(res, r[k] - pre - 1 - (sum[r[k] - 1] - sum[pre]));
      pre++;
    }
  }
  return res;
}
function binarySearch(arr, l, r, comp) {
  while (l < r) {
    const m = l + r >> 1;
    if (comp(m)) l = m + 1;else r = m;
  }
  return l;
}
const MOD = 10 ** 9 + 7;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = nextIntArray();
        var a = one[0];
        var b = one[1];
        var c = one[2];
        var d = one[3];
        var two = nextIntArray();
        var x = two[0];
        var y = two[1];
        var x1 = two[2];
        var y1 = two[3];
        var x2 = two[4];
        var y2 = two[5];
        if((x1 == x2 && (a > 0 || b > 0)) || (y1 == y2 && (c > 0 || d > 0))){
          output[i] = "NO";
        }else{
          var diffX = x + (b - a);
          var diffY = y + (d - c);
          if(diffX >= x1 && diffX <= x2 && diffY >= y1 && diffY <= y2){
            output[i] = "YES";
          }else{
            output[i] = "NO";
          }
        }
    }
    myout(myconv(output,9));
}

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

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

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

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

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

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

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

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

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

function main() {
  let t = readInt()
  while (t--) {
    const [a, b, c, d] = readInts()
    let [x, y, x1, y1, x2, y2] = readInts()
    if (a > 0 && b > 0 && x - 1 < x1 && x + 1 > x2) {
      wr('NO')
      continue
    }
    if (c > 0 && d > 0 && y - 1 < y1 && y + 1 > y2) {
      wr('NO')
      continue
    }
    let left = 0
    let right = 0
    let up = 0
    let down = 0
    if (a > b) left = a - b
    if (b > a) right = b - a
    if (c > d) down = c - d
    if (d > c) up = d - c
    if (left > 0) x -= left
    if (right > 0) x += right
    if (up > 0) y += up
    if (down > 0) y -= down
    if (x1 <= x && x <= x2 && y1 <= y && y <= y2) wr('YES')
    else wr('NO')
  }
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = nextIntArray();
        var a = one[0];
        var b = one[1];
        var c = one[2];
        var d = one[3];
        var two = nextIntArray();
        var x = two[0];
        var y = two[1];
        var x1 = two[2];
        var y1 = two[3];
        var x2 = two[4];
        var y2 = two[5];
        if((x1 == x2 && (a > 0 || b > 0))|| (y1 == y2 && (c > 0 || d > 0))){
          output[i] = "NO";
        }else{
          var diffX = b - a;
          var diffY = d - c;
          if(diffX >= x1 && diffX <= x2 && diffY >= y1 && diffY <= y2){
            output[i] = "YES";
          }else{
            output[i] = "NO";
          }
        }
    }
    myout(myconv(output,9));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = nextIntArray();
        var a = one[0];
        var b = one[1];
        var c = one[2];
        var d = one[3];
        var two = nextIntArray();
        var x = two[0];
        var y = two[1];
        var x1 = two[2];
        var y1 = two[3];
        var x2 = two[4];
        var y2 = two[5];
        if(x1 == x2 && y1 == y2){
          output[i] = "NO";
        }else{
          var diffX = b - a;
          var diffY = d - c;
          if(diffX >= x1 && diffX <= x2 && diffY >= y1 && diffY <= y2){
            output[i] = "YES";
          }else{
            output[i] = "NO";
          }
        }
    }
    myout(myconv(output,9));
}


print(function(n, p) {
	var i, j, ans = 0,
		mod = 1000000007,
		dp = new Int32Array(n + 2);

	n++;

	for (i = 1; i <= n; i++)
		dp[i] = 2;

	for (i = 1; i <= n; i++)
		for (j = p[i]; j < i; j++)
			dp[i] = (dp[i] + dp[j]) % mod;

	return dp[n] - 2;

}(+readline(), ('0 ' + readline() + ' 1').split(' ').map(Number)));

print(function(n, p) {
	var i, j, ans = 0,
		mod = 1000000007,
		dp = new Int32Array(n + 1);

	for (i = 1; i <= n; i++)
		dp[i] = 2;

	for (i = 1; i <= n; i++)
		for (j = p[i]; j < i; j++)
			dp[i] = (dp[i] + dp[j]) % mod;

	for (i = 1; i <= n; i++)
		ans = (ans + dp[i]) % mod;

	return ans;

}(+readline(), ('0 ' + readline()).split(' ').map(Number)));