A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square.For a given string $$$s$$$ determine if it is square.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) —the number of test cases. This is followed by $$$t$$$ lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between $$$1$$$ and $$$100$$$ inclusive.

For each test case, output on a separate line:   YES if the string in the corresponding test case is square,  NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

10
a
aa
aaa
aaaa
abab
abcabc
abacaba
xxyy
xyyx
xyxy

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

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

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

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


After lessons Nastya decided to read a book. The book contains $$$n$$$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $$$k$$$ as the first page which was not read (i.e. she read all pages from the $$$1$$$-st to the $$$(k-1)$$$-th).The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of chapters in the book. There are $$$n$$$ lines then. The $$$i$$$-th of these lines contains two integers $$$l_i$$$, $$$r_i$$$ separated by space ($$$l_1 = 1$$$, $$$l_i \leq r_i$$$) — numbers of the first and the last pages of the $$$i$$$-th chapter. It's guaranteed that $$$l_{i+1} = r_i + 1$$$ for all $$$1 \leq i \leq n-1$$$, and also that every chapter contains at most $$$100$$$ pages. The $$$(n+2)$$$-th line contains a single integer $$$k$$$ ($$$1 \leq k \leq r_n$$$) — the index of the marked page.

Print a single integer — the number of chapters which has not been completely read so far.

NoteIn the first example the book contains $$$11$$$ pages and $$$3$$$ chapters — $$$[1;3]$$$, $$$[4;7]$$$ and $$$[8;11]$$$. Nastya marked the $$$2$$$-nd page, so she finished in the middle of the $$$1$$$-st chapter. So, all chapters has not been read so far, so the answer is $$$3$$$.The book in the second example contains $$$12$$$ pages and $$$3$$$ chapters too, but Nastya finished reading in the middle of the $$$2$$$-nd chapter, so that the answer is $$$2$$$.

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

//Don't have to see. end------------------------------------------
function Main(){
	var 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;
        }
    }
});

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

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


Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

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

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

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


Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.Simply speaking, the process of photographing can be described as follows. Each friend occupies a rectangle of pixels on the photo: the i-th of them in a standing state occupies a wi pixels wide and a hi pixels high rectangle. But also, each person can lie down for the photo, and then he will occupy a hi pixels wide and a wi pixels high rectangle.The total photo will have size W × H, where W is the total width of all the people rectangles, and H is the maximum of the heights. The friends want to determine what minimum area the group photo can they obtain if no more than n / 2 of them can lie on the ground (it would be strange if more than n / 2 gentlemen lie on the ground together, isn't it?..)Help them to achieve this goal.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of friends. The next n lines have two integers wi, hi (1 ≤ wi, hi ≤ 1000) each, representing the size of the rectangle, corresponding to the i-th friend.

Print a single integer equal to the minimum possible area of the photo containing all friends if no more than n / 2 of them can lie on the ground.

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 = []
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) {
    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))


This is the hard version of Problem F. The only difference between the easy version and the hard version is the constraints.We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced.We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation:  replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced.For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+".How many non-empty substrings of the given string $$$s$$$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $$$s$$$.Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++".

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$): the length of $$$s$$$. The second line of the test case contains the string $$$s$$$ of length $$$n$$$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single number: the number of the promising non-empty substrings of string $$$s$$$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $$$s$$$.

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


Let's call a binary string $$$T$$$ of length $$$m$$$ indexed from $$$1$$$ to $$$m$$$ paranoid if we can obtain a string of length $$$1$$$ by performing the following two kinds of operations $$$m-1$$$ times in any order : Select any substring of $$$T$$$ that is equal to 01, and then replace it with 1. Select any substring of $$$T$$$ that is equal to 10, and then replace it with 0.For example, if $$$T = $$$ 001, we can select the substring $$$[T_2T_3]$$$ and perform the first operation. So we obtain $$$T = $$$ 01.You are given a binary string $$$S$$$ of length $$$n$$$ indexed from $$$1$$$ to $$$n$$$. Find the number of pairs of integers $$$(l, r)$$$ $$$1 \le l \le r \le n$$$ such that $$$S[l \ldots r]$$$ (the substring of $$$S$$$ from $$$l$$$ to $$$r$$$) is a paranoid string.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of $$$S$$$. The second line of each test case contains a binary string $$$S$$$ of $$$n$$$ characters $$$S_1S_2 \ldots S_n$$$. ($$$S_i = $$$ 0 or $$$S_i = $$$ 1 for each $$$1 \le i \le n$$$) It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output the number of pairs of integers $$$(l, r)$$$ $$$1 \le l \le r \le n$$$ such that $$$S[l \ldots r]$$$ (the substring of $$$S$$$ from $$$l$$$ to $$$r$$$) is a paranoid string.

NoteIn the first sample, $$$S$$$ already has length $$$1$$$ and doesn't need any operations.In the second sample, all substrings of $$$S$$$ are paranoid. For the entire string, it's enough to perform the first operation.In the third sample, all substrings of $$$S$$$ are paranoid except $$$[S_2S_3]$$$, because we can't perform any operations on it, and $$$[S_1S_2S_3]$$$ (the entire string).

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

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


Casimir has a rectangular piece of paper with a checkered field of size $$$n \times m$$$. Initially, all cells of the field are white.Let us denote the cell with coordinates $$$i$$$ vertically and $$$j$$$ horizontally by $$$(i, j)$$$. The upper left cell will be referred to as $$$(1, 1)$$$ and the lower right cell as $$$(n, m)$$$.Casimir draws ticks of different sizes on the field. A tick of size $$$d$$$ ($$$d > 0$$$) with its center in cell $$$(i, j)$$$ is drawn as follows:   First, the center cell $$$(i, j)$$$ is painted black.  Then exactly $$$d$$$ cells on the top-left diagonally to the center and exactly $$$d$$$ cells on the top-right diagonally to the center are also painted black.  That is all the cells with coordinates $$$(i - h, j \pm h)$$$ for all $$$h$$$ between $$$0$$$ and $$$d$$$ are painted. In particular, a tick consists of $$$2d + 1$$$ black cells. An already painted cell will remain black if painted again. Below you can find an example of the $$$4 \times 9$$$ box, with two ticks of sizes $$$2$$$ and $$$3$$$.  You are given a description of a checkered field of size $$$n \times m$$$. Casimir claims that this field came about after he drew some (possibly $$$0$$$) ticks on it. The ticks could be of different sizes, but the size of each tick is at least $$$k$$$ (that is, $$$d \ge k$$$ for all the ticks).Determine whether this field can indeed be obtained by drawing some (possibly none) ticks of sizes $$$d \ge k$$$ or not.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number test cases. The following lines contain the descriptions of the test cases.  The first line of the test case description contains the integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le k \le n \le 10$$$; $$$1 \le m \le 19$$$) — the field size and the minimum size of the ticks that Casimir drew. The following $$$n$$$ lines describe the field: each line consists of $$$m$$$ characters either being '.' if the corresponding cell is not yet painted or '*' otherwise.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if the given field can be obtained by drawing ticks of at least the given size and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

NoteThe first sample test case consists of two asterisks neither of which can be independent ticks since ticks of size $$$0$$$ don't exist.The second sample test case is already described in the statement (check the picture in the statement). This field can be obtained by drawing ticks of sizes $$$2$$$ and $$$3$$$, as shown in the figure.The field in the third sample test case corresponds to three ticks of size $$$1$$$. Their center cells are marked with $$$\color{blue}{\text{blue}}$$$, $$$\color{red}{\text{red}}$$$ and $$$\color{green}{\text{green}}$$$ colors: *.*.*$$$\color{blue}{\textbf{*}}$$$**.$$$\color{green}{\textbf{*}}\color{red}{\textbf{*}}$$$.....The field in the fourth sample test case could have been obtained by drawing two ticks of sizes $$$1$$$ and $$$2$$$. Their vertices are marked below with $$$\color{blue}{\text{blue}}$$$ and $$$\color{red}{\text{red}}$$$ colors respectively: .....*...*.*.*...$$$\color{red}{\textbf{*}}$$$.*...$$$\color{blue}{\textbf{*}}$$$.The field in the fifth sample test case can not be obtained because $$$k = 2$$$, and the last asterisk in the fourth row from the top with coordinates $$$(4, 5)$$$ can only be a part of a tick of size $$$1$$$.The field in the sixth sample test case can not be obtained because the top left asterisk $$$(1, 1)$$$ can't be an independent tick, since the sizes of the ticks must be positive, and cannot be part of a tick with the center cell in the last row, since it is separated from it by a gap (a point, '.') in $$$(2, 2)$$$.In the seventh sample test case, similarly, the field can not be obtained by the described process because the asterisks with coordinates $$$(1, 2)$$$ (second cell in the first row), $$$(3, 1)$$$ and $$$(3, 3)$$$ (leftmost and rightmost cells in the bottom) can not be parts of any ticks.

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