Timur likes his name. As a spelling of his name, he allows any permutation of the letters of the name. For example, the following strings are valid spellings of his name: Timur, miurT, Trumi, mriTu. Note that the correct spelling must have uppercased T and lowercased other letters.Today he wrote string $$$s$$$ of length $$$n$$$ consisting only of uppercase or lowercase Latin letters. He asks you to check if $$$s$$$ is the correct spelling of his name.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ $$$(1 \leq n \leq 10)$$$ — the length of string $$$s$$$. The second line of each test case contains a string $$$s$$$ consisting of only uppercase or lowercase Latin characters.

For each test case, output "YES" (without quotes) if $$$s$$$ satisfies the condition, and "NO" (without quotes) otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

10

5

Timur

5

miurT

5

Trumi

5

mriTu

5

timur

4

Timr

6

Timuur

10

codeforces

10

TimurTimur

5

TIMUR

n=+readline();
while(n--){
   l=+readline();
   t=readline();
   if(l === 5){
      p = t.match(/(m|r|i|T|u)/g);
      newP=[...new Set(p)];
      print(p === null ? "NO" : newP.length === 5 ? "YES" : "NO" )
   }else{
      print("NO")
   }
}

(function main(){

    var t = readline();
    for(var i = 0; i<t;i++){
        var num = readline();
        var s = readline();
        if(num!="5"){
            print("NO");
            continue;
        }
        var T = 0;
        var idx = 0;
        var m = 0;
        var u = 0;
        var r = 0;
        for(var j = 0; j<num;j++){
          if(s[j] == 'T')
          T++;
          else if(s[j] == 'i')
          idx++;
          else if(s[j] == 'm')
          m++;
          else if(s[j] == 'u')
          u++;
          else if(s[j] == 'r')
          r++;
        }
        if(T&&idx&&m&&u&&r){
            print("YES");
        }else{
            print("NO");
        }

    }

})();

// import input from 'input'

var n = +(readline())

for (var i = 0; i < n; i++) {
    var ns = readline()
    var s = readline()

    if (compare("Timur", s)) {
        print("YES")
    } else {
        print("NO")
    }
}

function compare(s, d) {
    var k = 0;

    for (var i = 0; i < s.length; i++) {
        if (d.includes(s[i])) {
            k++;
        }
    }

    return k === s.length && k === d.length
}

var t = parseInt(readline());

while(t--){
    var nn = {T: 0, i: 0, m: 0, u: 0, r: 0};
    var n = parseInt(readline());
    var s = readline();
    var ret = false
    var i;
    for(i = 0; i < s.length; i++){
        if(nn[s[i]] === undefined){ print ("NO"); ret = true; break; }
        else nn[s[i]]++;
    }
    if(ret) continue;
    for(var k in nn){
        if(nn[k] !== 1) {print("NO"); ret = true; break;}
    }
    if(ret) continue;
    print("YES");

}

var n;

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        n = parseInt(readline());
        var s = readline();
        var m = {
            T: 0,
            i: 0,
            m: 0,
            u: 0,
            r: 0,
        };

        var ans = 'YES'
        for (var i = 0; i < s.length; i++) {
            if (m[s.charAt(i)] !== 0) {
                ans = 'NO';
                break;
            }
            m[s.charAt(i)]++;
        }

        var vals = Object.keys(m);
        var sum = 0;
        vals.forEach(x => sum += m[x]);
        if (sum != 5) {
            ans = 'NO';
        }
        print(ans);
    }

var t = +readline();

for(var i = 0; i< t; i ++) {

      var nums = [];
    var t1 = +readline();
    var t2 = readline();
    print(removePrefix(t2));

}

function removePrefix(num){

   return num.split('').sort().join('') === 'Timru' ? 'YES' : 'NO';

}

var t = parseInt(readline());

var origin = 'Timur'.split('').sort();

for (var test = 0; test < t; test++) {
    var n = parseInt(readline());
    var str = readline();

    if (n !== 5) {
        print('NO');
    } else {
        var arr = str.split('').sort();

        if (arr.join('') === origin.join('')) {
            print('YES');
        } else {
            print('NO');
        }
    }
}

var t = readline(),
    timurName = ["T" , "i" , "m" , "u" , "r"],
    sortedName = timurName.sort().toString();
    for(var i = 0 ; i < t ; i++){
    var n = readline(),
        s= readline().split(''),
        sortedInput = s.sort();
        if(sortedInput == sortedName ){
            print("YES");}
            else{
                print("NO");
            }
    }

/*
if length is 5
and includes T, i, m, u, r
yes, else no
*/
var n=readline();
for(var i=0;i<n;i++){
  var strlen = readline();
  var str = readline();
  if(strlen==5 && str.includes("T") && str.includes("i") && str.includes("m") && str.includes("u") && str.includes("r")){
    print("YES");
  } else {
    print("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],e=0;
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j];
        }else{
            var k = lines[j].split('');
            var t = false, I = false, m = false, u = false, r = false;
                        if(e == 5){

            for(l = 0; l < e; l++){
                if(k[l] == 'T'){
                    t = true;
                }else if(k[l] == 'i'){
                    I = true;
                }else if(k[l] == 'm'){
                    m = true;
                }else if(k[l] == 'u'){
                    u = true;
                }else if(k[l] == 'r'){
                    r = true;
                }
            }
                        }
            if(t && I && m && u && r){
                console.log('YES');
            }else{
                console.log('NO');
            }

        }

    }
});

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 = lines[i];
        }else{
            var k = lines[i].split('');
            var timur = ['T', 'i', 'm', 'u', 'r'];
            if(n == 5){
                for(j = 0; j < n; j++){
                    for(l = 0; l < 5; l++){
                        if(k[j] == timur[l]){
                            timur.splice(l, 1);
                            break;
                        }
                    }
                }
                console.log(timur.length === 0 ? 'YES' : 'NO');
            }else{
                console.log('NO');
            }
        }
    }
});

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 = lines[i];
        }else{
            var k = lines[i].split('');
            var name = ['T', 'i', 'm', 'u', 'r'];
            var check = 0;
            if(n == 5){
                for(j = 0; j < n; j++){
                    for(l = 0; l < n; l++){
                        if(k[j] == name[l]){
                            check++;
                            name.splice(l, 1);
                        }
                    }
                }
                console.log(name.length === 0 ? 'YES' : 'NO');
            }else{
                console.log('NO');
            }
        }
    }
});

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const n = parseInt(readline());

    for (let i = 0; i < n; i++) {
        const sz = parseInt(readline());
        let str = readline();

        if (sz != 5) {
            console.log("NO");
            continue;
        }

        console.log([...str].sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('') == "Timru" ? "YES" : "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() {
    var t = parseInt(readline());
    const s = Array.from("Timur");
    s.sort();

    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline());
        x.sort();
        var ok = true;
        if (n === 5)
        for (let i = 0;i < 5;++i) {
            // console.log(x[i],s[i]);
            if (x[i+1] != s[i]) {
                ok = false;
            }
        }
        if (n ===5 && ok) {
            console.log('YES');
        } else {
            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() {
    var t = parseInt(readline());
    const s = Array.from("Timur");

    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline());
        let cnt = 0;
        var hsh = new Array(5).fill(false);
        for (let i = 0; i < n;++i) {
            for (let j = 0;j < 5;++j) {
                if (hsh[j] === false && s[j] === x[i]) {
                    hsh[j] = true;
                    cnt++;
                }
            }
        }
        if (n === 5 && cnt === 5) {
            console.log('YES');
        } else {
            console.log('NO');
        }

    }
}

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

let standardInputString = ''
let currentLine = 0

function readLine(){
    return standardInputString[currentLine++]
}
process.stdin.on('data', rawData => {
    standardInputString += rawData
})

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

    main()
})

//   .........................................................   //

const main=()=>{
    const testCase =parseInt(readLine());

    for (let index = 1; index <= testCase; index++) {
        const length =parseInt(readLine());
        const string = readLine();
        console.log(spellCheck(length, string));

    }
}

const spellCheck = (length, string) => {
    const sort = str => str.split('').sort((a, b) => a.localeCompare(b)).join('');
    const name = 'Timur';
    if (sort(name) === sort(string))
        return 'YES';

    else
        return 'NO'
}

let readline = require("readline");
const { start } = require("repl");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);

  if (input.length === +input[0] * 2 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  let name = ["T", "i", "m", "u", "r"];

  for (let i = 1; i < input.length; i += 2) {
    if (+input[i] !== 5) {
      console.log("NO");
      continue;
    } else {
      let count = 0;
      let test = input[i + 1];

      for (let j = 0; j < name.length; j++) {
        if (test.includes(name[j])) count++;
        else {
          console.log("NO");
          break;
        }
      }

      if (count === 5) console.log("YES");
    }
  }
};

//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();
	var ok = "Timur";
	while(hasNext()){
		var N = nextInt();
		var s = next();
		var map = {};
		var isOK = true;
		for(var i = 0; i < N; i++){
			if(ok.indexOf(s[i]) == -1){
				isOK = false;
				break;
			}else if(map[s[i]]){
				isOK = false;
				break;
			}
			map[s[i]] = true;
		}
		for(var i = 0; i < ok.length; i++){
			if(map[ok[i]] == null){
				isOK = false;
				break;
			}
		}
		if(isOK){
			myout("Yes");
		}else{
			myout("No");
		}
	}
}

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

let c = 0;
const original = ["T", "i", "m", "r", "u"];

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

  if (c % 2 !== 0) {
    c++;
    return;
  }

  const chars = [...d].sort();
  let ans = "YES";

  for (let i = 0; i < original.length; i++) {
    if (original[i] !== chars[i]) {
      ans = "NO";
      break;
    }
  }

  if (chars.length !== original.length) {
    ans = "NO";
  }

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

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

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

const readline = () => inputString[currentLine++]
// Common Template Ends //

// Driver Function Starts //
const main = () => {
    console.clear()
    let t = parseInt(readline())
    while (t--) {
        let n = parseInt(readline())
        let s = readline()
        console.log( solve(n,s) )
    }
}
// Driver Function Ends //

// MAIN LOGIC
const solve = (n, s) => {
    if( n != 5 ) return 'NO'

    let flag = false

    if( s.includes("T") ) {
	    if( s.includes("i") ) {
		    if( s.includes("m") ) {
			    if( s.includes("u") ) {
				    if( s.includes("r") ) {
				    	return 'YES'
				    }
			    }
		    }
	    }
    }

    return 'NO'
}

// 12339
// 0
// 15
// 54306
// 999999995
// 185
// 999999998

const isOdd         = (num) => num & 1
const isEven        = (num) => !(num & 1)
const minOfArray    = (arr) => Math.min.apply(null, arr)
const maxOfArray    = (arr) => Math.max.apply(null, arr)
const uniqueArray   = (arr) => [...new Set(arr)]
const sortArray     = (arr) => arr.sort((a, b) => a - b)
const sumOfArray    = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)

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

  main();
});

function main() {
  const testCases = inputString[0];

  for (let i = 1; i <= testCases * 2; i += 2) {
    const length = Number(inputString[i]);
    const str = inputString[i + 1].split("");
    if (length !== 5) console.log("NO");
    else {
      const name = new Set("Timur".split(""));
      str.forEach(e => name.delete(e));
      if(name.size === 0) console.log("YES");
      else console.log("NO");
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let s =  readline().split('');

        let t = ('Timur').split('');
        t.sort();
        s.sort();
        output(t.join('') === s.join('') ? '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++];
}

// Main Function, write code here

function main() {
  let T = readline();
  for (let i = 0; i < T; i++) {
    const n = readline();
    const str = readline();
    let timur = "Timur".split("").sort().join("");
    const strSorted = str.split("").sort().join("");
    console.log(timur === strSorted ? '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 main() {
    const numberOfTest = Number.parseInt(readline());
    for(let i=0; i<numberOfTest; i++){
        const strLength = Number.parseInt(readline());
        const str = readline();
        Solution(strLength, str);
    }
}

function Solution(n, s){
    const nameSet = new Set(['T', 'i', 'm', 'u', 'r']);
    const length = nameSet.size;
    let result = "NO";
    if(n == length){
        for(let j=0; j<length; j++){
            const value = s.charAt(j);
            if(nameSet.has(value)){
                nameSet.delete(value);
            }
        }
        if(nameSet.size == 0){
            result = "YES"
        }
    }
    console.log(result);
}

const rdline = require('readline');
const rl = rdline.createInterface({
    input: process.stdin
});

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    // input in lines
    solve();
});

let line = 0;
const readline = () => lines[line++];

solve = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var s = readline();
        if (n === 5 && s.includes('T') && s.includes('i') && s.includes('m') && s.includes('u') && s.includes('r')) {
            console.log("YES");

        } else {
            console.log("NO");
        }
    }
}

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

function solve(n, str) {
    // str = 'Timur'
    return str.split('')
        .sort((a, b) => a < b ? -1 : (a > b ? 1 : 0))
        .join('') === 'Timru' ? 'YES' : 'NO'
}

let fs = require("fs");
let sc = {
    _buf: new Buffer.alloc(1 << 14),
    _bufPos: 0,
    _bufLen: 0,
    _ensure: function ()
    {
        if (this._bufPos === this._bufLen)
        {
            this._bufPos = 0;
            this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);
        }
    },
    _isws: function (ch)
    {
        return ch === 32 || ch === 9 || ch === 10 || ch === 13;
    },
    _islf: function (ch)
    {
        return ch === 10 || ch === 13;
    },
    _peekChar: function ()
    {
        this._ensure();
        return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];
    },
    _skipWs: function ()
    {
        while (this._isws(this._peekChar()))
            this._bufPos++;
    },
    _readUntil: function (stop)
    {
        this._ensure();
        if (this._bufPos === this._bufLen)
            throw new Error("eof");
        let start = this._bufPos;
        let before = null;
        for (; ;)
        {
            if (this._bufPos === this._bufLen)
            {
                let len = this._bufPos - start, preLen = (before ? before.length : 0);
                let nbuf = new Buffer(len + preLen);
                if (before)
                    before.copy(nbuf);
                before = nbuf;
                this._buf.copy(before, preLen, start);
                this._ensure();
                start = this._bufPos;
            }
            if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;
            this._bufPos++;
        }
        if (!before)
            return this._buf.toString("utf8", start, this._bufPos);
        let after = this._buf.slice(start, this._bufPos);
        let res = new Buffer(before.length + after.length);
        before.copy(res);
        after.copy(res, before.length);
        return res.toString();
    },

    nextToken: function ()
    {
        this._skipWs();
        return this._readUntil(this._isws);
    },
    L: function ()
    {
        let line = this._readUntil(this._islf);
        if (this._peekChar() === 13) this._bufPos++;
        if (this._peekChar() === 10) this._bufPos++;
        return line;
    },
    N: function ()
    {
        return +this.nextToken();
    },
    S: function ()
    {
        return this.nextToken();
    }
};

// DO NOT CHANGE TEMPLATE BEFORE

const Def = Number(1e9);

const LowerBound = (arr, val) =>
{
    let ng = -1;
    let ok = arr.length;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] >= val)
        {
            ok = med;
        }
        else
        {
            ng = med;
        }
    }

    return ok;
}

const ReverseLowerBound = (arr, val) =>
{
    let ng = 0;
    let ok = arr.length;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] <= val)
        {
            ng = med;
        }
        else
        {
            ok = med;
        }
    }
    // Находит наибольший элемент который меньше или равен val
    return ng;
}

const ReverseUpperBound = (arr, val) =>
{
    let ng = 0;
    let ok = arr.length;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] < val)
        {
            ng = med;
        }
        else
        {
            ok = med;
        }
    }
    // Находит наибольший элемент который меньше val
    return ng;
}

const UpperBound = (arr, val) =>
{
    let ok = arr.length;
    let ng = -1;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] > val)
        {
            ok = med;
        }
        else
        {
            ng = med;
        }
    }

    return ok;
}

const Solve = () =>
{
    let n = sc.N();
    let s = sc.S();

    if (n !== 5)
    {
        console.log("NO");
        return;
    }

    let arr = ['T', 'i', 'm', 'r', 'u'];
    let r = [...s];
    r.sort();

    let e = true;
    for (let i = 0; i < 5; ++i)
    {
        if (arr[i] !== r[i])
        {
            console.log("NO");
            return;
        }
    }

    console.log("YES");

}

const main = () =>
{
    let cases = +sc.L();
    while (cases-- > 0) Solve();

    // Solve();
}
main();

n=+readline();
while(n--){
   l=+readline();
   t=readline();
   if(l === 5){
      p = t.match(/(Timur|miurT|Trumi|mriTu)/g);
      print(p !== null ? "Yes" : "No")
   }else{
      print("NO")
   }
}

n=+readline();

for(i=0;i<n;i++){
   l=+readline();
   t=readline();

   if(l == 5){
      p=t.match(/(Timur|miurT|Trumi|mriTu)/g) == null ? "" : t.match(/(Timur|miurT|Trumi|mriTu)/g) ;
      if( p.length == 1){
         print( t == "Timur" || t == "miurT" || t== "Trumi" || t== "mriTu" ? "YES" : "NO")
      }else{
      print("NO")
      }
   }else{
      print("NO")
   }
}

n=readline();
for(i=0;i<n;i++){

   l=readline();
   t=readline();

   p=t.match(/(Timur|miurT|Trumi|mriTu)/g) || "" ;

   if(l == 5){

      if( p.length == 1){

      print( t == "Timur" || t == "miurT" || t== "Trumi" || t== "mriTu" ? "YES" : "NO")

      }else{

      print("NO")

      }

   }else{

      print("NO")
   }

}

n=readline();
for(i=0;i<n;i++){
   l=readline();
   t=readline();
   if(+l === 5){
      print( t == "Timur" || t == "miurT" || t== "Trumi" || t== "mriTu" ? "YES" : "NO")
   }else{
      print("NO")
   }
}

(function main(){

    var t = readline();
    for(var i = 0; i<t;i++){
        var num = readline();
        var s = readline();
        if(num!=5){
            print("No");
        }
        var T = 0;
        var idx = 0;
        var m = 0;
        var u = 0;
        var r = 0;
        for(var j = 0; j<num;j++){
          if(s[j] == 'T')
          T++;
          else if(s[j] == 'i')
          idx++;
          else if(s[j] == 'm')
          m++;
          else if(s[j] == 'u')
          u++;
          else if(s[j] == 'r')
          r++;
        }
        if(T&&idx&&m&&u&&r){
            print("YES");
        }else{
            print("NO");
        }

    }

})();

(function main(){

    var t = readline();
    for(var i = 0; i<t;i++){
        var num = readline();
        var s = readline();
        if(num!=5){
            print("No");
        }
        var T = 0;
        var idx = 0;
        var m = 0;
        var u = 0;
        var r = 0;
        for(var j = 0; j<num;j++){
          if(s[j] == 'T')
          T++;
          else if(s[j] == 'i')
          idx++;
          else if(s[j] == 'm')
          m++;
          else if(s[j] == 'u')
          u++;
          else if(s[j] == 'r')
          r++;
        }
        if(T&&idx&&m&&u&&r){
            print("No");
        }else{
            print("No");
        }

    }

})();

// import input from 'input'

var n = +(readline())
var t = 'Timur'

for (var i = 0; i < n; i++) {
    var ns = readline()
    var s = readline()

    if (compare(t, s)) {
        print("YES")
    } else {
        print("NO")
    }
}

function compare(s, d) {
    var k = 0;

    for (var i = 0; i < s.length; i++) {
        if (d.includes(s[i])) {
            k++;
        }
    }

    return k === s.length
}

var t = parseInt(readline());

while(--t){
    var nn = {T: 0, i: 0, m: 0, u: 0, r: 0};
    var n = parseInt(readline());
    var s = readline();
    var ret = false
    var i;
    for(i = 0; i < s.length; i++){
        if(nn[s[i]] === undefined){ print ("NO"); ret = true; break; }
        else nn[s[i]]++;
    }
    if(ret) continue;
    for(var k in nn){
        if(nn[k] !== 1) {print("NO"); ret = true; break;}
    }
    if(ret) continue;
    print("YES");

}

var t = +readline();

for(var i = 0; i< t; i ++) {

      var nums = [];
    var t1 = +readline();
    var t2 = readline();
    print(removePrefix(t2));

}

function removePrefix(num){

 if (num.length != 5) return 'NO';

    var str = 'Timur';
 var count = 0;
  for(var each of num){
          if (str.indexOf(each) == -1)return 'NO';
          count++;

  }
  if (count == 5){
          return 'YES'
          }else {
                  return '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],e=0
    for(j = 1; j <= n *2; j++){
        if(j % 2 == 1){
            e = lines[j], t = false, I = false, m = false, u = false, r = false
        }else{
            if(e == 5){
                for(l = 0; l < e; l++){
                    var k = lines[j].split('')
                    if(k[l] == 'T' && t === false){
                        t = true
                    }else if(k[l] == 'i' &&I === false){
                        i = true
                    }else if(k[l] == 'm' && m === false){
                        m = true
                    }else if(k[l] == 'u' && u === false){
                        u = true
                    }else if(k[l] == 'r' && r === false){
                        r = true
                    }
            }
            }
            if(t === true && I === true && m === true && u === true && r === true ){
                console.log('YES')
            }else{
                console.log('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],e=0
    for(j = 1; j <= n; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
            if(e == 5){
                for(l = 0; l < e; l++){
                    var k = lines[j].split(''), t = false, I = false, m = false, u = false, r = false
                    if(k[l] == 'T' && t === false){
                        t = true
                    }else if(k[l] == 'i' &&I === false){
                        i = true
                    }else if(k[l] == 'm' && m === false){
                        m = true
                    }else if(k[l] == 'u' && u === false){
                        u = true
                    }else if(k[l] == 'r' && r === false){
                        r = true
                    }
            }
            }
            if(t === true && I === true && m === true && u === true && r === true ){
                console.log('YES')
            }else{
                console.log('NO')
            }
        }

    }
});

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const n = parseInt(readline());

    for (let i = 0; i < n; i++) {
        const sz = parseInt(readline());

        if (sz != 5) {
            console.log("NO");
            continue;
        }

        let str = readline();
        console.log([...str].sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('') == "Timru" ? "YES" : "NO");
    }
}

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

let standardInputString = ''
let currentLine = 0

function readLine(){
    return standardInputString[currentLine++]
}
process.stdin.on('data', rawData => {
    standardInputString += rawData
})

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

    main()
})

//   .........................................................   //

const main=()=>{
    const testCase =parseInt(readLine());

    for (let index = 1; index <= testCase; index++) {
        const length =parseInt(readLine());
        const string = readLine();
        console.log(spellCheck(length, string));

    }
}

const spellCheck = (length, string) => {
    const name = 'Tumir';
    if (name.length != string.length)
        return 'NO';
    let count = 0;
    for (let index = 0; index < name.length; index++) {
        for (let j = 0; j < string.length; j++) {
            if (name[index] === string[j]) {
                count++;
            }

        }

    }
    if (count === name.length) {
        return 'YES'
    }
    else
        return 'NO'
}

let readline = require("readline");
const { start } = require("repl");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);

  if (input.length === +input[0] * 2 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  let name = {
    T: true,
    i: true,
    m: true,
    u: true,
    r: true,
  };

  for (let i = 1; i < input.length; i += 2) {
    if (+input[i] !== 5) {
      console.log("NO");
      continue;
    } else {
      let count = 0;
      for (let j = 0; j < input[i + 1].length; j++) {
        if (name[input[i + 1][j]]) {
          count++;
        }
      }
      if (count === 5) {
        console.log("YES");
      } else {
        console.log("NO");
      }
    }
  }
};

//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();
	var list = ["Timur", "miurT", "Trumi", "mriTu"];
	while(hasNext()){
		var N = nextInt();
		var s = next();
		if(list.indexOf(s) > -1){
			myout("Yes");
		}else{
			myout("No");
		}
	}
}


You are given a string $$$s$$$ consisting of lowercase letters of the English alphabet. You must perform the following algorithm on $$$s$$$:  Let $$$x$$$ be the length of the longest prefix of $$$s$$$ which occurs somewhere else in $$$s$$$ as a contiguous substring (the other occurrence may also intersect the prefix). If $$$x = 0$$$, break. Otherwise, remove the first $$$x$$$ characters of $$$s$$$, and repeat. A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd".For instance, if we perform the algorithm on $$$s =$$$ "abcabdc",   Initially, "ab" is the longest prefix that also appears somewhere else as a substring in $$$s$$$, so $$$s =$$$ "cabdc" after $$$1$$$ operation.  Then, "c" is the longest prefix that also appears somewhere else as a substring in $$$s$$$, so $$$s =$$$ "abdc" after $$$2$$$ operations.  Now $$$x=0$$$ (because there are no non-empty prefixes of "abdc" that also appear somewhere else as a substring in $$$s$$$), so the algorithm terminates. Find the final state of the string after performing the algorithm.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, each containing a description of one test case. Each line contains a string $$$s$$$. The given strings consist only of lowercase letters of the English alphabet and have lengths between $$$1$$$ and $$$2 \cdot 10^5$$$ inclusive. It is guaranteed that the sum of the lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single line containing the string $$$s$$$ after executing the algorithm. It can be shown that such string is non-empty.

6
abcabdc
a
bbbbbbbbbb
codeforces
cffcfccffccfcffcfccfcffccffcfccf
zyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw

NoteThe first test case is explained in the statement.In the second test case, no operations can be performed on $$$s$$$.In the third test case,   Initially, $$$s =$$$ "bbbbbbbbbb".  After $$$1$$$ operation, $$$s =$$$ "b". In the fourth test case,   Initially, $$$s =$$$ "codeforces".  After $$$1$$$ operation, $$$s =$$$ "odeforces".  After $$$2$$$ operations, $$$s =$$$ "deforces".

var t = readline();

for (var i = 0; i < t; i++) {
  var a = readline();

  var f = 0;
  var s = 0;
  for (var j = 0; j < a.length; j++) {
    for (var k = j + 1; k < a.length; k++) {
      if (a[j] === a[k]) {
        s = j + 1;
        break;
      }

      if(k === a.length - 1  &&  a[j] !== a[k]) {
        f = 1;
        break;
      }
    }

    if (f === 1) {
      break;
    }
  }
  print(a.substring(s));
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let s = readline();
        let arr = s.split('');

        if (s.length === 1) {
            output(s);
            continue;
        }

        let freq = {};
        for (let i = 0; i < arr.length; i++) {
            if (freq[arr[i]]) {
                freq[arr[i]]++;
            } else {
                freq[arr[i]] = 1;
            }
        }

        let count = Object.keys(freq).length;

        let freq2 = {};
        for (let i = s.length - 1; i >= 0; i--) {
            if (!freq2[s[i]]) {
                freq2[s[i]] = true;
            }

            if (Object.keys(freq2).length === count) {
                output(s.slice(i));
                break;
            }
        }
    }
}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(s) {
  const map = new Map();
  for (let char of s) {
    var _map$get;
    map.set(char, ((_map$get = map.get(char)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  for (let [i, char] of [...s].entries()) {
    if (map.get(char) > 1) {
      map.set(char, map.get(char) - 1);
    } else {
      return s.slice(i);
    }
  }
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const s = await read();
    res.push(solve(s));
  }
  console.log(res.join('\n'));
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict'; /*jslint node:true, browser:true, es6:true*/
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;

let calc = (s)=>{
  let map = new Map();
  for (let i=0; i<s.length; i++){
    map.set(s[i], (map.get(s[i])||0) + 1);
  }
  for (let i=0; i<s.length; i++){
    let cnt = map.get(s[i]);
    if (cnt==1)
      return s.slice(i);
    map.set(s[i], cnt - 1);
  }
};
// codecxcode -> cxcode
// xcode

function main() {
    let T = +readline();
    while (T--){
      let s = readline();
      print(calc(s));
    }
}

function solve() {
   const str = read();
   const charSet = new Set();
   for (let i = 0; i < str.length; i++) {
      charSet.add(str[i]);
   }
   const currentSet = new Set();
   for (let i = str.length - 1; i >= 0; i--) {
      currentSet.add(str[i]);
      if (currentSet.size === charSet.size) {
         write(str.substring(i));
         return;
      }
   }
}

function init() {
   try {
      var T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e + e.stack);
   }
}

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

function solveAll(inputs) {
    inputs.forEach(input => {
        let lastLet = input;
        let valid = true;
        while (valid) {
            let pref = lastLet[0]
            valid = lastLet.slice(1, lastLet.length).includes(pref)
            if (valid) lastLet = lastLet.slice(1, lastLet.length);
        }
        console.log(lastLet)
    });
}

const rl = require('readline').createInterface(process.stdin, process.stdout);
let testCase = 0; const inputs = []
rl.on('line', (data) => {
    if (testCase === 0) testCase = parseInt(data)
    else {
        inputs.push(data)
        if (inputs.length === testCase) { solveAll(inputs); rl.close() };
    }
})

//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 = nextCharArray();
		var map = getCountMap(S);
		var output = [];
		var N = S.length;
		var ok = false;
		for(var i = 0; i < N; i++){
			if(map[S[i]] > 1 && !ok){
				map[S[i]]--;
			}else{
				output.push(S[i]);
				ok = true;
			}
		}
		myout(myconv(output, 0));
	}
}

var t = readline();

for (var i = 0; i < t; i++) {
  var n = readline();
  var arr = Array.from(n);
  var res = arr.reverse().filter((el, i) => arr.indexOf(el) === i);
  print(res.reverse().join(''));
}

var t = readline();

for (var i = 0; i < t; i++) {
  var a = readline().split(' ').map(Number);
  var n = a[0];
  var B = a[1], x = a[2], y = a[3];
  var sum = 0;
  var ans = 0;

  while(n > 0) {
    sum += sum + x <= B ? x : -y;
    ans += sum;
    n--;
  }
  print(ans);
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let s = readline();
        let freq = {};
        let i = s.length - 1;
        for (; i >= 0; i--) {
            if (!freq[s[i]]) {
                freq[s[i]] = 1;
            } else break;
        }
        output(s.slice(i));
    }
}


You are given three arrays $$$a$$$, $$$b$$$ and $$$c$$$. Initially, array $$$a$$$ consists of $$$n$$$ elements, arrays $$$b$$$ and $$$c$$$ are empty.You are performing the following algorithm that consists of two steps:   Step $$$1$$$: while $$$a$$$ is not empty, you take the last element from $$$a$$$ and move it in the middle of array $$$b$$$. If $$$b$$$ currently has odd length, you can choose: place the element from $$$a$$$ to the left or to the right of the middle element of $$$b$$$. As a result, $$$a$$$ becomes empty and $$$b$$$ consists of $$$n$$$ elements.  Step $$$2$$$: while $$$b$$$ is not empty, you take the middle element from $$$b$$$ and move it to the end of array $$$c$$$. If $$$b$$$ currently has even length, you can choose which of two middle elements to take. As a result, $$$b$$$ becomes empty and $$$c$$$ now consists of $$$n$$$ elements.  Refer to the Note section for examples.Can you make array $$$c$$$ sorted in non-decreasing order?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — the array $$$a$$$ itself. It's guaranteed that the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test, print YES (case-insensitive), if you can make array $$$c$$$ sorted in non-decreasing order. Otherwise, print NO (case-insensitive).

var tests = parseInt(readline());
    var n;
    var a;

    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        var prevMax = 0;
        var start = 0;
        var ans = 'YES';
        if (a.length & 1) {
            start = 1;
            prevMax = a[0];
        }
        for (var i = start; i < n; i+=2) {
            if (a[i] < prevMax || a[i+1] < prevMax) {
                ans = 'NO';
                break;
            }
            prevMax = Math.max(a[i], a[i+1]);
        }
        print(ans);
    }

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

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (n, a)=>{
    if (n < 3) return 'YES';

    if (n % 2 === 1) {
        a.unshift(0);
        n++;
    }

    for (let i = 0; i < n; i += 2) {
        let max = Math.max(a[i], a[i + 1]);
        let min = Math.min(a[i], a[i + 1]);
        a[i] = min;
        a[i + 1] = max;
    }

    for (let i = 1; i < n; i++) {
        if (a[i] < a[i - 1]) return 'NO';
    }

    return 'YES';
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

"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(" ")
      .map((cur) => parseInt(cur));
    if (n === 1) {
      console.log("YES");
      continue;
    }
    let narr = [],
      i = 0;
    if (n % 2) narr.push(arr[i++]);
    while (i + 1 < n) {
      if (arr[i] > arr[i + 1]) {
        narr.push(arr[i + 1]);
        narr.push(arr[i]);
      } else {
        narr.push(arr[i]);
        narr.push(arr[i + 1]);
      }
      i = i + 2;
    }
    let ans = true;
    for (let i = 0; i < n - 1; i++) {
      if (narr[i] > narr[i + 1]) {
        ans = false;
        break;
      }
    }
    if (ans) console.log("YES");
    else console.log("NO");
  }
};
solve();

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
const INF = Infinity;
let n;
let a;
function solve() {
    for (let i = n - 1; i > 0; i -= 2) {
        if (a[i] < a[i - 1]) {
            [a[i], a[i - 1]] = [a[i - 1], a[i]];
        }
    }
    for (let i = 0; i + 1 < n; i++) {
        if (a[i] > a[i + 1]) {
            return false;
        }
    }
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        printf("%s\n", (solve() ? "YES" : "NO"));
    }
}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, nums) {
  const res = [];
  let start = 0;
  if (n & 1) {
    res.push(nums[0]);
    start = 1;
  }
  for (let i = start; i < n; i += 2) {
    var _res;
    let a = nums[i],
        b = nums[i + 1];
    if (a > b) [a, b] = [b, a];
    if (a < ((_res = res[i - 1]) !== null && _res !== void 0 ? _res : -Infinity)) {
      console.log('NO');
      return;
    }
    res.push(a, b);
  }
  console.log('YES');
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    solve(n, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

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

function Main(){
    // input in nodeJs
	var t = nextInt();
	while(hasNext()){
		let n= nextInt();
        let a= nextIntArray(n);
        let stop = false;
        for(let i=n-1;i>=0;i-=2){
            if(i+1<n && a[i]>a[i+1]) {
                myout("NO");
                stop = true;
                break;
            }
            if(i+2<n && a[i]>a[i+2]) {
                myout("NO");
                stop = true;
                break;
            }
            if(i-1>=0 && i+1<n && a[i-1]>a[i+1]) {
                myout("NO");
                stop = true;
                break;
            }
            if(i-1>=0 && i+2<n && a[i-1]>a[i+2]) {
                myout("NO");
                stop = true;
                break;
            }
        }
        if (stop) continue;
        myout("YES")
	}
}

'use strict';

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const lines = []
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

const pcalc = function(){
  print(calc.apply(null, arguments)); }

const ra = ()=>readline().split(' ').map(a=>+a)

// SOLUTION

const calc = (n, A)=>{
  let Bl = [];
  let Bm = 0;
  let Br = [];
  for (let i=n-1; i>=0; i--){
    let a = A[i];
    let canChoose = (n-i)%2==0;
    if (!canChoose){
      // push prev Bm?
      Bm = a;
    } else {
      if (Bm<a){
        Bl.push(Bm);
        Br.push(a);
      } else {
        Bl.push(a);
        Br.push(Bm);
      }
      Bm = 0;
    }
  }
  if (Bm) // why?
    Bl.push(Bm);
  L(A, {Bl, Br})
  let C = [];
  while (Bl.length || Br.length){
    if (Bl.length<Br.length){
      C.push(Br.pop())
    } else if (Bl.length>Br.length) {
      C.push(Bl.pop())
    } else {
      let lBl = Bl[Bl.length-1]
      let lBr = Br[Br.length-1]
      if (lBl<lBr){
        C.push(Bl.pop())
      } else {
        C.push(Br.pop())
      }
    }
  }
  L(C)
  for (let i=0; i<n-1; i++){
    if (C[i]>C[i+1])
      return false;
  }
  return true;
  let ans = 0;
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let A = ra();
      L('Ans:');
      print(calc(n, A) ? 'YES' : 'NO');
    }
}

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 n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    for (let i = arr.length - 1; i >= 0; i -= 2) {
        if (i && arr[i] < arr[i - 1]) {
            [arr[i], arr[i - 1]] = [arr[i - 1], arr[i]]
        }
    }
    // console.log(arr)
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] < arr[i - 1]) return false
    }
    return true
}

var tests = parseInt(readline());
    var n;
    var a;

    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        var prevMax = 0;
        var start = 0;
        var ans = 'YES';
        if (a.length & 1) {
            start = 1;
            prevMax = a[1];
        }
        for (var i = start; i < n; i+=2) {
            if (a[i] < prevMax || a[i+1] < prevMax) {
                ans = 'NO';
                break;
            }
            prevMax = Math.max(a[i], a[i+1]);
        }
        print(ans);
    }

var tests = parseInt(readline());
    var n;
    var a;

    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        var prevMax = 0;
        var ans = 'YES';
        for (var i = 0; i < n; i+=2) {
            if (i == n-1) {
                if (a[i] < a[i-1] && a[i] < a[i-2]) {
                    ans = 'NO';
                    break;
                }
            } else {
                if (a[i] < prevMax || a[i+1] < prevMax) {
                    ans = 'NO';
                    break;
                }
                prevMax = Math.max(a[i], a[i+1]);
            }
        }
        print(ans);
    }

 var tests = parseInt(readline());
    var n;
    var arr;

    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        arr = readline().split(' ').map(x=>parseInt(x));
        var prevMax = 0;
        var ans = 'YES';
        for (var i = 0; i < n; i+=2) {
            var max = arr[i];
            if (prevMax > max) {
                ans = 'NO';
                break;
            }
            if (i != n-1) {
                max = Math.max(arr[i], arr[i+1]);
                if (arr[i+1] < prevMax) {
                    ans = 'NO';
                    break;
                }
            }

            prevMax = max;
        }
        print(ans);
    }

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

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (n, a)=>{
    if (n < 3) return 'YES';

    if (n % 2 === 1) {
        a.unshift(0);
        n++;
    }

    for (let i = n - 2; i > 0; i -= 2) {
        let maxr = Math.max(a[i], a[i + 1]);
        let maxl = Math.max(a[i - 1], a[i - 2]);
        if (maxl > maxr) return 'NO';
    }

    return 'YES';
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

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

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (n, a)=>{
    if (n < 3) return 'YES';

    if (n % 2 === 1) {
        a.unshift(0);
        n++;
    }

    // console.log(`DEBUG a`, a);

    for (let i = n - 2; i > 0; i--) {
        let maxr = Math.max(a[i], a[i + 1]);
        let maxl = Math.max(a[i - 1], a[i - 2]);
        // console.log(`DEBUG i ${i} maxl ${maxl} maxr ${maxr}`);
        if (maxl > maxr) return 'NO';
    }

    return 'YES';
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}


A palindrome is a string that reads the same backward as forward. For example, the strings "z", "aaa", "aba", and "abccba" are palindromes, but "codeforces" and "ab" are not. You hate palindromes because they give you déjà vu.There is a string $$$s$$$. You must insert exactly one character 'a' somewhere in $$$s$$$. If it is possible to create a string that is not a palindrome, you should find one example. Otherwise, you should report that it is impossible.For example, suppose $$$s=$$$ "cbabc". By inserting an 'a', you can create "acbabc", "cababc", "cbaabc", "cbabac", or "cbabca". However "cbaabc" is a palindrome, so you must output one of the other options.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The only line of each test case contains a string $$$s$$$ consisting of lowercase English letters. The total length of all strings does not exceed $$$3\cdot 10^5$$$.

For each test case, if there is no solution, output "NO". Otherwise, output "YES" followed by your constructed string of length $$$|s|+1$$$ on the next line. If there are multiple solutions, you may print any. You can print each letter of "YES" and "NO" in any case (upper or lower).

YES
cbabac
YES
aab
YES
zaza
YES
baa
NO
YES
nutforajarofatuna

NoteThe first test case is described in the statement.In the second test case, we can make either "aab" or "aba". But "aba" is a palindrome, so "aab" is the only correct answer.In the third test case, "zaza" and "zzaa" are correct answers, but not "azza".In the fourth test case, "baa" is the only correct answer.In the fifth test case, we can only make "aa", which is a palindrome. So the answer is "NO".In the sixth test case, "anutforajaroftuna" is a palindrome, but inserting 'a' elsewhere is valid.

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    let s = rl();

    if (!palindrome(s + "a")) {
      cl("Yes");
      cl(s + "a");
    } else if (!palindrome("a" + s)) {
      cl("Yes");
      cl("a" + s);
    } else {
      cl("NO");
    }
  }
  function palindrome(_str) {
    return _str == _str.split("").reverse().join("");
  }
}

function solve() {
   var str = read();
   var str1 = str + 'a';
   var str2 = str1.split('').reverse().join('');
   var str3 = 'a' + str;
   var str4 = str3.split('').reverse().join('');
   if (str1 !== str2) {
      write('YES');
      write(str1);
      return;
   }
   if (str3 !== str4) {
      write('YES');
      write(str3);
      return;
   }
   write('no');
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   fs.readFile(inTextName ? path.join(__dirname, inTextName) : 0, 'utf8', function(err, data) {
      MEMORY = data.split('\r\n');
      init();
   });
} else {
   init();
}

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

function solve() {
   var str = read();
   var str1 = str + 'a';
   var str2 = str1.split('').reverse().join('');
   var str3 = 'a' + str;
   var str4 = str3.split('').reverse().join('');
   if (str1 !== str2) {
      write('YES');
      write(str1);
      return;
   }
   if (str3 !== str4) {
      write('YES');
      write(str3);
      return;
   }
   write('no');
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

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) {
    let a = 'a' + str
    let b = str + 'a'
    if (a === a.split('').reverse().join('')) {
        if (b === b.split('').reverse().join('')) {
            console.log('NO')
        } else {
            console.log('YES')
            console.log(b)
        }
    } else {
        console.log('YES')
        console.log(a)
    }
}

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

'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++];
}

var maxN = 21
var mod = 1000000007

// Make a Snippet for the code above this and then write your logic in main();

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

  Array(Number(xx)).fill(1).map((t, i) => {
    // const a = parseInt(readline());
    // var [n, p, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split('').map((x, iii) => {
      return x
    });
    var allA = true
    for (let j = 0; j < a.length; j++) {
      if (a[j] !== 'a') allA = false
    }
    if (allA) return console.log('NO')

    var ans = []
    var once = true
    for (let j = 0; j < a.length; j++) {
      if (a[a.length - j - 1] !== 'a' && once) {
        ans.push('a')
        once = false
      }
      ans.push(a[j])
    }
    console.log('YES')
    console.log(ans.join(''))
    // console.log(a)
  })
}

let input = '';

process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
    const lines = input.trim().split('\n').slice(1);

    for (let i=0; i<lines.length; i++) {
        const line = lines[i].trim();
        const line1 = 'a' + line;
        const line2 = line + 'a';
        let line1Flag = true, line2Flag = true;

        for (let j=0; j<line1.length; j++) {
            if (line1[j] !== line1[line1.length-1-j]) {
                line1Flag = false;
            }

            if (line2[j] !== line2[line2.length-1-j]) {
                line2Flag = false;
            }
        }

        if (line1Flag && line2Flag) {
            console.log('NO');
        } else if (line1Flag) {
            console.log('YES');
            console.log(line2);
        } else {
            console.log('YES');
            console.log(line1);
        }

    }
})

//////////////////////  Nodejs / Javascript Problem Solving /////////////////
/////////////////////* @author  Nawab Khairuzzaman Mohammad Kibria *////////

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

///////////////////////// END BASIC IO STREAM TEMPLATE //////////////////////

function insert(main_string, ins_string, pos) {
  if (typeof pos == "undefined") {
    pos = 0;
  }
  if (typeof ins_string == "undefined") {
    ins_string = "";
  }
  return main_string.slice(0, pos) + ins_string + main_string.slice(pos);
}

function reverseString(str) {
  // return a new array of strings
  const arrayStrings = str.split("");

  // reverse the new created array elements
  const reverseArray = arrayStrings.reverse();

  // join all elements of the array into a string
  const joinArray = reverseArray.join("");

  // return the reversed string
  return joinArray;
}

// Additional Functions ////////
function main() {
  let testCase = +readLine();
  const LETTER = "a";
  while (testCase--) {
    let f = 0;
    const word = readLine();
    let n = word.length + 1;
    let m = n - 1;
    let newWord = word.split("").filter((x) => {
      if (x !== "a") return x;
    });
    if (newWord.length === 0) {
      console.log("NO");
    } else {
      for (let i = 0; i < n / 2; i++) {
        let word1 = word.slice();
        let word2 = word.slice();
        const newWord1 = insert(word1, "a", i);
        const newWord2 = insert(word2, "a", m);
        const revWord1 = reverseString(newWord1);
        const revWord2 = reverseString(newWord2);
        if (revWord1 !== newWord1) {
          console.log("YES");
          console.log(newWord1);
          f = 1;
          break;
        } else if (revWord2 !== newWord2) {
          console.log("YES");
          console.log(newWord2);
          f = 1;
          break;
        }
        m--;
      }
    }
  }
}

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var s = next();
		var isOK = false;
		for(var j = 0; j < s.length; j++){
			if(s[j] != "a"){
				isOK = true;
				break;
			}
		}
		if(isOK){
			myout("YES");
			var s1 = s + "a";
			var isOK2 = false;
			for(var j = 0; j < s1.length; j++){
				if(s1[j] != s1[s1.length - 1 - j]){
					isOK2 = true;
					break;
				}
			}
			if(isOK2){
				myout(s + "a");
			}else{
				myout("a" + s);
			}
		}else{
			myout("NO");
		}
	}
}

function solve() {
   var str = read();
   var str1 = str + 'a';
   var str2 = str1.split('').reverse().join('');
   var str3 = 'a' + str;
   var str4 = str3.split('').reverse().join('');
   if (str1 !== str2) {
      write('YES');
      write(str1);
      return;
   }
   if (str3 !== str4) {
      write('YES');
      write(str3);
      return;
   }
   write('no');
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var readable = process.stdin;
      readable.once('readable', function() {
         MEMORY = ('' + readable.read()).split('\r\n');
         init();
      });
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

function reverseString(str) {
    return str;
}

var t=readline();
while(t--)
{
	var s=readline();
	var c=0;
	for(i=0;i<s.length;i++)
	{
		if(s[i]!='a')
		c=1;
	}
	if(c==0)
	print("NO");
	else{
		var s1='a'+s;
		var str="";
		var s2=s+'a';
		for(i=0;i<s1.length;i++)
		  str+=s1[s1.length-i-1];
		if(s1!=str){ print("YES");
		print(s1);
		}
		else {
			print("YES");
			print(s2);
		}
	}
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    let str = rl();

    if (checkPalindrome("a" + str) && checkPalindrome(str + "a")) {
      cl("NO");
    } else {
      cl("YES");
      cl(str.split("").reverse().join("") + "a");
    }
  }
  function checkPalindrome(_str) {
    return _str == _str.split("").reverse().join("");
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    let str = rl();

    if (checkPalindrome("a" + str) && checkPalindrome(str + "a")) {
      cl("NO");
    } else {
      cl("YES");
      cl(str + "a");
    }
  }
  function checkPalindrome(_str) {
    return _str == _str.split("").reverse().join("");
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    let str = rl().split("");
    let flags = false;
    let temp = "";

    for (let i = 0; i < str.length; i++) {
      // cl(str.join(""));
      str.splice(i, 0, "a");
      if (!checkPalindrome(str)) {
        flags = true;
        temp = [...str];
        break;
      }
      str.reverse().splice(i, 1);
    }
    if (!flags) {
      cl("NO");
    } else {
      cl("YES");
      cl(temp.reverse().join(""));
    }
  }
  function checkPalindrome(_str) {
    for (let i = 0; i < _str.length; i++) {
      if (_str[i] != _str[_str.length - i - 1]) {
        return false;
      }
    }
    return true;
    // return _str.join("") == _str.reverse().join("");
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    let str = rl().split("");
    let flags = false;
    let temp = "";

    for (let i = 0; i < str.length; i++) {
      // cl(str.join(""));
      str.splice(i, 0, "a");
      if (!checkPalindrome(str)) {
        flags = true;
        temp = [...str];
      }
      str.reverse().splice(i, 1);
    }
    if (!flags) {
      cl("NO");
    } else {
      cl("YES");
      cl(temp.join(""));
    }

    // cl(checkPalindrome(str));
  }
  function checkPalindrome(_str) {
    return _str.join("") == _str.reverse().join("");
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    let str = rl().split("");
    const loop = str.length;
    let flags = false;

    for (let i = 0; i < loop; i++) {
      str.splice(i, 0, "a");
      if (!checkPalindrome(str)) {
        flags = true;
      }
      str.reverse("").splice(i, 1);
      // cl(str.join(""));
    }
    if (!flags) {
      cl("No");
    } else {
      cl("Yes");
      str.unshift("a");
      cl(str.join(""));
    }

    // cl(checkPalindrome(str));
  }
  function checkPalindrome(_str) {
    return _str.join("") == _str.reverse().join("");
  }
}

function solve() {
   var str = read();
   var str1 = str + 'a';
   var str2 = str1.split('').reverse().join('');
   var str3 = 'a' + str;
   var str4 = str3.split('').reverse().join('');
   if (str1 !== str2) {
      write('YES');
      write(str1);
      return;
   }
   if (str3 !== str4) {
      write('YES');
      write(str3);
      return;
   }
   write('no');
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', function(err, data) {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var readable = process.stdin;
      readable.once('readable', function() {
         MEMORY = ('' + readable.read()).split('\r\n');
         init();
      });
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

var maxN = 21
var mod = 1000000007

// Make a Snippet for the code above this and then write your logic in main();

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

  Array(Number(xx)).fill(1).map((t, i) => {
    // const a = parseInt(readline());
    // var [n, p, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split('').map((x, iii) => {
      return x
    });
    if (a.length ===1 )return console.log('NO')
    var ans= []
    var once= true
    for (let j = 0; j < a.length; j++) {
      if(a[a.length-j-1] !== 'a' && once) {
        ans.push('a')
        once = false
      }
      ans.push(a[j])
    }
    console.log('YES')
    console.log(ans.join(''))
    // console.log(a)
  })
}

'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++];
}

var maxN = 21
var mod = 1000000007

// Make a Snippet for the code above this and then write your logic in main();

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

  Array(Number(xx)).fill(1).map((t, i) => {
    // const a = parseInt(readline());
    // var [n, p, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split('').map((x, iii) => {
      return x
    });
    if (a.length ===1 )return console.log('NO')
    if(a[0] === 'a') a.push('s')
    else a.push('a')
    console.log('YES')
    console.log(a.join(''))
    // console.log(a)
  })
}

let input = '';

process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
    const lines = input.trim().split('\n').slice(1);

    for (let i=0; i<lines.length; i++) {
        const line = lines[i].trim();
        let nextLine = '';

        if (line[line.length-1] !== 'a') {
            nextLine = 'a' + line;
        } else if (line[0] !== 'a') {
            nextLine = line + 'a';
        }

        if (nextLine.length === 0) {
            console.log('NO')
        } else {
            console.log(`YES\n${nextLine}`);
        }
    }
})