You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.

The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

codeforces round letter round
hbnyiyc joll joll un joll

var input = readline().split(" ").map(Number), n = input[0], m = input[1];
var lang1to2 = {}, lang2to1 = {};

for(var i = 0; i < m; i++){
	input = readline().split(" ");

	lang1to2[input[0]] = input[1];
	lang2to1[input[1]] = input[0];
}

var speech = readline().split(" ");

for(var i = 0; i < n; i++){
	if(lang1to2[speech[i]] != undefined){
		if(speech[i].length <= lang1to2[speech[i]].length){
			write(speech[i]);
		}
		else{
			write(lang1to2[speech[i]]);
		}
	}
	else{
		if(speech[i].length <= lang2to1[speech[i]].length){
			write(speech[i]);
		}
		else{
			write(lang2to1[speech[i]]);
		}
	}

	write(" ");
}

var m1 = {}, m2 = {};
var n, m;
var token = [];
var ans = "";

token = readline().split(' ');
n = parseInt(token[0]);
m = parseInt(token[1]);

for(var i=0;i<m;i++) {
  token = readline().split(' ');
  m1[token[0]]=token[1];
  m2[token[1]]=token[0];
}

token = readline().split(' ');

for(var i=0;i<n;i++) {
  var w1="", w2="";

  if(m1[token[i]]==null) {
    w2=token[i];
    w1=m2[w2];
  }
  else {
    w1=token[i];
    w2=m1[w1];
  }

  if(i>0) ans+=" ";

  if(w1.length<=w2.length) {
    ans+=w1;
  }
  else {
    ans+=w2;
  }
}

print(ans);

function main(n,m,arr,prof) {

    var ans = ""

    for(var i = 0 ; i < n ; i++){
      for(var j = 0 ; j  < m ; j++){
        if(prof[i] === arr[j][0]){
          if(prof[i].length > arr[j][1].length)ans = ans + arr[j][1] + " ";
          else ans = ans + arr[j][0] + " ";
          break;
        }
      }
    }

    print(ans);

}

//
// main(4,3,[["codeforces","codesecrof"],["contest","round"],["letter","message"]],
// ["codeforces","contest","letter","contest"])
//

var nm = readline().split(" ");

var arr = []

for(var i = 0 ; i < parseInt(nm[1]) ; i++){
  arr[i] = readline().split(" ");
}

var prof = readline().split(" ");

main(parseInt(nm[0]),parseInt(nm[1]),arr,prof);

var t = readline().split(' ');
var n = t[0];
var m = t[1];
var i = 0, inpStr1, slo1 = [], slo2 = [];

for(i=0; i<m; i++)
{
  inpStr1 = readline().split(' ');

  slo1[i] = inpStr1[0];
  slo2[i] = inpStr1[1];
}

var inpStr2 = readline().split(' '), outStr = "";

for(i=0; i<n; i++)
{
  for(var k=0; k<m; k++)
  {
    if (inpStr2[i] == slo1[k] && slo1[k].length > slo2[k].length)
    {
      outStr = outStr + slo2[k];
    }
    else if (inpStr2[i] == slo1[k])
    {
      outStr = outStr + slo1[k];
    }
  }
  if (i<n) outStr = outStr + " ";
}

print(outStr);

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

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

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

function printValues() {
	var parts = [];
	for (var i = 0; i < arguments.length; i += 2) {
		parts.push(arguments[i]+' = '+arguments[i+1]);
	}
	print(parts.join(', '));
}

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
    translate = {};
  for (var i = 0; i < m; ++i) {
    var tokens = tokenize(readline());
    translate[tokens[0]] = tokens[1];
  }
  var speech = tokenize(readline()),
      result = [];
  for (var i = 0; i < n; ++i) {
    var a = speech[i], b = translate[a];
    if (a.length <= b.length) {
      result.push(a);
    } else {
      result.push(b);
    }
  }
  print(result.join(' '));
}

main();

/* TEST CASE
input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
output
codeforces round letter round
input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
output
hbnyiyc joll joll un joll

*/

function main() {
	var splitted = readline().split(' ');
	var nWordsLectured = parseInt(splitted[0]);
	var nWordsInDictionary = parseInt(splitted[1]);
	var i;
	var wordMap = {};
	for (i = 0; i < nWordsInDictionary; i++) {
		splitted = readline().split(' ');
		if(splitted[0].length <= splitted[1].length) {
			wordMap[splitted[1]] = splitted[0];
		} else {
			wordMap[splitted[0]] = splitted[1];
		}
	}

	splitted = readline().split(' ');

	for (i = 0; i < nWordsLectured; i++) {
		var newShorter = wordMap[splitted[i]];
		if (newShorter != null) {
			splitted[i] = newShorter;
		}
	}
	print(splitted.join(' '));
}

main();

var line1 = readline().split(' ')
var n = line1[0];
var m = line1[1];
var words = {};

for (var i=0; i<m; i++) {
  var line = readline().split(' ')
  var key = line[0];
  var val = line[1];
  words[key] = val;
}

var lastline = readline().split(' ')
var answer = [];
for (var i=0; i<n; i++) {
  var word = lastline[i];
  var word2 = words[word];

  if (word.length <= word2.length) {
    answer[i] = word;
  } else {
    answer[i] = word2;
  }
}

print(answer.join(' '));

(function() {
    function createDictionary(count) {
        var result = [];
        for (var i = 0; i < count; ++i) {
            input = readline().split(' ');
            var a = input[0];
            var b = input[1];
            if (b.length >= a.length)
                b = a;
            result[a] = b;
        }
        return result;
    };

    function writeAnswer(answer) {
        for (i = 0; i < answer.count; ++i) {
            write(answer.get(answer, i));
            if (i < answer.count - 1)
                write(' ');
        }
    }

    var input = readline().split(' ');
    var n = parseInt(input[0]);
    var m = parseInt(input[1]);
    var inf = createDictionary(m);

    input = readline().split(' ');
    writeAnswer({
        count: n,
        data: input,
        dict: inf,
        get: function(self, index) {
            return self.dict[self.data[index]];
        }
    });
})()

//var input = "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}

function main(){
    var mapF = {};
    var mapS = {};
    var t = readline().split(' ');
    var n = parseInt(t[0]);
    var m = parseInt(t[1]);
    for(var i = 0; i < m; i++){
        var arr = readline().split(' ');
        mapF[arr[0]] = arr[1];
        mapS[arr[1]] = arr[0];
    }
    var text = readline().split(' ');
    var ans = "";
    for(var i = 0; i < text.length; i++){
        if(text[i] in mapF){
            var val = mapF[text[i]];
            if(val.length < text[i].length)
                ans += val;
            else
                ans += text[i];
        }else{
            var val = mapS[text[i]];
            if(val.length <= text[i].length)
                ans += val;
            else
                ans += text[i];
        }
        ans += " ";
    }
    print(ans);
}
main();

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, strs, di1 ={}, di2 = {}, c = 0,
lec, arr1 = [], arr = [];
rl.on('line', input => {
    if (n && m && c < m ) {
        arr.push(input);
        let str = arr[c].split(' ')
        di1[str[0]] = str[1]
        c++;
    } else if ( c >= m ) {
        lec = input.split(' ');
        c++;
        for (let j = 0; j < lec.length; j++) {
            if (lec[j].length > di1[lec[j]].length) {
                lec[j] = di1[lec[j]]
            }
        }
        console.log(lec.join(' '))
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

"use strict";

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

let [lectureLength, languageWords] = [null];
let wordsA = [], wordsB = [], speech = [];

readline.on('line', line => {
    if (!lectureLength) {
        [lectureLength, languageWords] = line.split(' ');
    } else if (wordsA.length < languageWords) {
        let [a, b] = line.split(' ');
        wordsA.push(a);
        wordsB.push(b);
    } else {
        speech = line.split(' ');
        readline.close();
    }
});

readline.on('close', () => {
    writeNote();
});

const writeNote = () => {
    let result = '';
    speech.map(word => {
        let comparator = wordsB[wordsA.indexOf(word)];
        let shorter = comparator.length < word.length ? comparator : word;
        result += shorter + ' ';
    })
    console.log(result.trim());
};

const input = [];

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

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

RL.on('close', () => {
  const [n, m] = input[0].split(' ').map(x => parseInt(x));
  const map = {};

  for (let i = 0; i < m; i += 1) {
    let [w1, w2] = input[i+1].split(' ');

    map[w1] = {len: w1.length, w: w2};
    map[w2] = {len: w2.length, w: w1};
  }

  const answer = [];
  const dict = input[m+1].split(' ');

  for (const w of dict) {
    if (map[w].len <= map[w].w.length) {
      answer.push(w);
    } else {
      answer.push(map[w].w);
    }
    answer.push(' ');
  }

  console.log(answer.join(''));
});

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

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

const store = {};

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);
	let dic = {};

	while (m--) {
		let [key, value] = readLine().split(' ');
		dic[key] = value;
	}

	let lec = readLine().split(' ');
	const res = lec.map(word =>
		word.length <= dic[word].length ? word : dic[word]
	);

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

var t = readline().split(' ');
var n = t[0];
var m = t[1];
var i = 0, inpStr1, slo1 = [], slo2 = [];

for(i=0; i<m; i++)
{
  inpStr1 = readline().split(' ');

  slo1[i] = inpStr1[0];
  slo2[i] = inpStr1[1];
}

var inpStr2 = readline().split(' '), outStr = "";

for(i=0; i<n; i++)
{
  for(var k=0; k<m; k++)
  {
    if (inpStr2[i] == slo1[k] && slo1[k].length > slo2[k].length)
    {
      outStr = outStr + slo2[k];
    }
    else
    {
      outStr = outStr + slo1[k];
    }
  }
  if (i>0 && i<n) outStr = outStr + " ";
}

print(outStr);

var line1 = readline().split(' ')
var n = line1[0];
var m = line1[1];
var words = {};

for (var i=0; i<m; i++) {
  var line = readline().split(' ')
  var key = line[0];
  var val = line[1];
  words[key] = val;
}

var lastline = readline().split(' ')
var answer = "";
for (var i=0; i<n; i++) {
  var word = lastline[i];
  var word2 = words[word];

  if (word.length <= word2.length) {
    answer += word;
  } else {
    answer += word2;
  }
}

print(answer);

var line0 = readline().split(' ')
print(line0)

//var input = "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}

function main(){
    var mapF = {};
    var mapS = {};
    var t = readline().split(' ');
    var n = parseInt(t[0]);
    var m = parseInt(t[1]);
    for(var i = 0; i < m; i++){
        var arr = readline().split(' ');
        mapF[arr[0]] = arr[1];
        mapS[arr[1]] = arr[0];
    }
    var text = readline().split(' ');
    var ans = "";
    for(var i = 0; i < text.length; i++){
        if(text[i] in mapF){
            var val = mapF[text[i]];
            if(val.length <= text[i].length)
                ans += val;
            else
                ans += text[i];
        }else{
            var val = mapS[text[i]];
            if(val.length < text[i].length)
                ans += val;
            else
                ans += text[i];
        }
        ans += " ";
    }
    print(ans);
}
main();

const input = [];

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

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

RL.on('close', () => {
  const [n, m] = input[0].split(' ').map(x => parseInt(x));
  const map = {};

  for (let i = 0; i < m; i += 1) {
    let [w1, w2] = input[i+1].split(' ');

    map[w1] = {len: w1.length, w: w2};
    map[w2] = {len: w2.length, w: w1};
  }

  const answer = [];
  const dict = input[m+1].split(' ');

  for (const w of dict) {
    if (map[w].len < map[w].w.length) {
      answer.push(w);
    } else {
      answer.push(map[w].w);
    }
    answer.push(' ');
  }

  console.log(answer.join(''));
});


T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.

The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.

For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)

NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.

for (var t = parseInt(readline()); t > 0; t --) {
	var n = parseInt(readline());
	var arr = readline().split(' ').map(x => parseInt(x));
	var total = 0;
	var largest = 0;
	for (var i = 0; i < n; i ++) {
		total += arr[i];
		if (arr[i] > largest) largest = arr[i];
	}
	var winner = '';
	if (n === 1) {
		winner = 'T';
	} else if (largest > total - largest) {
		winner = 'T';
	} else if (total % 2 === 0) {
		winner = 'HL';
	} else {
		winner = 'T';
	}
	print(winner);
}

var tc = parseInt(readline());
while (tc--) {
    var n = parseInt(readline());
    var ar = readline().split(' ').map(x => parseInt(x));
    var sum = ar.reduce((a, b) => a + b);
    var MX = Math.max(...ar);
    var ok = 0;
    if (MX > sum / 2) ok = 1;
    if (sum & 1) ok = 1;
    print(ok ? 'T' : 'HL');
}

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $(), a = $(n).sort(desc)
    if (n == 1) {
      log('T')
    } else {
      if (a[0] > a.sum() - a[0]) log('T')
      else log((a.sum() - a[0] - a[0]) % 2 ? 'T' : 'HL')
    }
  }
}

// Lang: Node.js
'use strict';
let x = '', y = 0;
let print = x => console.log(x);

process.stdin.on('data', inputStdin => x += inputStdin);
process.stdin.on('end', () => { x = x.split('\n'); main(); });
let readline = () => x[y++];

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

function main() {

  var tc = parseInt(readline());
  while (tc--) {
    var n = parseInt(readline());
    var ar = readline().split(" ").map((x) => parseInt(x));
    var sum = ar.reduce((a, b) => a + b);
    var MX = Math.max(...ar);
    var ok = 0;
    if (MX > sum / 2) ok = 1;
    if (sum & 1) ok = 1;
    print(ok ? "T" : "HL");
  }
}

for (var t = parseInt(readline()); t > 0; t --) {
	var n = parseInt(readline());
	var arr = readline().split(' ').map(x => parseInt(x));
	var total = 0;
	for (var i = 0; i < n; i ++) total += arr[i];
	if (n === 1) {
		print('T');
	} else if (total % 2 === 0) {
		print('HL');
	} else {
		print('T');
	}
}

for (var t = parseInt(readline()); t > 0; t --) {
	var n = parseInt(readline());
	var arr = readline().split(' ').map(x => parseInt(x));
	var total = 0;
	var oneCount = 0;
	for (var i = 0; i < n; i ++) {
		total += arr[i];
		if (arr[i] === 1) oneCount ++;
	}
	var winner = '';
	if (n === 1) {
		winner = 'T';
	} else if (total % 2 === 0) {
		winner = 'HL';
	} else {
		winner = 'T';
	}
	if (oneCount % 2 === 0 && oneCount !== 0) {
		if (winner === 'T') {
			winner = 'HL';
		} else {
			winner = 'T';
		}
	}
	print(winner);
}

var inp = readline().split(' ');
var m = parseInt(inp[0]);
var s = parseInt(inp[1]);

var largestArr = [], smallestArr = [];
for (var i = 0; i < m; i ++) {
	largestArr.push(0);
	smallestArr.push(1);
}

var largestOn = 0, smallestOn = m - 1;
for (var i = 0; i < s; i ++) {
	if (largestOn < m) {
		largestArr[largestOn] ++;
		if (largestArr[largestOn] === 9) largestOn ++;
	} else largestArr = [-1];

	if (smallestOn >= 0 && m <= s) {
		if (i >= m) {
			smallestArr[smallestOn] ++;
			if (smallestArr[smallestOn] === 9) smallestOn --;
		}
	} else smallestArr = [-1];
}

print(s === 0 ? '-1 -1' : smallestArr.join('') + ' ' + largestArr.join(''));

for (var t = parseInt(readline()); t > 0; t --) {
	var n = parseInt(readline());
	var arr = readline().split(' ').map(x => parseInt(x));
	var odds = 0;
	var evens = 0;
	for (var i = 0; i < n; i ++) {
		if (arr[i] % 2 === 0) {
			evens ++;
		} else {
			odds ++;
		}
	}
	if (evens <= odds) {
		print('HL');
	} else {
		print('T');
	}
}


You are given a string $$$s$$$ consisting only of lowercase Latin letters.You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.Let's call a string good if it is not a palindrome. Palindrome is a string which is read from left to right the same as from right to left. For example, strings "abacaba", "aa" and "z" are palindromes and strings "bba", "xd" are not.You have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — number of queries. Each of the next $$$t$$$ lines contains one string. The $$$i$$$-th line contains a string $$$s_i$$$ consisting only of lowercase Latin letter. It is guaranteed that the length of $$$s_i$$$ is from $$$1$$$ to $$$1000$$$ (inclusive).

Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query: -1 if it is impossible to obtain a good string by rearranging the letters of $$$s_i$$$ and any good string which can be obtained from the given one (by rearranging the letters) otherwise.

NoteIn the first query we cannot rearrange letters to obtain a good string.Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".In the third query we can do nothing to obtain a good string.

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

let l = 0;
let t = 0
rl.on('line', (input) => {
    if (l === t + 1) {
        return 0
    }
    if (l === 0) {
        t = parseInt(input)
    } else {
        let s = input.split('')
        s.sort()
        if (s[0] !== s[s.length - 1]) {
            console.log(s.join(""))
        } else {
            console.log(-1)
        }
    }
    l++
});

"use strict";

const mySet = new Set();
const arr = new Array(26).fill(null);

const input = [];
const RL = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
RL.on("line", line => {
  input.push(line.trim());
});
RL.on("close", () => {
  const N = +input[0];
  for (let i = 1; i <= N; i += 1) {
    const setSize = isImpossible(input[i]);
    if (setSize === 1) {
      console.log(-1);
      continue;
    }

    initArray();
    solve(input[i]);
  }
});

function isImpossible(str) {
  mySet.clear();
  for (let char of str) {
    mySet.add(char);
  }
  return mySet.size;
}

function initArray() {
  for (let i = 0; i < 26; i += 1) {
    arr[i] = 0;
  }
}

function isPalindrome(str) {
  const shrinked = arr.map(ele => {
    return ele % 2;
  });

  let count = 0;
  shrinked.forEach(ele => {
    if (ele === 1) {
      count += 1;
    }
  });

  if (count >= 2) {
    return false;
  }

  return true;
}

function solve(str) {
  for (let char of str) {
    arr[char.codePointAt(0) - "a".codePointAt(0)] += 1;
  }

  const answer = isPalindrome(arr);
  if (answer === false) {
    console.log(str);
    return;
  }

  let good = "";
  let oddValue = -1;
  let oddIndex = -1;

  arr.forEach((value, index) => {
    if (value === 0) {
      return;
    }

    if (value % 2 === 1) {
      oddValue = value;
      oddIndex = index;
      return;
    }

    const left = good.slice(0, parseInt(good.length / 2));
    const right = good.slice(parseInt(good.length / 2), good.length);
    const middle = String.fromCodePoint(index + "a".codePointAt(0)).repeat(
      value
    );

    good = left + middle + right;
  });

  if (oddIndex !== -1) {
    const left = good.slice(0, parseInt(good.length / 2));
    const right = good.slice(parseInt(good.length / 2), good.length);
    const middle = String.fromCodePoint(oddIndex + "a".codePointAt(0)).repeat(
      oddValue
    );

    good = left + middle + right;
  }

  const temp = good.split("");
  [temp[0], temp[parseInt(temp.length / 2)]] = [
    temp[parseInt(temp.length / 2)],
    temp[0]
  ];
  console.log(`${temp.join("")}`);
}

// NYAN NYAN
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
// ░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
// ░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
// ░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
// ░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
// ░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
// ░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
// ░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
// ░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
// ░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
// ░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
// ░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

// 백준의 노드 버전이 너무 낮아 babel 사용.
// 풀이는 solve() 함수에 있음.

const CODEFORCES_NODE = "cf";
const CODEFORCES_V8 = "cf-v8";
const BEAKJOON = "bj";
const TEST = "test";
// var SITE = BEAKJOON;
var SITE = CODEFORCES_NODE;
var DEBUG = false;

if(SITE == BEAKJOON){
  if (!String.prototype.startsWith) {
    String.prototype.startsWith = function(search, pos) {
      return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
    };
  }
  if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
      if (this_len === undefined || this_len > this.length) {
        this_len = this.length;
      }
      return this.substring(this_len - search.length, this_len) === search;
    };
  }
  if (!String.prototype.repeat) {
    String.prototype.repeat = function(count) {
      'use strict';
      if (this == null) {
        throw new TypeError('can\'t convert ' + this + ' to object');
      }
      var str = '' + this;
      count = +count;
      if (count != count) {
        count = 0;
      }
      if (count < 0) {
        throw new RangeError('repeat count must be non-negative');
      }
      if (count == Infinity) {
        throw new RangeError('repeat count must be less than infinity');
      }
      count = Math.floor(count);
      if (str.length == 0 || count == 0) {
        return '';
      }
      // Ensuring count is a 31-bit integer allows us to heavily optimize the
      // main part. But anyway, most current (August 2014) browsers can't handle
      // strings 1 << 28 chars or longer, so:
      if (str.length * count >= 1 << 28) {
        throw new RangeError('repeat count must not overflow maximum string size');
      }
      var maxCount = str.length * count;
      count = Math.floor(Math.log(count) / Math.log(2));
      while (count) {
         str += str;
         count--;
      }
      str += str.substring(0, maxCount - str.length);
      return str;
    }
  }
}

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

Function.prototype.repeat = function(times){
  for(let i = 0; i < times; i++){
    this();
  }
}

Array.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){
  const N = this.length;
  let maxsum = defaultValue;
  let cursum = defaultValue;
  let cur;
  for(var ii = 0; ii < N; ii++){
    cur = this[ii];
    if(cursum + cur > 0){
      if(cur > cursum + cur){
        cursum = cur;
      } else cursum += cur;
    } else {
      cursum = cur;
      if(maxsum < cursum){
        maxsum = cursum;
      }
    }
    if(maxsum < cursum){
      maxsum = cursum;
    }
  }
  this.maxConsecutiveSum = maxsum;
  return maxsum;
}

try {
  require('manakin').global;
  // require ("babel-polyfill");
} catch (error) {

}
try {
  process.argv.forEach(function (val, index, array) {
    if (val.startsWith("site")) {
      switch (val.split("=")[1]) {
        case "test":
          // console.log('change site to test')
          SITE = TEST;
          break;
        case "cf-node":
          // console.log('change site to cf')
          SITE = CODEFORCES_NODE;
          break;
        case "cf":
          // console.log('change site to cf')
          SITE = CODEFORCES_NODE;
          break;
        case "cf-v8":
          // console.log('change site to cf')
          SITE = CODEFORCES_V8;
          break;
        case "bj":
          // console.log('change site to bj')
          SITE = BEAKJOON;
          break;
      }
    }
    if (val.startsWith("debug")) {
      switch (val.split("=")[1]) {
        case "true":
          DEBUG = true;
          break;
        case "false":
          DEBUG = false;
          break;
      }
    }
  });
} catch (error) {
}

let inputFilePath = '';
switch(SITE){
  case TEST:
    const config = require('config');
    var fs = require("fs");
    var path = require('path');
    inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, "input.txt");
    break;
  default:
    inputFilePath = './input.txt';
    break;
}
const INPUTFILEPATH = inputFilePath;

// if (!String.prototype.endsWith) {
// 	String.prototype.endsWith = function(search, this_len) {
// 		if (this_len === undefined || this_len > this.length) {
// 			this_len = this.length;
// 		}
// 		return this.substring(this_len - search.length, this_len) === search;
// 	};
// }
// if (!Array.prototype.includes) {
//   Array.prototype.includes = function (target) {
//     return this.indexOf(target) !== -1
//   }
// }

const newLine = '\n';
var ans;
var inputText = "";
var lineCount = 0;
var lines;
var input;
var readline;
var getlines;
var lineOpen = false;
var readingLine = '';

var clockStart;
var clock;

var print;
print = console.log;
var it;
var step;
function EnableLogging(){
  it = console.info;
  step = console.success;
}
function DisableLogging(){
  it = function it(params) {
    return 0;
  }
  step = it;
}
if (DEBUG) {
  EnableLogging();
  clock = function(start) {
    if ( !start ) return process.hrtime();
    var end = process.hrtime(start);
    return Math.round((end[0]*1000) + (end[1]/1000000));
  }
} else {
  DisableLogging();
}

// prepares test data. to replace line input, assign arrays to lines variable.
function prepareTestData() {
  // it(lines);

  // lines = ['custom line 1', 'custom line 2'];
}

// executes exactly once for both test and run. execution time will be included to elapsed time.
const prepareSolve = () => {

}

function power(x, y) {    //분할 정복을 이용하여 x^y 구하기
  let ret = 1;
  while (y > 0) {
    if (y % 2) {
        ret *= x;
        ret %= P;
    }
    x *= x;
    x %= P;
    y /= 2;
  }
  return ret;
}

function createArray(lengths) {
  var arr = new Array(lengths || 0),
    i = lengths;
  if (arguments.length > 1) {
    var args = Array.prototype.slice.call(arguments, 1);
    while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);
  }
  return arr;
}

function numericSortList(list){
  list.sort((a,b)=>a-b);
}

function getRectangleIntersection(r1, r2)
{
    if(r1.x > r2.x+r2.w) return null;
    if(r1.x+r1.w < r2.x) return null;
    if(r1.y > r2.y+r2.h) return null;
    if(r1.y+r1.h < r2.y) return null;

    var rect = {};
    rect.x = Math.max(r1.x, r2.x);
    rect.y = Math.max(r1.y, r2.y);
    rect.w = Math.min(r1.x+r1.w, r2.x+r2.w)-rect.x;
    rect.h = Math.min(r1.y+r1.h, r2.y+r2.h)-rect.y;

    return rect;
}

function getRandomNumber(to, from){
  if(from == undefined){
    return Math.floor(Math.random()*to + 1);
  }
  return Math.floor(Math.random()*(to - from) + from);
}

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ MAIN SOLVE FUNCTION ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

function solve(){
  var cases = readInts()[0];
  it(cases);
  for(var i = 0; i < cases; i++){
    it(i);

    /**
     * @type {string}
     */
    var str = readline();
    it(str);

    var charToCount = {};

    for(var c of str){
      it(c);
      if(charToCount[c]){
        ++charToCount[c];
      } else charToCount[c] = 1;
    }

    if(Object.keys(charToCount).length <= 1){
      print('-1');
      continue;
    }

    var newStr = '';

    Object.keys(charToCount).forEach(function(key) {
      for(var k = 0; k < charToCount[key]; k++){
        it('new char : ' + key)
        newStr += key;
      }
    });

    print(newStr);
  }
}

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

function resetRead(){
  lineCount = 0;
}

function checkMemoryUsage() {
  it(process.memoryUsage());
}

function readOne(separator=' ') {
  if(lineOpen && readingLine != null){
  // if(lineOpen){
    // it(readingLine);
    let splitPos = readingLine.search(separator)

    let ret = readingLine.slice(0, splitPos);
    if(splitPos == -1){
      // it('close');
      ret = readingLine;
      readingLine = '';
      lineOpen = false;
    }
    readingLine = readingLine.substr(splitPos + 1)
    // it(ret, readingLine, splitPos);
    return ret;
  } else {
    readingLine = readline();
    lineOpen = true;
    if(readingLine == null) return '';
    return readOne(separator);
  }
}

function readInts() {
  try {
    lineOpen = false;
    return readline()
      .split(" ")
      .map(x => parseInt(x));
  } catch (error) {
    console.error(error);
    return null;
  }
}

switch (SITE) {
  case TEST:
    var fs = require("fs");
    var path = require('path');
    // input = fs.createReadStream(path.resolve(__dirname, "input.txt"), {
    //   encoding: "utf8"
    // });
    input = fs.createReadStream(INPUTFILEPATH, {
      encoding: "utf8"
    });

    function inputListener(line) {
      console.log(line);
      if(line.startsWith('end')){
        console.log('end');
        closing();
      }
      if (!line) {
        closing();
      }
      lineCount++;
      inputText += line + "\r\n";
    }

    function readlines() {
      const readline = require("readline");
      const rl = readline.createInterface({
        input,
        output: process.stdout,
        terminal: false
      });
      rl.on("line", inputListener);
      rl.on('close', closing);
    }

    getlines = function* (inputText) {
      var lines = inputText.split(/\r?\n/);
      for (let line of lines) {
        yield line + newLine;
      }
    }

    readline = function () {
      return lines.next().value.trim();
    }

    readlines();

    break;

  case CODEFORCES_NODE:
    input = process.stdin;

    function inputListener(line) {
      if (!line) {
        closing();
      }
      lineCount++;
      inputText += line + "\r\n";
    }

    function readlines() {
      const readline = require("readline");
      const rl = readline.createInterface({
        input,
        output: process.stdout,
        terminal: false
      });
      rl.on("line", inputListener);
      rl.on('close', closing);
    }

    getlines = function* (inputText) {
      var lines = inputText.split(/\r?\n/);
      for (let line of lines) {
        yield line + newLine;
      }
    }

    readline = function () {
      return lines.next().value.trim();
    }

    readlines();

    break;
  case BEAKJOON:
    var fs = require('fs');
    if (DEBUG) {
      // input = fs.readFileSync('./input.txt').toString();
      inputText = fs.readFileSync(INPUTFILEPATH).toString();

    } else {
      inputText = fs.readFileSync('/dev/stdin').toString();
    }

    readline = function () {
      lineCount++;
      let line = lines[lineCount - 1];
      if (line)
        return lines[lineCount - 1].trim();
      else return null;
    }

    getlines = function (inputText) {
      lineCount = 0;
      return inputText.split(/\r?\n/);
    }

    // lines = getlines(input);
    closing();
    break;
  default:
    break;
}

function closing() {
  if(DEBUG){
    DisableLogging();
    const prepareClock = clock();
    lines = getlines(inputText);
    prepareSolve();
    const prepareClockElapsedTime = clock(prepareClock);
    EnableLogging();
    prepareTestData();
    solve();
    resetRead();
    console.warn('performance check');
    DisableLogging();
    clockStart = clock();
    // lines = getlines(inputText);
    solve();
    console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);
    EnableLogging();
    process.exit();
  } else {
    lines = getlines(inputText);
    prepareSolve();
    solve();
    process.exit();
  }
}

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

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

  const arr = [...str];
  arr.sort();

  const r = arr.join('');
  const reverseR = arr.reverse().join('');

  if (r === reverseR) {
    console.log(-1);
  }
  else {
    console.log(r);
  }

  c++;
});

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

  let l=0;
  let t=0
  rl.on('line', (input) => {
     if(l===t+1)
     {
         return 0
     }
    if (l==0) {
          t=parseInt(input)
        } else {
           let s= input.split('')
           s.sort()
           let isPal = true
           for(let i=0;i<s.length/2&&isPal;i++){
               if(s[i]!==s[s.length-i-1]){
                   console.log(s.join(""))
                   isPal = false
               }
           }
           if(isPal){
               console.log(-1)
           }
}
l++
});

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

  let l=0;
  let t=0
  rl.on('line', (input) => {
     if(l === t + 1)
     {
         return 0
     }
    if (l==0) {
          t=parseInt(input)
        } else {
           let s = input.split('')
           s.sort()
               if(s[0] !== s[s.length-1]){
                   console.log(s.join(""))
               } else {
                console.log(-1)
               }
           }
    l++
});

'use strict'

var a = parseInt(readline());
var i=0;
var arr=[];

for(i;i<a;i++){
    arr[i]=readline();
}

function hwbh(a){
    var p=0;
    var i=0;
    var n='';
    for(i in a){
        if(a[i]!==a[0]){
            p=i;
            break;
        }
    }
    if(p==0){
        print('-1');
    }else{
        n=a[0];
        a[0]=a[p];
        a[p]=n;
        print(a.join(''));
    }

}
var j;
var p;
for(i in arr){
    p=0;
    for(j=0;j<=(arr[i].length-1)/2;j++){
        if(arr[i].length==1){
            print('-1');
            p=-1;
            break;
        }else if(arr[i][j]!==arr[i][arr[i].length-j-1]){
            p=1;
        }

    }
    if(p==1){
        print(arr[i]);
    }else if(p==0)
        hwbh(arr[i].split(''));
}

var t = function () {
    var input = readline();
    return parseInt(input);
} ();

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

    var good = "";

    var possible = false;
    for(var j=1; j<line.length; j++) {
        if( line[0] != line[j] ) {
            possible = true;
            other = j;
            break;
        }
    }
    if( possible === false ) {
        print(-1);
    } else {
        print( line[0] + line.substr(1, j-1) + line.substr(j+1) + line[j] )
    }

}

var t = function () {
    var input = readline();
    return parseInt(input);
} ();

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

    line = line.split("").sort().toString().replace(/,/g, '');

    if(line[0]===line[line.length-1]) {
        print(-1);
    } else {
        print(line);
    }
}

var t = parseInt(readline())
var result = []

for(var i = 0; i < t; i++)
{
    var str = readline();
    var s = []
    var len = str.length;

    for(var j = 0; j < len; j++)
    {
        s.push(str[j]);
    }

    var same = 1;
    var good = 1;

    for(j = 0; j < len; j++)
    {
        if(s[j] != s[0])
        {
            same = 0;
            index = j;
            break;
        }
    }
    if(same == 1)
    {
        result.push("-1");
    }
    else
    {
        for(var j = 0; j < len; j++)
        {
            if(s[j] != s[len - 1 - j])
            {
                good = 0;
                break;
            }
        }
        if(good == 1)
        {
            var memory = s[0];
            s[0] = s[index];
            s[index] = memory;
        }

        string = ""
        for(var j = 0; j < len; j++)
        {
            string += s[j];
        }

        result.push(string);
    }
}

for(var i = 0; i < t; i++)
{
    print(result[i]);
}

var t = readline();
var s = '';

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

	var s = readline();

	var letter = '';
	var output = -1;

	for (var j=1; j<s.length; j++){
		if (s.charAt(j) != s.charAt(0)) {
			letter = s.charAt(j);
			s = s.replace(letter, '');
			s = s.concat(letter);
			output = s;
			break;
		} else output = -1;
	}
	print(output);
}

//var input = readline()
var k = readline()

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

    var m = n.split('').sort().join('')
    // //print('sort: '+ m)

    // var L = Math.ceil(n.length/2)-1
    // var middle = n[L]
    // var first = n[0]
    // //print(first +' '+ middle)

    // arr.splice(0,1,middle)
    // arr.splice(L,1,first)
    // var change = arr.join('')
    // //print(change)

    // var a = n.split("").reverse().join("")
    // var c = /^(.)\1+$/.test(n) // check input same letter
    // //print(c)

     if(m[0] == m.slice(-1)) print(-1)
    // else if(n == a) print(change)
     else print (m)

}

"use strict";

const mySet=new Set();
const arr=new Array(26).fill(null);

const input = [];
const RL = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
RL.on("line", line => {
  input.push(line.trim());
});
RL.on("close", () => {
  const N=+input[0];
  for(let i=1; i<=N; i+=1){
    const setSize=isImpossible(input[i]);
    if(setSize===1){
      console.log(-1);
      continue;
    }

    initArray();
    solve(input[i]);
  }
});

function isImpossible(str){
  mySet.clear();
  for(let char of str){
    mySet.add(char);
  }
  return mySet.size;
}

function initArray(){
  for(let i=0; i<26; i+=1){
    arr[i]=0;
  }
}

function isPalindrome(str){
  const shrinked=arr.map(ele=>{
    return ele%2;
  });

  let count=0;
  shrinked.forEach(ele=>{
    if(ele===1){
      count+=1;
    }
  });

  if(count>=2){
    return false;
  }

  return true;
}

function solve(str){
  for(let char of str){
    arr[char.codePointAt(0)-"a".codePointAt(0)]+=1;
  }

  const answer=isPalindrome(arr);
  if(answer===false){
    console.log(str);
  }

  let good="";
  let oddValue=-1;
  let oddIndex=-1;

  arr.forEach((value, index)=>{
    if(value===0){
      return;
    }

    if(value%2===1){
      oddValue=value;
      oddIndex=index;
      return;
    }

    const left=good.slice(0, good.length/2);
    const right=good.slice(good.length/2, good.length);
    const middle=String.fromCodePoint(index+"a".codePointAt(0)).repeat(value);

    good=left+middle+right;
  });

  if(oddIndex!==-1){
    const left=good.slice(0, good.length/2);
    const right=good.slice(good.length/2, good.length);
    const middle=String.fromCodePoint(oddIndex+"a".codePointAt(0)).repeat(oddValue);

    good=left+middle+right;
  }

  const temp=good.split('');
  [temp[0], temp[parseInt(temp.length/2)]]=[temp[parseInt(temp.length/2)], temp[0]];
  console.log(`${temp.join('')}`);
}

"use strict";

const mySet=new Set();
const arr=new Array(26).fill(null);

const input = [];
const RL = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
RL.on("line", line => {
  input.push(line.trim());
});
RL.on("close", () => {
  const N=+input[0];
  for(let i=1; i<=N; i+=1){
    const setSize=isImpossible(input[i]);
    if(setSize===1){
      console.log(-1);
      continue;
    }

    initArray();
    solve(input[i]);
  }
});

function isImpossible(str){
  mySet.clear();
  for(let char of str){
    mySet.add(char);
  }
  return mySet.size;
}

function initArray(){
  for(let i=0; i<26; i+=1){
    arr[i]=0;
  }
}

function isPalindrome(str){
  const shrinked=arr.map(ele=>{
    return ele%2;
  });

  let count=0;
  shrinked.forEach(ele=>{
    if(ele===1){
      count+=1;
    }
  });

  if(count>=2){
    return false;
  }

  return true;
}

function solve(str){
  for(let char of str){
    arr[char.codePointAt(0)-"a".codePointAt(0)]+=1;
  }

  const answer=isPalindrome(arr);
  if(answer===false){
    console.log(str);
  }

  let good="";
  let oddValue=-1;
  let oddIndex=-1;

  arr.forEach((value, index)=>{
    if(value===0){
      return;
    }

    if(value%2===1){
      oddValue=value;
      oddIndex=index;
      return;
    }

    const left=good.slice(0, parseInt(good.length/2));
    const right=good.slice(parseInt(good.length/2), good.length);
    const middle=String.fromCodePoint(index+"a".codePointAt(0)).repeat(value);

    good=left+middle+right;
  });

  if(oddIndex!==-1){
    const left=good.slice(0, parseInt(good.length/2));
    const right=good.slice(parseInt(good.length/2), good.length);
    const middle=String.fromCodePoint(oddIndex+"a".codePointAt(0)).repeat(oddValue);

    good=left+middle+right;
  }

  const temp=good.split('');
  [temp[0], temp[parseInt(temp.length/2)]]=[temp[parseInt(temp.length/2)], temp[0]];
  console.log(`${temp.join('')}`);
}

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

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

  const arr = [...str];
  arr.sort();

  const r = arr.join('');

  if (r === str) {
    console.log(-1);
  }
  else {
    console.log(r);
  }

  c++;
});

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

  let l=0;
  let t=0
  rl.on('line', (input) => {
     if(l===t+1)
     {
         return 0
     }
    if (l==0) {
          t=parseInt(input)
        } else {
           rl.close();
           let s= input.split('')
           s.sort()
           let isPal = true
           for(let i=0;i<s.length/2&&isPal;i++){
               if(s[i]!==s[s.length-i-1]){
                   console.log(s.join(""))
                   isPal = false
               }
           }
           if(isPal){
               console.log(-1)
           }
}
l++
});

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

  let l=0;
  let t=0
  rl.on('line', (input) => {
     if(l===t+1)
     {
         return 0
     }
    if (l==0) {
          t=parseInt(input)
        } else {
           rl.close();
           let s= input.split('')
           s.sort()
           let isPal = true
           for(let i=0;i<s.length/2;i++){
               if(s[i]!==s[s.length-i-1]){
                   console.log(s.join(""))
                   isPal = false
               }
           }
           if(isPal){
               console.log(-1)
           }
}
l++
});

'use strict'

var a = parseInt(readline());
var i=0;
var arr=[];
for(i;i<a;i++){
    arr[i]=readline();
}

function hwbh(a){
    var p=0;
    var i=0;
    var n='';
    for(i in a){
        if(a[i]!==a[0]){
            p=i;
            break;
        }
    }
    if(p==0){
        print('-1');
    }else{
        n=a[0];
        a[0]=a[p];
        a[p]=n;
        print(a.join(''));
    }

}
var j;
var p;
for(i in arr){
    p=0;
    for(j=0;j<=(arr[i].length-1)/2;j++){
        if(arr[i].length==1){
            print('-1');
            continue;
        }else if(arr[i][j]!==arr[i][arr[i].length-j-1]){
            p=1;
        }

    }
    if(p==1){
        print(arr[i]);
    }else
        hwbh(arr[i].split(''));
}

var t = function () {
    var input = readline();
    return parseInt(input);
} ();

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

    var good = "";

    var possible = false;
    for(var j=1; j<line.length; j++) {
        if( line[0] != line[j] ) {
            possible = true;
            other = j;
            break;
        }
    }
    if( possible === false ) {
        print(-1);
    } else {
        if(j==1) {
            print(line)
        } else {
            print( line[0] + line.substr(1, j-1) + line.substr(j+1) + line[j] )
        }
    }

}

var t = function () {
    var input = readline();
    return parseInt(input);
} ();

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

    var good = "";

    var possible = false;
    for(var j=1; j<line.length; j++) {
        if( line[0] != line[j] ) {
            possible = true;
            other = j;
            break;
        }
    }
    if( possible === false ) {
        print(-1);
    } else {
        if(j==1) {
            print(line)
        } else {
            print( line[0] + line[j] + line.substr(1, j-1) + line.substr(j+1))
        }
    }

}

var t = parseInt(readline())
var result = []

for(var i = 0; i < t; i++)
{
    var str = readline();
    var s = []
    var len = s.length;

    for(var j = 0; j < len; j++)
    {
        s.push(str[j]);
    }

    var same = 1;
    var good = 1;

    for(j = 0; j < len; j++)
    {
        if(s[j] != s[0])
        {
            same = 0;
            index = j;
            break;
        }
    }
    if(same == 1)
    {
        result.push("-1");
    }
    else
    {
        for(var j = 0; j < len; j++)
        {
            if(s[j] != s[length - 1 - j])
            {
                good = 0;
                break;
            }
        }
        if(good == 1)
        {
            var memory = s[0];
            s[0] = s[index];
            s[index] = memory;
        }

        string = ""
        for(var j = 0; j < len; j++)
        {
            string += s[j];
        }

        result.push(string);
    }
}

for(var i = 0; i < t; i++)
{
    print(result[i]);
}

//var input = readline()
var k = readline()

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

    var m = n.split('').sort().join('')

    // var L = Math.ceil(n.length/2)-1
    // var middle = n[L]
    // var first = n[0]
    // //print(first +' '+ middle)

    // arr.splice(0,1,middle)
    // arr.splice(L,1,first)
    // var change = arr.join('')
    // //print(change)

    // var a = n.split("").reverse().join("")
     var c = /^(.)\1+$/.test(n) // check input same letter
    // //print(c)

     if(c) print(-1)
    // else if(n == a) print(change)
     else print (n)

}

//var input = readline()
var k = readline()

for(var i=0; i<k; i++){
    var n = readline()
    var ar = n
    var arr = ar.split('')

    var L = Math.ceil(n.length/2)-1
    var middle = n[L]
    var first = n[0]
    //print(first +' '+ middle)

    arr.splice(0,1,middle)
    arr.splice(L,1,first)
    var change = arr.join('')
    //print(change)

    var a = n.split("").reverse().join("")
    var c = /^(.)\1+$/.test(n) // check input same letter

    if(c) print(-1)
    else if(n == a) print(change)
    else print (n)

}


A flowerbed has many flowers and two fountains.You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.

The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000,  - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain. Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower. It is guaranteed that all n + 2 points in the input are distinct.

Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

NoteThe first sample is (r12 = 5, r22 = 1):  The second sample is (r12 = 1, r22 = 32):

var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [p1, p2];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));
}

for (i = 0; i < points.length; ++i) {
    points[i] = {
        sqrLength1: sqrLength(p1, points[i]),
        sqrLength2: sqrLength(p2, points[i])
    }
}

points.sort(function (a, b) {
    return a.sqrLength1 === b.sqrLength1 ? 0 : a.sqrLength1 < b.sqrLength1 ? -1 : 1;
});

var result = Infinity;

for (i = 0; i < points.length; ++i) {
    var subResult = 0;

    for (var j = i + 1; j < points.length; ++j) {
        subResult = Math.max(subResult, points[j].sqrLength2);
    }

    subResult = points[i].sqrLength1 + subResult;

    result = Math.min(result, subResult);
}

write(result);

var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
    arr[i][0] = Number(arr[i][0]);
    arr[i][1] = Number(arr[i][1]);
}
arr[n] = [Number(str[1]), Number(str[2])];
arr[n + 1] = [Number(str[3]), Number(str[4])];

function dis(a, b) {
    var aa = a[0] - b[0], bb = a[1] - b[1];
    return aa * aa + bb * bb;
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 1; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(len2, dis(arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);

var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    distantions[i+1] = [];
    distantions[i+1][0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    distantions[i+1][1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
}
distantions[0] = [];
distantions[0][0] = 0;
distantions[0][1] = 0;

var result = Number.MAX_VALUE;
for (var i = 0; i < n + 1; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n + 1; j++) {
        if (distantions[j][0] > r1) {
            r2 = Math.max(r2, distantions[j][1]);
        }
    }
    result = Math.min(result, r1 + r2);
}

print(result);

var arg = readline().split(' ');
var N = arg[0];
var A = [arg[1], arg[2]];
var B = [arg[3], arg[4]];

var dist = (a, b) =>
  Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2);
var d = [], P;
for (var i = 0; i < N; ++i) {
  P = readline().split(' ');
  d.push([dist(A, P), dist(B, P)]);
}
d.sort((a, b) => {
  if (a[0] < b[0]) {
    return -1;
  } else if (a[0] > b[0]) {
    return 1;
  }
  if (a[1] < b[1]) {
    return -1;
  } else if (a[1] > b[1]) {
    return 1;
  }
  return 0;
});

var ra, rb, ans = Infinity;
for (var i = -1; i < N; ++i) {
  ra = i > -1 ? d[i][0] : 0;
  rb = 0;
  for (var j = i + 1; j < N; ++j) {
    rb = Math.max(rb, d[j][1]);
  }
  ans = Math.min(ans, ra+rb);
}
print(ans);

var Point = function(coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function(p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx*dx + dy*dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [0];
var sqrLengths2 = [0];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    sqrLengths1.push(sqrLength(p1, points[i]));
    sqrLengths2.push(sqrLength(p2, points[i]));
}

var check = function(sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

for (var j = 0; j < sqrLengths1.length; ++j) {
    var sqrR1 = sqrLengths1[j];

    var a2 = 0;
    var b2 = 100000000;

    while (b2 - a2 > 1) {
        var m2 = Math.round((a2 + b2) / 2.0);
        var sqrR2 =  m2*m2;

        if (check(sqrR1, sqrR2)) {
            b2 = m2;
        } else {
            a2 = m2;
        }
    }

    MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));
}

write(MIN);

var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
}
arr[n] = [str[1], str[2]];
arr[n + 1] = [str[3], str[4]];

function dis(a, b) {
    return (a[0] - b[0]) * (a[0] - b[0]) +
        (a[1] - b[1]) * (a[1] - b[1]);
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 2; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n + 2; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(dis(len2, arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);

var str = readline().split(" ", 5);
var n = Number(str[0]);
var arr = new Array(n + 2);
for (var i = 0; i < n; ++i) {
    arr[i] = readline().split(" ", 2);
    arr[i][0] = Number(arr[i][0]);
    arr[i][1] = Number(arr[i][1]);
}
arr[n] = [Number(str[1]), Number(str[2])];
arr[n + 1] = [Number(str[3]), Number(str[4])];

function dis(a, b) {
    var aa = a[0] - b[0], bb = a[1] - b[1];
    return aa * bb;
}

var ans = Number.MAX_SAFE_INTEGER;
for (var i = 0; i < n + 1; ++i) {
    var len = dis(arr[n], arr[i]);
    var len2 = 0;
    for (var j = 0; j < n; ++j) {
        if (dis(arr[n], arr[j]) > len) {
            len2 = Math.max(len2, dis(arr[n + 1], arr[j]));
        }
    }
    ans = Math.min(ans, len + len2);
}
print(ans);

var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    var dist = [];
    dist[0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    dist[1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
    distantions.push(dist);
}

var result = -1;
for (var i = 0; i < n; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n; j++) {
        if (i != j) {
            r2 = Math.max(distantions[j][1], r2);
        }
    }
    if (result == -1) {
        result = r1 + r2;
    } else {
        result = Math.min(r1 + r2, result);
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    var dist = [];
    dist[0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    dist[1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
    distantions.push(dist);
}

var result = -1;
for (var i = 0; i < n; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n; j++) {
        if (distantions[j][0] > r1) {
            r2 = Math.max(distantions[j][1], r2);
        }
    }
    if (result == -1) {
        result = r1 + r2;
    } else {
        result = Math.min(r1 + r2, result);
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    x1 = data[1],
    y1 = data[2],
    x2 = data[3],
    y2 = data[4];
var distantions = [];

for (var i = 0; i < n; i++) {
    var flower = readline().split(' ').map(Number);
    distantions[i+1] = [];
    distantions[i+1][0] = Math.pow(flower[0] - x1, 2) + Math.pow(flower[1] - y1, 2);
    distantions[i+1][1] = Math.pow(flower[0] - x2, 2) + Math.pow(flower[1] - y2, 2);
}
distantions[0] = [];
distantions[0][0] = 0;
distantions[0][1] = 0;

print(distantions);

var result = Number.MAX_VALUE;
for (var i = 0; i < n + 1; i++) {
    var r1 = distantions[i][0];
    var r2 = 0;
    for (var j = 0; j < n + 1; j++) {
        if (distantions[j][0] > r1) {
            r2 = Math.max(r2, distantions[j][1]);
        }
    }
    result = Math.min(result, r1 + r2);
}

print(result);

var arg = readline().split(' ');
var N = arg[0];
var A = [arg[1], arg[2]];
var B = [arg[3], arg[4]];

var dist = (a, b) =>
  Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2);
var d = [], P;
for (var i = 0; i < N; ++i) {
  P = readline().split(' ');
  d.push([dist(A, P), dist(B, P)]);
}
d.sort((a, b) => (a[0] > b[0]));

var ra, rb, ans = Infinity;
for (var i = -1; i < N; ++i) {
  ra = i > -1 ? d[i][0] : 0;
  rb = 0;
  for (var j = i + 1; j < N; ++j) {
    rb = Math.max(rb, d[j][1]);
  }
  ans = Math.min(ans, ra+rb);
}
print(ans);

var Point = function(coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function(p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx*dx + dy*dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [];
var sqrLengths2 = [];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    sqrLengths1.push(sqrLength(p1, points[i]));
    sqrLengths2.push(sqrLength(p2, points[i]));
}

var check = function(sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

for (var j = 0; j < n; ++j) {
    var sqrR1 = sqrLengths1[j];

    var a2 = 0;
    var b2 = 1000000;

    while (b2 - a2 > 0.001) {
        var m2 =  (a2 + b2) / 2.0;
        var sqrR2 = m2*m2;

        if (check(sqrR1, sqrR2)) {
            b2 = m2;
        } else {
            a2 = m2;
        }
    }

    MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));
}

write(MIN);

var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [];
var sqrLengths2 = [];

var MAX_SQR_LENGTH1 = -Infinity;
var MAX_SQR_LENGTH2 = -Infinity;

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    var sqrLength1 = sqrLength(p1, points[i]);
    var sqrLength2 = sqrLength(p2, points[i]);

    sqrLengths1.push(sqrLength1);
    sqrLengths2.push(sqrLength2);

    MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);
    MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);
}

var check = function (sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

var a1 = 0;
var b1 = MAX_SQR_LENGTH1*2;
debugger;
while (b1 - a1 > 0) {
    var sqrR1 = (a1 + b1) >> 1;

    var a2 = 0;
    var b2 = MAX_SQR_LENGTH2*2;

    while (b2 - a2 > 1) {
        var sqrR2 = (a2 + b2) >> 1;

        if (check(sqrR1, sqrR2)) {
            b2 = sqrR2;
        } else {
            a2 = sqrR2;
        }
    }

    if (check(sqrR1, b2)) {
        MIN = Math.min(MIN, sqrR1 + b2);
        b1 = sqrR1;
    } else {
        a1 = sqrR1;
    }
}

write(MIN);

var Point = function(coors) {
   this.x = +coors[0];
   this.y = +coors[1];
};

var length = function(p1, p2) {
   var dx = p2.x - p1.x;
   var dy = p2.y - p1.y;

   return dx*dx + dy*dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var lengths1 = [];
var lengths2 = [];

for (var i = 0; i < n; ++i) {
   points.push(new Point(readline().split(' ')));

   lengths1.push(length(p1, points[i]));
   lengths2.push(length(p2, points[i]));
}

var check = function(r1, r2) {
   //r1 *= r1;
   r2 *= r2;

   for (var i = 0; i < n; ++i) {
      if (lengths1[i] > r1 && lengths2[i] > r2) {
         return false;
      }
   }

   return true;
};

var MIN = Infinity;

for (var j = 0; j < n; ++j) {
   var r1 = lengths1[j];

   var a2 = 0;
   var b2 = 100000000;

   while (b2 - a2 > 0.001) {
      var r2 =  (a2 + b2) / 2.0;

      if (check(r1, r2)) {
         b2 = r2;
      } else {
         a2 = r2;
      }
   }

   MIN = Math.min(MIN, Math.round(r1 + a2*a2));
}

write(MIN);

var Point = function(coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function(p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx*dx + dy*dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [];
var sqrLengths2 = [];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    sqrLengths1.push(sqrLength(p1, points[i]));
    sqrLengths2.push(sqrLength(p2, points[i]));
}

var check = function(sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

for (var j = 0; j < n; ++j) {
    var sqrR1 = sqrLengths1[j];

    var a2 = 0;
    var b2 = 100000000;

    while (b2 - a2 > 0.001) {
        var m2 =  (a2 + b2) / 2.0;
        var sqrR2 = m2*m2;

        if (check(sqrR1, sqrR2)) {
            b2 = m2;
        } else {
            a2 = m2;
        }
    }

    MIN = Math.min(MIN, Math.round(sqrR1 + b2*b2));
}

write(MIN);

var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = '1 0 0 10 10'.split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [];
var sqrLengths2 = [];

var MAX_SQR_LENGTH1 = -Infinity;
var MAX_SQR_LENGTH2 = -Infinity;

for (var i = 0; i < n; ++i) {
    points.push(new Point('0 1'.split(' ')));

    var sqrLength1 = sqrLength(p1, points[i]);
    var sqrLength2 = sqrLength(p2, points[i]);

    sqrLengths1.push(sqrLength1);
    sqrLengths2.push(sqrLength2);

    MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);
    MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);
}

var check = function (sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

var a1 = 0;
var b1 = MAX_SQR_LENGTH1*2;
debugger;
while (b1 - a1 > 0) {
    var sqrR1 = (a1 + b1) >> 1;

    var a2 = 0;
    var b2 = MAX_SQR_LENGTH2*2;

    while (b2 - a2 > 1) {
        var sqrR2 = (a2 + b2) >> 1;

        if (check(sqrR1, sqrR2)) {
            b2 = sqrR2;
        } else {
            a2 = sqrR2;
        }
    }

    if (check(sqrR1, b2)) {
        MIN = Math.min(MIN, sqrR1 + b2);
        b1 = sqrR1;
    } else {
        a1 = sqrR1;
    }
}

write(MIN);

var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [];
var sqrLengths2 = [];

var MAX_SQR_LENGTH1 = -Infinity;
var MAX_SQR_LENGTH2 = -Infinity;

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    var sqrLength1 = sqrLength(p1, points[i]);
    var sqrLength2 = sqrLength(p2, points[i]);

    sqrLengths1.push(sqrLength1);
    sqrLengths2.push(sqrLength2);

    MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);
    MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);
}

var check = function (sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

var a1 = 0;
var b1 = MAX_SQR_LENGTH1;

while (b1 - a1 > 1) {
    var sqrR1 = (a1 + b1) >> 1;

    var a2 = 0;
    var b2 = MAX_SQR_LENGTH2;

    while (b2 - a2 > 1) {
        var sqrR2 = (a2 + b2) >> 1;

        if (check(sqrR1, sqrR2)) {
            b2 = sqrR2;
        } else {
            a2 = sqrR2;
        }
    }

    if (check(sqrR1, b2)) {
        MIN = Math.min(MIN, sqrR1 + b2);
        b1 = sqrR1;
    } else {
        a1 = sqrR1;
    }
}

write(MIN);

var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [];
var sqrLengths1 = [];
var sqrLengths2 = [];

var MAX_SQR_LENGTH1 = -Infinity;
var MAX_SQR_LENGTH2 = -Infinity;

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));

    var sqrLength1 = sqrLength(p1, points[i]);
    var sqrLength2 = sqrLength(p2, points[i]);

    sqrLengths1.push(sqrLength1);
    sqrLengths2.push(sqrLength2);

    MAX_SQR_LENGTH1 = Math.max(MAX_SQR_LENGTH1, sqrLength1);
    MAX_SQR_LENGTH2 = Math.max(MAX_SQR_LENGTH2, sqrLength2);
}

var check = function (sqrR1, sqrR2) {
    for (var i = 0; i < n; ++i) {
        if (sqrLengths1[i] > sqrR1 && sqrLengths2[i] > sqrR2) {
            return false;
        }
    }

    return true;
};

var MIN = Infinity;

var a1 = 0;
var b1 = MAX_SQR_LENGTH1;

while (b1 - a1 > 0) {
    var sqrR1 = (a1 + b1) >> 1;

    var a2 = 0;
    var b2 = MAX_SQR_LENGTH2;

    while (b2 - a2 > 1) {
        var sqrR2 = (a2 + b2) >> 1;

        if (check(sqrR1, sqrR2)) {
            b2 = sqrR2;
        } else {
            a2 = sqrR2;
        }
    }

    if (check(sqrR1, b2)) {
        MIN = Math.min(MIN, sqrR1 + b2);
        b1 = sqrR1;
    } else {
        a1 = sqrR1;
    }
}

write(MIN);

var Point = function (coors) {
    this.x = +coors[0];
    this.y = +coors[1];
};

var sqrLength = function (p1, p2) {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;

    return dx * dx + dy * dy;
};

var input = readline().split(' ');

var n = input[0];

var p1 = new Point(input.slice(1, 3));
var p2 = new Point(input.slice(3, 5));

var points = [p1, p2];

for (var i = 0; i < n; ++i) {
    points.push(new Point(readline().split(' ')));
}

for (i = 0; i < points.length; ++i) {
    points[i] = {
        sqrLength1: sqrLength(p1, points[i]),
        sqrLength2: sqrLength(p2, points[i])
    }
}

points.sort(function (a, b) {
    return a.sqrLength1 === b.sqrLength1 ? 0 : a.sqrLength1 < b.sqrLength1 ? -1 : 1;
});

var result = Infinity;

for (i = 0; i < points.length - 1; ++i) {
    var subResult = -Infinity;

    for (var j = i + 1; j < points.length; ++j) {
        subResult = Math.max(subResult, points[j].sqrLength2);
    }

    subResult = points[i].sqrLength1 + subResult;

    result = Math.min(result, subResult);
}

write(result);


You are given an integer $$$n$$$. Find any string $$$s$$$ of length $$$n$$$ consisting only of English lowercase letters such that each non-empty substring of $$$s$$$ occurs in $$$s$$$ an odd number of times. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print a single line containing the string $$$s$$$. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.

NoteIn the first test case, each substring of "abc" occurs exactly once.In the third test case, each substring of "bbcaabbba" occurs an odd number of times. In particular, "b" occurs $$$5$$$ times, "a" and "bb" occur $$$3$$$ times each, and each of the remaining substrings occurs exactly once.

let examples = [90];

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const solver = (n) => {
    const x = Math.floor( (n - 3) / 4);

    // console.log({x, left})
    if (x < 1) {
        return 'defghijklm'.substring(0, n);
    }
    const left = n - (x*4 + 3);
    return 'a'.repeat(x) + 'b'.repeat(x) + 'a'.repeat(x+1) + 'c' + 'b'.repeat(x+1) + 'defghijklm'.substring(0, left);
};

for(let example of examples) {
    console.log(solver(example))
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rn = () => Number(read());
  const n = rn();
  if (n < 26) {
    let s = '';
    for (let i = 0; i < n; i++) {
      s += String.fromCharCode(97 + i);
    }
    return s;
  }
  const a = Math.floor(n / 2),
        b = a - 1;
  const c = n - a - b;
  let s = 'a'.repeat(a);
  for (let i = 0; i < c; i++) {
    s += String.fromCharCode(97 + i + 1);
  }
  s += 'a'.repeat(b);
  return s;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

let examples = [90];

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const solver = (n) => {
    const x = Math.floor(n/7);
    const left = n - x*7;
    if (x < 1) {
        return 'defghijklm'.substring(0, left);
    }
    return 'a'.repeat(x) + 'b'.repeat(x) + 'a'.repeat(x+1) + 'c' + 'b'.repeat(x+1) + 'defghijklm'.substring(0, left);
};

for(let example of examples) {
    console.log(solver(example))
}

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

const examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const allLeters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

const solver = (n) => {

    let currentResult = '';
    let rstr = '';
    const letters = allLeters.slice(0)
    while(currentResult.length < n) {

        const [a,b] = [letters.shift(), letters.shift()];

        const left = n - currentResult.length;
        //console.log({n, currentResult, rstr, left})
        if (left <= 6) {
            const c = letters.shift()
            if (left === 0) currentResult += '';
            if (left === 1) currentResult += a
            if (left === 2) currentResult += a+b
            if (left === 3) currentResult += a+b+c
            if (left === 4) currentResult += a+b+a+a
            if (left === 5) currentResult += a+b+a+a+c
            if (left === 6) currentResult += a+b+a+a+b+b
            break;
        }

       if (rstr) {
           if (rstr.length * 2 + 2 <= left) {
               currentResult += a + rstr + b + rstr;
               rstr = rstr + a + rstr + b + rstr;
           } else {
               rstr = ''
           }
       } else {
            rstr = a+b+a+a+b+b;
            currentResult += rstr;
            // if (rstr * 2 + 2 <= left) {
            //     const [c,d] = [letters.shift(), letters.shift()];
            // }

       }
    }
    return currentResult;

};

// const solver = (n, letters = allLeters.slice(0), rstr = '') => {
//     console.log(n, letters.length, rstr.length)
//     const [a,b] = [letters.shift(), letters.shift()]
//     if (n <= 6) {
//         const c = letters.shift()
//         if (n === 0) return rstr;
//         if (n === 1) return rstr + a
//         if (n === 2) return rstr + a+b
//         if (n === 3) return rstr + a+b+c
//         if (n === 4) return rstr + a+b+a+a
//         if (n === 5) return rstr + a+b+a+a+c
//         if (n === 6) return rstr + a+b+a+a+b+b
//     }
//     if (!rstr) {
//         // const [a,b] = [letters.shift(), letters.shift()]
//         return solver(n, letters, a+b+a+a+b+b)
//     }

//     const newLength = n - rstr.length * 3 - 2;
//     if (newLength <= 0) {
//         return rstr + solver(n - rstr.length, letters.slice(0))
//     }
//     return rstr + solver(newLength, letters.slice(0), rstr + a + rstr + b + rstr)
// };

// console.log(examples)

for(let example of examples) {
    console.log(solver(example))
}

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

const examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const allLeters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

const solver = (n, letters = allLeters.slice(0), rstr = '') => {
    // console.log(n, letters.length, rstr.length)
    const [a,b] = [letters.shift(), letters.shift()]
    if (n <= 6) {
        const c = letters.shift()
        if (n === 1) return a
        if (n === 2) return a+b
        if (n === 3) return a+b+c
        if (n === 4) return a+b+a+a
        if (n === 5) return a+b+a+a+c
        if (n === 6) return a+b+a+a+b+b
    }
    if (!rstr) {
        // const [a,b] = [letters.shift(), letters.shift()]
        return solver(n, letters, a+b+a+a+b+b)
    }

    const newLength = n - rstr.length * 3 - 2;
    if (newLength < 0) {
        return rstr + solver(n - rstr.length, letters.slice(0))
    }
    return solver(newLength, letters.slice(0), rstr + a + rstr + b + rstr)
};

// console.log(examples)

for(let example of examples) {
    console.log(solver(example))
}

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

const examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const allLeters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

const solver = (n, letters = allLeters.slice(0), rstr = '') => {
    console.log(n, letters.length, rstr.length)
    const [a,b] = [letters.shift(), letters.shift()]
    if (n <= 6) {
        const c = letters.shift()
        if (n === 1) return a
        if (n === 2) return a+b
        if (n === 3) return a+b+c
        if (n === 4) return a+b+a+a
        if (n === 5) return a+b+a+a+c
        if (n === 6) return a+b+a+a+b+b
    }
    if (!rstr) {
        // const [a,b] = [letters.shift(), letters.shift()]
        return solver(n, letters, a+b+a+a+b+b)
    }

    const newLength = n - rstr.length * 3 - 2;
    if (newLength < 0) {
        return rstr + solver(n - rstr.length, letters.slice(0))
    }
    return solver(newLength, letters.slice(0), rstr + a + rstr + b + rstr)
};

console.log(examples)

for(let example of examples) {
    console.log(solver(example))
}


A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.You are given a regular bracket sequence $$$s$$$ and an integer number $$$k$$$. Your task is to find a regular bracket sequence of length exactly $$$k$$$ such that it is also a subsequence of $$$s$$$.It is guaranteed that such sequence always exists.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 2 \cdot 10^5$$$, both $$$n$$$ and $$$k$$$ are even) — the length of $$$s$$$ and the length of the sequence you are asked to find. The second line is a string $$$s$$$ — regular bracket sequence of length $$$n$$$.

Print a single string — a regular bracket sequence of length exactly $$$k$$$ such that it is also a subsequence of $$$s$$$. It is guaranteed that such sequence always exists.

var ip = readline().split(' ').map(Number);
var n = ip[0], open = ip[1]/2, close = ip[1]/2, res = '';
readline().split('').forEach(x=>{
   if (x === '(' && open !== 0){
       open--;
       res += x;
   }  else if (x === ')' && close !== 0){
       close--;
       res += x;
   }
});
print(res)