var tmp = readline().split(' ');
var n = +tmp[0];
var l = +tmp[1];
var r = +tmp[2];
var b = readline().split(' ').map(function(v){return +v;});
var a = readline().split(' ').map(function(v){return +v;});

var ans = 1;
l--; r--;
for(var i = 0; i<l; i++)
if(a[i] != b[i])
{
    ans = 0;
}
for(var i = r+1; i<n; i++)
{
    if(a[i] != b[i])
    {
        ans = 0;
    }
}
var A = [];
var B = [];

for(var i = l; i<=r; i++)
{
    A.push(a[i]);
    B.push(b[i]);
}

A.sort();
B.sort();

r-=l;
for(var i = 0; i<=l; i++)
if(A[i]!=B[i])
{
    ans = 0;
}

if(ans != 0)
{
    print("TRUTH");
}
else
{
    print("LIE");
}

var s1 = readline().split(' ');
var a = readline().split(' ');
var b = readline().split(' ');
var n = parseInt(s1[0]);
var l = parseInt(s1[1]);
var r = parseInt(s1[2]);

var e = true;
--l;
--r;

for (var i = 0; i < l; ++i) {
if (a[i] != b[i]) e = false;
}
for (var i = r + 1; i < n; ++i) {
if (a[i] != b[i]) e = false;
}

var a2 = a.slice(l, r + 1);
var b2 = b.slice(l, r + 1);
a2.sort();
b2.sort();

for (var i = 0; i < a2.length; ++i) {
if (a2[i] != b2[i]) e = false;
}

if (e)
print('TRUTH');
else
print('LIE');

p = readline().split(" ").map(function(x) { return parseInt(x); });
a = readline().split(" ").map(function(x) { return parseInt(x); });
b = readline().split(" ").map(function(x) { return parseInt(x); });
p[0] = p[0] - 1;
p[1] = p[1] - 1;
p[2] = p[2] - 1;
var x = true;
for (var i = 0; i < p[1]; ++i) {
    if (a[i] != b[i]) {
        x = false;
        break;
    }
}
for (var i = p[2] + 1; i < p[0]; ++i) {
    if (a[i] != b[i]) {
        x = false;
        break;
    }
}
if (x) {
    aa = a.slice(p[1], p[2] + 1).sort();
    bb = b.slice(p[1], p[2] + 1).sort();
    for (var i = 0; i < aa.length; ++i) {
        if (aa[i] != bb[i]) {
            x = false;
            break;
        }
    }
}
if (x) {
    print('TRUTH');
} else {
    print('LIE');
}

var nums = readline().split(' ');
var n = +nums[0];
var l = +nums[1];
var r = +nums[2];
var a = readline().split(' ').map(function(v) {return +v;});
var b = readline().split(' ').map(function(v) {return +v;});

function main() {
  for (var i = 0; i < l - 1; ++i) {
    if (a[i] !== b[i]) {
      print("LIE");
      return;
    }
  }

  for (var i = r; i < n; ++i) {
    if (a[i] !== b[i]) {
      print("LIE");
      return;
    }
  }

  var na = a.slice(l - 1, r);
  var nb = b.slice(l - 1, r);

  na.sort();
  nb.sort();

  for (var i = 0; i < na.length; ++i) {
    if (na[i] !== nb[i]) {
      print("LIE");
      return;
    }
  }

  print("TRUTH");
}

main();

var tmp = readline().split(' ');
var n = +tmp[0];
var l = +tmp[1] - 1;
var r = +tmp[2] - 1;
var a = readline().split(' ');
var b = readline().split(' ');
var ans = true;
var g = [], f = [];
for (var i = 0; i < n; i++) {
    if (i < l || i > r) {
        if (a[i] != b[i]) {
            ans = false;
        }
    } else {
        g.push(a[i]);
        f.push(b[i]);
    }
}
if (ans && f.sort().toString() == g.sort().toString()) {
    print("TRUTH");
} else {
    print("LIE");
}

var inp = readline().split(' ');
var a = readline().split(' ');
var b = readline().split(' ');
var ca = a.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
var cb = b.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
ca.sort();
cb.sort();
var ans = true;
for (var i = 0; i < ca.length; i++) {
    if (ca[i] != cb[i])
        ans = false;
}
for (var i = 0; i < a.length; i++) {
    if (i < parseInt(inp[1]) - 1 || i >= parseInt(inp[2])) {
        if (a[i] != b[i])
        ans = false;
    }
}
if (ans)
    print("TRUTH");
else
    print("LIE");

var n = readline().split(' ').map(function(v){return +v;});
var a = readline().split(' ').map(function(v){return +v;});
var b = readline().split(' ').map(function(v){return +v;});

var fl=true;

for (var i = 0; i<n[1]-1; i++) {
    if (a[i]!=b[i]){
      fl=false;

    }
}

for (var i = n[2]; i<n[0]; i++) {
    if (a[i]!=b[i]){
      fl=false;
    }
}

if (fl===true){
   print('TRUTH');
}else{
    print('LIE');
}

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

var n = ii[0];
var l = ii[1];
var r = ii[2];

var a = readline().split(' ');
var b = readline().split(' ');

var f = true;
for(var i = 0; i < l - 1; ++i){
   if(a[i] != b[i]) f = false;
}
for(var i = r; i < n; ++i){
   if(a[i] != b[i]) f = false;
}

var na = Array(r - l + 1);
var nb = Array(r - l + 1);

var cnt = 0;
for(var i = l - 1; i < r; ++i, cnt++){
   na[cnt] = a[i];
   nb[cnt] = b[i];
}

na.sort();
nb.sort();

for(var i = 0; i < cnt; ++i){
   if(na[i] != nb[i]){
      f = false;
   }
}

if(f == true){
   print("TRUTH");
} else {
   print("LIE");
}

var inp = readline();
    var n = inp.split(' ')[0];
    var l = inp.split(' ')[1];
    var r = inp.split(' ')[2];

    var flag = true;

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

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

    for (var i = 1; i <= n; ++i)
    {
        if (i < l || i > r)
        {
            if (a1[i - 1] != a2[i - 1])
            {
                flag = false;
                break;
            }
        }
    }
    if (flag === true)
    {
        print("TRUTH");
    }
    else
    {
        print("LIE");
    }

var meta = readline().split(" ").map(function(n) {return parseInt(n)});

var count = meta[0];
var left = meta[1] - 1;
var right = meta[2];

var a = readline().split(" ").map(function(n) {return parseInt(n)});
var b = readline().split(" ").map(function(n) {return parseInt(n)});
var lie = false;
for (var i = 0; i < left; ++i) {
	if (a[i] !== b[i]) {
		lie = true;
		break;
	};
};

if (!lie) {
	for (var i = right; i < a.length; ++i) {
		if (a[i] !== b[i]) {
			lie = true;
			break;
		};
	};
}

print(!lie ? "TRUTH": "LIE");

function main() {
    var line = readline().split(" ");
    var n = parseInt(line[0]);
    var l = parseInt(line[1]) - 1;
    var r = parseInt(line[2]) - 1;

    line = readline();
    var a = line.split(" ");
    a.forEach(function(x, i) {
        a[i] = parseInt(a[i]);
    });

    line = readline();
    var b = line.split(" ");
    b.forEach(function(x, i) {
        b[i] = parseInt(b[i]);
    });

    for (var i = 0; i < l; ++i) {
        if (a[i] != b[i]) {
            print("LIE");
            return;
        }
    }

    for (var i = r + 1; i < n; ++i) {
        if (a[i] != b[i]) {
            print("LIE");
            return;
        }
    }

    print("TRUTH");
}

main();

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && !(i >= l - 1 && i <= r - 1))
    good = false;
if (good)
  print('TRUTH');
else
  print('LIE');

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     // '4 2 4',
//     // '1 1 1 1',
//     // '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
//     // '6 3 5',
//     // '6 7 9 0 1 8',
//     // '6 7 0 9 1 8'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourceBefore = source.slice(0, l);
var destBefore = dest.slice(0, l);

var sourceAfter = source.slice(r + 1, source.length + 1);
var destAfter = dest.slice(r + 1, source.length + 1);

var sourcePart = source.slice(l, r + 1);
var destPart = dest.slice(l, r + 1);
sourcePart.sort();
destPart.sort();

var truth = true;

for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        print('LIE');
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourceBefore.length; i++) {
        if (sourceBefore[i] !== destBefore[i]) {
            print('LIE');
            truth = false;
            break;
        }
    }

    if (truth) {
        for (var i = 0; i < sourceAfter.length; i++) {
            if (sourceAfter[i] !== destAfter[i]) {
                print('LIE');
                truth = false;
                break;
            }
        }
    }
}

if (truth) {
    print('TRUTH');
}

var str = readline().split(' ');
var n = +str[0];
var l = +str[1];
var r = +str[2];
var a = readline().split(' ').map(function(v){return +v;});
var b = readline().split(' ').map(function(v){return +v;});
var c = new Array(100010);
for (i = 0; i < 100005; i++){
    c[i] = 0;
}
l--;
var ans = "TRUTH";

for (i = 0; i < n; i++){
    if (i < l || i >= r){
        if (a[i] != b[i]){
            ans = "LIE";
        }
    }
}

for (i = l; i < r; i++){
    c[a[i]]++;
}
for (i = l; i < r; i++){
    if (c[b[i]] > 0){
        c[b[i]]--;
    } else {
        ans = "LIE";
    }
}
print(ans);

var K = readline().split(' ').map( x => +x);
var n = K[0];
var l = K[1];
var r = K[2];
l--;r--;

var a = readline().split(' ').map( x => +x);

var b = readline().split(' ').map( x => +x);

var ok = true;

for(var i=0;i<l;i++) if(a[i] != b[i]) ok = false;
for(var i=r+1;i<n;i++) if(a[i] != b[i]) ok = false;

var counts = (arr) => {
    var obj = {};
    for(var i=l;i<=r;i++) {
        if(!(arr[i] in obj)) obj[arr[i]] = 1;
        else obj[arr[i]]++;
    }
    return obj;
}

var A = counts(a);
var B = counts(b);

for(var i=l;i<=r;i++) if(A[a[i]] != B[a[i]]) ok = false;

if(ok) print("TRUTH");
else print("LIE");

var line = readline().split(' ');
var aa = readline().split(' ');
var bb = readline().split(' ');
var n = +line[0];
var l = +line[1];
var r = +line[2];
l = l-1;
r = r-1;
var inA = [];
var inB = [];
var lie=false;
for (i =0;i<n;i++){
    if (((i<l) || (i>r)) && aa[i]!=bb[i]){
        lie=true;
        break;
    }
    if (aa[i]!=bb[i]){
        inA.push(aa[i]);
        inB.push(bb[i]);
    }
}
if (lie){
    print("LIE");
}else{
    inA.sort();
    inB.sort();
    for(i=0;i<inA.length;i++){
        if (inA[i]!=inB[i]){
            lie=true;
            break;
        }
    }
    if (lie){
    print("LIE");
}else{
    print("TRUTH");
}
}

var S = readline().split(" ").map(function(x) { return parseInt(x); });
n = S[0]; l = S[1]; r = S[2];
var A = readline().split(" ").map(function(x) { return parseInt(x); });
var B = readline().split(" ").map(function(x) { return parseInt(x); });
l--;
S = A;
T = B;
A = A.slice(l, r);
B = B.slice(l, r);
A.sort();
B.sort();
if(JSON.stringify(A) == JSON.stringify(B)){
	var ok = true;
	for(i = 0; i < l && ok; i++){
		if(S[i] != T[i]) ok = false;
	}
	for(i = r; i < n && ok; i++){
		if(S[i] != T[i]) ok = false;
	}
	if(ok) print("TRUTH");
	else print("LIE");
}else{
	print("LIE");
}

var prsi = function(i) { return +i; };
var reg = /\s+/;
var ln = readline().split(reg).map(prsi);
var n = ln[0], l = ln[1] - 1, r = ln[2] - 1;
var a = readline().split(reg).map(prsi),
	b = readline().split(reg).map(prsi);

var flag = 1;
for(var i = 0; i < l; ++i) {
	if(a[i] !== b[i]) {
		flag = 0;
		break;
	}
}

if(flag) {
	for(var i = r + 1; i < n; ++i) {
		if(a[i] !== b[i]) {
			flag = 0;
			break;
		}
	}
}

if(flag) print("TRUTH");
else print("LIE");

"use strict";
if (typeof readline == 'undefined') {
    let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var readline = () => lines[id++];
    var print = console.log;
}
let nums = () => readline().split(' ').map(x => +x);
let t = nums(), n = t[0], l = --t[1], r = --t[2];
let a = nums();
let b = nums();

let c = Array(n).fill(0);
let ans = true;
for (let i = l; i <= r; ++i) {
    ++c[a[i] - 1];
    --c[b[i] - 1];
}
for (let i = 0; i < l && ans; ++i) {
    if (a[i] !== b[i])
        ans = false;
}
for (let i = r + 1; i < n && ans; ++i) {
    if (a[i] != b[i])
        ans = false;
}

if (ans) ans = c.every(x => x === 0);

if (ans) print("TRUTH");
else print("LIE");

var temp = readline().split(' ').map(Number);
var n = temp[0];
var l = temp[1];
var r = temp[2];
//print(n)
//print(l)
//print(r)
var fr = readline().split(' ').map(Number);
var sc = readline().split(' ').map(Number);
l -= 1;
r -= 1;
var ch = 1;
for (var i = 0; i < l; i++) {
	if (fr[i] != sc[i])	{
		ch = 0;
		//exit(0);
	}
}
for (var i = r + 1; i < n; i++) {
	if (fr[i] != sc[i]) {
		ch = 0;
		//exit(0);
	}
}
var c1 = [];
var c2 = [];
for (var i = l; i <= r; i++) {
	c1.push(fr[i]);
	c2.push(sc[i]);
}
c1.sort();
c2.sort();
for (var i = l; i <= r; i++) {
	if (c1[i - l] != c2[i - l]) {
		ch = 0;
		//exit(0);
	}
}
if (ch == 0)
	print("LIE");
else
	print("TRUTH");

var t = readline().split(' ');
var n = parseInt(t[0]);
var l = parseInt(t[1]) - 1;
var r = parseInt(t[2]);
var a = readline().split(' ');
var b = readline().split(' ');
var good = true;

for (i = 0; i < n; i++) {
    a[i] = parseInt(a[i]);
    b[i] = parseInt(b[i]);
}

for (i = 0; i < l && good; i++)
    if (a[i] != b[i])
        good = false;
for (i = r; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

a.sort();
b.sort();

for (i = 0; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

print(good ? "TRUTH" : "LIE")

(function work() {
    var n, l, r;
    var A, B;
    var hash = {};
    var arr, i;
    arr = readline().split(' ');
    arr = arr.map((s) => parseInt(s));
    n = arr[0];
    l = arr[1] - 1;
    r = arr[2] - 1;
    arr = readline().split(' ');
    A = arr.map((s) => parseInt(s));
    for (i = l; i <= r; i ++) {
        if (!hash[A[i]])
            hash[A[i]] = 1;
        else
            hash[A[i]] ++;
    }
    arr = readline().split(' ');
    B = arr.map((s) => parseInt(s));
    for (i = 0; i < l; i ++) {
        if (A[i] !== B[i]) {
            print('LIE');
            return;
        }
    }
    for (i = l; i <= r; i ++) {
        if (!hash[B[i]] || hash[B[i]] === 0) {
            print('LIE');
            return;
        } else {
            hash[B[i]] --;
        }
    }
    for (i = r + 1; i < n; i ++) {
        if (A[i] !== B[i]) {
            print('LIE');
            return;
        }
    }
    print('TRUTH');
})();

var t = readline().split(' ');
var n = t[0];
var l = parseInt(t[1]) - 1;
var r = t[2];
var a = readline().split(' ');
var b = readline().split(' ');
var good = true;

for (i = 0; i < n; i++) {
    a[i] = parseInt(a[i]);
    b[i] = parseInt(b[i]);
}

for (i = 0; i < l && good; i++)
    if (a[i] != b[i])
        good = false;
for (i = r; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

a.sort();
b.sort();

for (i = 0; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

print(good ? "TRUTH" : "LIE")

var t = readline().split(' ');
var n = t[0];
var l = t[1] - 1;
var r = t[2];
var a = readline().split(' ');
var b = readline().split(' ');
var good = true;
for (i = 0; i < l && good; i++)
    if (a[i] != b[i])
        good = false;
for (i = r; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

a.sort();
b.sort();

for (i = 0; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

print(good ? "TRUTH" : "LIE")

var tmp = readline().split(' ');
var n = +tmp[0];
var l = +tmp[1];
var r = +tmp[2];
var a = readline().split(' ').map(function(v){return +v;});
b = a;
var ans = 1;
l--; r--;
for(var i = 0; i<l; i++)
if(a[i] != b[i])
{
    ans = 0;
}
for(var i = r+1; i<n; i++)
if(a[i] != b[i])
{
    ans = 0;
}

var A = [];
var B = [];

for(var i = l; i<=r; i++)
{
    A.push(a[i]);
    B.push(b[i]);
}

A.sort();
B.sort();

r-=l;
for(var i = 0; i<=l; i++)
if(A[i]!=B[i])
{
    ans = 0;
}

if(ans !== 0)
{
    print("TRUTH");
}
else
{
    print("LIE");
}

var inp = readline().split(' ');
var a = readline().split(' ');
var b = readline().split(' ');
var ca = a.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
var cb = b.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
ca.sort();
cb.sort();
var ans = true;
for (var i = 0; i < ca.length; i++) {
    if (ca[i] != cb[i])
        ans = false;
}
if (ans)
    print("TRUTH");
else
    print("LIE");

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && !(i >= l - 1 && i <= r - 1)) {
    print(i);
    good = false;
  }
if (good)
  print('TRUTH');
else
  print('LIE');

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && i >= l - 1 && i <= r - 1)
    good = false;
if (good)
  print('TRUTH');
else
  print('LIE');

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && i >= l - 1 && i < r)
    good = false;
if (good)
  print('TRUTH');
else
  print('LIE');

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     // '4 2 4',
//     // '1 1 1 1',
//     // '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
//     '5 3 5',
//     '6 7 9 0 1',
//     '7 6 9 0 1'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourceBefore = source.slice(0, l);
var destBefore = dest.slice(0, l);

var sourceAfter = source.slice(l + r + 1, source.length);
var destAfter = dest.slice(l + r + 1, source.length);

var sourcePart = source.slice(l, l + r + 1);
var destPart = dest.slice(l, l + r + 1);
sourcePart.sort();
destPart.sort();

var truth = true;

for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        print('LIE');
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourceBefore.length; i++) {
        if (sourceBefore[i] !== destBefore[i]) {
            print('LIE');
            truth = false;
            break;
        }
    }

    if (truth) {
        for (var i = 0; i < sourceAfter.length; i++) {
            if (sourceAfter[i] !== destAfter[i]) {
                print('LIE');
                truth = false;
                break;
            }
        }
    }
}

if (truth) {
    print('TRUTH');
}

var input = readline().split(' ');
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ');
var dest = readline().split(' ');

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
destPart.sort();

var truth = true;
for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
destPart.sort();

var truth = true;
for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     '4 2 4',
//     '1 1 1 1',
//     '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
sourcePart.sort();
destPart.sort();

source.sort();
dest.sort();

var truth = true;

for (var i = 0; i < source.length; i++) {
    if (source[i] !== dest[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourcePart.length; i++) {
        if (sourcePart[i] !== destPart[i]) {
            truth = false;
            break;
        }
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     // '4 2 4',
//     // '1 1 1 1',
//     // '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
//     '6 3 5',
//     '6 7 9 0 1 8',
//     '6 7 0 0 1 8'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourceBefore = source.slice(0, l);
var destBefore = dest.slice(0, l);

var sourceAfter = source.slice(l + r - 1, source.length);
var destAfter = dest.slice(l + r - 1, source.length);

var sourcePart = source.slice(l, l + r - 1);
var destPart = dest.slice(l, l + r - 1);
sourcePart.sort();
destPart.sort();

var truth = true;

for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        print('LIE');
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourceBefore.length; i++) {
        if (sourceBefore[i] !== destBefore[i]) {
            print('LIE');
            truth = false;
            break;
        }
    }

    if (truth) {
        for (var i = 0; i < sourceAfter.length; i++) {
            if (sourceAfter[i] !== destAfter[i]) {
                print('LIE');
                truth = false;
                break;
            }
        }
    }
}

if (truth) {
    print('TRUTH');
}

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     '4 2 4',
//     '1 1 1 1',
//     '1 1 1 1'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
sourcePart.sort();
destPart.sort();

var truth = true;
for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

var S = readline().split(" ").map(function(x) { return parseInt(x); });
n = S[0]; l = S[1]; r = S[2];
var A = readline().split(" ").map(function(x) { return parseInt(x); });
var B = readline().split(" ").map(function(x) { return parseInt(x); });
l--;
A = A.slice(l, r);
B = B.slice(l, r);
A.sort();
B.sort();
if(JSON.stringify(A) == JSON.stringify(B)){
	print("TRUTH");
}else{
	print("LIE");
}

var S = readline().split(" ").map(function(x) { return parseInt(x); });
n = S[0]; l = S[1]; r = S[2];
var A = readline().split(" ").map(function(x) { return parseInt(x); });
var B = readline().split(" ").map(function(x) { return parseInt(x); });
l--;
A = A.slice(l, r);
B = B.slice(l, r);
A.sort();
B.sort();
if(JSON.stringify(A) == JSON.stringify(B)){
	var ok = true;
	for(i = 0; i < l && ok; i++){
		if(A[i] != B[i]) ok = false;
	}
	for(i = r; i < n && ok; i++){
		if(A[i] != B[i]) ok = false;
	}
	if(ok) print("TRUTH");
	else print("LIE");
}else{
	print("LIE");
}

"use strict";
if (typeof readline == 'undefined') {
    let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var readline = () => lines[id++];
    var print = console.log;
}
let nums = () => readline().split(' ').map(x => +x);
let t = nums(), n = t[0], l = --t[1], r = --t[2];
let a = nums();
let b = nums();

let c = Array(n).fill(0);
for (let i = l; i <= r; ++i) {
    ++c[a[i] - 1];
    --c[b[i] - 1];
}

let ans = c.every(x => x === 0);

if (ans) print("TRUTH");
else print("LIE");

var n, l, r;
var A, B;
var hash = {};
var arr, i, ans = 'TRUTH';
arr = readline().split(' ');
arr = arr.map((s) => parseInt(s));
n = arr[0];
l = arr[1] - 1;
r = arr[2] - 1;
arr = readline().split(' ');
A = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[A[i]])
        hash[A[i]] = 1;
    else
        hash[A[i]] ++;
}
arr = readline().split(' ');
B = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[B[i]]) {
        ans = 'LIE';
        break;
    } else {
        hash[B[i]] --;
    }
}
print(ans);

var n, l, r;
var A, B;
var hash = {};
var arr, i, ans = 'TRUTH';
arr = readline().split(' ');
arr = arr.map((s) => parseInt(s));
n = arr[0];
l = arr[1] - 1;
r = arr[2] - 1;
arr = readline().split(' ');
A = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[A[i]])
        hash[A[i]] = 1;
    else
        hash[A[i]] ++;
}
arr = readline().split(' ');
B = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[B[i]] || hash[B[i]] === 0) {
        ans = 'LIE';
        break;
    } else {
        hash[B[i]] --;
    }
}
print(ans);


function rda(){ return readline().split(" ").map(Number); }
function rdn(){ return Number(readline()); }

var n = rdn(), a = rda();
a.sort(function(x, y){ return x-y; });

var max = 1;
var cur = 1;
for(var i = 0; i < n-1; i++){
    if(a[i] == a[i+1]){
        cur++;
        max = Math.max(max, cur);
    }else{
        cur = 1;
    }
}

var ans = n - max;
write(ans);

var n = Number(readline());
var paintings = readline().split(' ').map(Number);

/* Without the function, the default sort would convert to string and mess up */
paintings.sort(function(a, b) {
	return a - b;
});

/* I want to split paintings into increasing miniarrays */
var max_chunk = 1;
var curr_chunk = 1;

for (var i = 0; i < n; i++) {
	if (paintings[i] == paintings[i + 1]) {
		curr_chunk += 1;
		if (curr_chunk >= max_chunk) {
			max_chunk = curr_chunk;
		}
	} else {
		curr_chunk = 1;
	}
}

var happy = n - max_chunk;

print(happy);

/** B. Beautiful Paintings

There are n pictures delivered for the new exhibition. The i-th painting has
beauty ai. We know that a visitor becomes happy every time he passes from a
painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible
number of times the visitor may become happy while passing all pictures from
first to last? In other words, we are allowed to rearrange elements of a in
any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1),
such that ai + 1 > ai.

Input
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of
painting.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where
ai means the beauty of the i-th painting.

Output
Print one integer — the maximum possible number of neighbouring pairs, such
that ai + 1 > ai, after the optimal rearrangement.

5
20 30 10 50 40
> 4

4
200 100 100 200
> 2

6
10 10 10 20 30 40
> 3
(via 10 20 30 40 10 10 or 10 20 10 30 10 40)

 */

var countHappiness = function(numPaintings, paintingStats) {
    /**
    e.g.
    numPaintings = 7;
    paintingStats = [10, 10, 10, 20, 30, 40, 40];
    --
    numPaintingsWithEachStat = [
        10: 3,
        20: 1,
        30: 1,
        40: 2,
    ];
    --
    happinessAtThisCount = [
        1: true,
        2: true,
        3: true,
    ];
    --
    */
    var happiness = 0;
    if (numPaintings === 0 || numPaintings === 1) {
        print(happiness);
        return;
    }

    var numPaintingsWithEachStat = [];

    for (var i = 0; i < numPaintings; i++) {
        var paintingStat = paintingStats[i];
        if (numPaintingsWithEachStat[paintingStat] == null) {
            numPaintingsWithEachStat[paintingStat] = 0;
        }
        numPaintingsWithEachStat[paintingStat]++;
    }

    var happinessAtThisCount = [];
    for (var i = 0; i < numPaintingsWithEachStat.length; i++) {
        if (numPaintingsWithEachStat[i] != null) {
            for (var j = numPaintingsWithEachStat[i]; j > 0; j--) {
                if (happinessAtThisCount[j] != null) {
                    happiness++;
                }
                happinessAtThisCount[j] = true;
            }
        }
    }
    print(happiness);
}

var numPaintings = readline().split(' ');
var paintingStats = readline().split(' ');
countHappiness(numPaintings, paintingStats)

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var n, array, count = [], prev, answer = 0;
n = Number(readline());
array = readline().split(' ').map(Number).sort();
function check (value) {
    return value > 0;
}

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

    if (array[i] != prev) {
        count.push(1);
    } else {
        count[count.length - 1]++;
    }
    prev = array[i];
}

while (count.length > 1) {

    answer += count.length - 1;
    count = count.map(x => x - 1);
    count = count.filter(check);
}

print(answer);

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

var group = function(a) {
    var excess = [];
    var distinct = a.reduce(function(result, item) {
        if (result.indexOf(item) == -1) {
            result.push(item);
        } else {
            excess.push(item);
        }
        return result;
    }, []);

    return [distinct, excess];
};

var result = 0;
var dirty = n.splice(0);
do {
    var grouped = group(dirty);
    result += grouped[0].length - 1;
    dirty = grouped[1];
} while (dirty.length != 0)

print(result);

var n = Number(readline());
var arr = readline().split(" ", n).map(Number);

var num = [], maxNum = 0;
for (var i = 0; i < n; ++i) {
    if (!num[arr[i]]) {
        num[arr[i]] = 0;
    }
    ++num[arr[i]];
    maxNum = Math.max(maxNum, num[arr[i]]);
}

print(n - maxNum);

var n = readline(), beaut = readline().split(" "), h = [], max = 0;
for (var i = 0; i < n; i++) {
    if (!h[beaut[i]])
        h[beaut[i]] = 0;
    h[beaut[i]]++;
    max = Math.max(max, h[beaut[i]]);
}
print(n - max);

/* TEST CASE
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2

*/
function main() {
	var n = parseInt(readline());
	var splitted = readline().split(' ');
	var a = new Array(n);
	var i, j;
	for (i = 0; i < n; i++) {
		a[i] = parseInt(splitted[i]);
	}
	a.sort(function(v1, v2) {return v1 - v2});

	for (i = 0; i < n - 1; i++) {
		j = i + 1;
		while (j < n && a[j] == a[i]) {
			j++;
		}

		if (j > i + 1 && j < n) {
			var temp = a[j];
			a[j] = a[i + 1]
			a[i + 1] = temp;
			i++;
		}
	}

	var answer = 0;

	for (i = 1; i < n; i++) {
		if (a[i - 1] < a[i]) {
			answer++;
		}
	}

	print(answer);
}

main();

/* TEST CASE
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2

*/
function main() {
	var n = parseInt(readline());
	var last = n - 1;
	var a = new Array(n);
	var i, j;
	var splitted = readline().split(' ');

	for (i = 0; i < n; i++) {
		a[i] = parseInt(splitted[i]);
	}

	a.sort(function(v1, v2) {return v1 - v2;});

	for (i = 0; i < last; i++) {
		j = i + 1;
		while (j < n && a[j] == a[i]) {
			j++;
		}

		if (j > i + 1 && j < last) {
			i++;
			var temp = a[j];
			a[j] = a[i]
			a[i] = temp;
		}
	}

	var answer = 0;

	for (i = 0; i < last; i++) {
		if (a[i + 1] > a[i]) {
			answer++;
		}
	}

	print(answer);
}

main();

var count = readline();
var n = readline().split(' ');

var filtered = n.reduce(function(result, item) {
    if (!result) {result=[]}
    if (result.indexOf(item) == -1) {
        result.push(item);
    }
    return result;
}, []);

print(filtered.length - 1);

var count = readline();
var n = readline().split(' ');

var filtered = n.reduce(function(result, item) {
    if (!result) {result=[]}
    if (result.indexOf(item) == -1) {
        result.push(item);
    }
    return result;
}, []);

print(filtered.length);


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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

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

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

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

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const [n, m] = readInts(input, 0)
  const ai = readInts(input, 1)
  if(n > m) wr(0)
  else {
    let p = 1
    sort(ai, false)
    for(let i = 0; i < n - 1; i ++) {
      for(let j = i + 1; j < n; j ++) {
        p *= ((ai[i] - ai[j]) % m)
        p = p % m
      }
    }
    wr(p % m)
  }
}

'use strict'

const problem = (n, m, a) => {
    if (n > m) return 0;
    let r = 1;

    for (let i = 0; i < n - 1; i++)
        for (let j = i + 1; j < n; j++)
            r = (r * (a[j] -= a[i])) % m;

    return Math.abs(r);
}

const nm = readline().split(' ').map(i => +i);
const n = nm[0], m = nm[1];

print(problem(n, m, readline().split(' ').map(i => +i)))

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    prod %= sizes[1]
    }
    stop += 1
}
print(prod)
}

var input = readline().split(' ');
var n = input[0];
var m = input[1];
var arr = readline().split(' ');
var result = 1;
var printed = false;
var possibleRemainders = {};

for (var i=0; i<n; i++) {
    var remainder = arr[i]%m;
    if (possibleRemainders[remainder]) {
        printed = true;
        print('0');
        break;
    }
    possibleRemainders[remainder] = true;
}

if (!printed) {
    for (var i=0; i<n-1; i++) {
        for (var j=i+1; j<n; j++) {
            var diff = Math.abs(arr[i] - arr[j]) % m;
            result = (result * diff) % m;
        }
    }
    print(result);
}

function processData(input) {
  const verbose = 0
input = input.split("\n")
const [n, mod] = input[0].split(" ").map(e => Number(e))
const arr = input[1].split(" ").map(e => Number(e))
var res = 1
if(n > mod)
    console.log(0)
else{
    for(let i = 0; i < n-1; i++){
        for(let j = i+1; j < n; j++){
            res = (res*Math.abs(arr[i]-arr[j]))%mod
        }
    }
    res = res%mod
    console.log(res)
}
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});

process.stdin.on("end", function () {
processData(_input);
});

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    prod %= sizes[1]
    }
    stop += 1
}
}
print(prod)

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])%sizes[1]
    }
    stop += 1
}
}
print(prod)

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    }
    stop += 1
}
}
print(prod%sizes[1])

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    }
    stop += 1
}
}
print (stop%sizes[1])

'use strict'

const problem = (n, m, a) => {
    if (n >= m) return 0;

    a = a.map(i => +i % m)
    let p = new Array(m); p[0] = true;
    for (let i = 0; i < n; i++) {
        const x = a[i];
        if (p[x]) return 0;
        p[x] = x;
    }
    a = p.filter(Boolean).slice(1);
    let r = 1;
    for (let i = 0; i < n - 1; i++) {
        const x = a[i];
        for (let j = i + 1; j < n; j++) r = (r * (a[j] = a[j] - x)) % m;
    }
    return r;
}

const nm = readline().split(' ').map(i => +i);
const n = nm[0], m = nm[1];
print(problem(n, m, readline().split(' ')))

var input = readline().split(' ');
var n = input[0];
var m = input[1];
var arr = readline().split(' ');
var result = 1;
var printed = false;
for (var i=0; i<n-1; i++) {
    for (var j=i+1; j<n; j++) {
        var diff = Math.abs(arr[i] - arr[j]) % m;
        result = (result * diff) % m;
        if (result === 0) {
            print(result);
            printed = true;
        }
    }
}
if (!printed) {
    print(result);
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});
process.stdin.on("end", _ => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => {
      return string.trim();
    });
  main();
});
function readline() {
  return inputString[currentLine++];
}
function main(){
    const [n, mod] = readline().split(" ").map(e => Number(e))
    const arr = readline().split(" ").map(e => Number(e))
    var stack = []
    for(let i = 0; i < n-1; i++){
        for(let j = i+1; j < n; j++){
            stack.push(Math.abs(arr[i]-arr[j]))
        }
    }
    var res = 1
    for(let i = 0; i < stack.length; i++){
        res *= stack[i]
    }
    res = res%mod
    console.log(res)
}

function processData(input) {
  input = input.split("\n")
  const [n, mod] = input[0].split(" ").map(e => Number(e))
  const arr = input[1].split(" ").map(e => Number(e))
  var res = 1
  if(n > mod)
      console.log(0)
  else{
      for(let i = 0; i < n-1; i++){
          for(let j = i+1; j < n; j++){
              res = res*(Math.abs(arr[i]-arr[j])%mod)
          }
      }
      res = res%mod
      console.log(res)
  }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
  _input += input;
});

process.stdin.on("end", function () {
 processData(_input);
});


var n = Number(readline()),
array = readline().split(" ").map(x => Number(x)),
result = "NO";
for (var i = 0; i < array.length; i++) {
	if (i != array[array[i] - 1] - 1 && array[array[array[i] - 1] - 1] - 1 == i) {
		result = "YES";
		break;
	}
}
print(result);

var n = readline();
var fn = readline().split(' ');

var no = true;

for(var i = 0; i < fn.length; i++)
{
    fn[i] = int(fn[i]);
}

for(var i = 0; i < int(n); i++)
{
    var m = [];
    m.push(i+1);
    m.push(fn[i]);
    m.push(fn[fn[i]-1]);
    m.push(fn[fn[fn[i]-1]-1]);

    if(m[0] == m[3])
    {
        no = false;
        write("YES");
        break;
    }
}
if(no)
{
    write("NO");
}

function int(val)
{
    return parseInt(val);
}

	var nr = readline();
	var planes = readline().split(" ");
	var pivot;
    var pivotLoves;

    var res = "NO";

	for (var i = 0; i<nr; i++) {
       	pivot = i;
        pivotLoves = planes[i];
        if (planes[planes[pivotLoves-1]-1]-1 == pivot) {
        	res = "YES";
        }
    }
    print(res);

var planesAmount = parseInt(readline());
var planes = readline().split(' ');
var result = 'NO';
planes.some(function (plane, index) {
    if (planes[planes[plane - 1] - 1] - 1 === index) {
        result = 'YES';
        return true;
    }
});
print(result);

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={}

	for(let i =0;i<arr.length;i++){
		obj[i+1] = arr[i];

	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			//console.log(obj[obj[obj[arr[i]]]]);
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	//console.log(obj);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var tmp = nextIntArray();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = {
			no : i,
			next : tmp[i] - 1
		};
	}
	var isOK = false;
	for(var i = 0; i < N; i++){
		var now = i;
		var count = 0;
		while(count < 3){
			now = list[now].next;
			if(now == i && count == 2){
				isOK = true;
			}
			count++;
		}
	}
	myout((isOK) ? "YES" : "NO");

}

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

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

  let ans = 'NO';
  const arr = d.split(' ').map(Number);

  for (let i = 0; i < arr.length; i++) {
    let idx = 0;
    let start = arr[i];
    let end = start;

    while (idx < 3) {
      end = arr[end - 1];
      idx++;
    }

    if (start === end) {
      ans = 'YES';
      break
    }
  }

  console.log(ans);

  c++;
});

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

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

  let ans = 'NO';
  // const arr = d.split(' ').map(Number);
  const arr = [0, ...d.split(' ').map(Number)];

  for (let i = 1; i < arr.length; i++) {
    if (arr[arr[arr[i]]] === i) {
      ans = 'YES';
      break;
    }
  }

  // for (let i = 0; i < arr.length; i++) {
  //   let idx = 0;
  //   let start = arr[i];
  //   let end = start;

  //   while (idx < 3) {
  //     end = arr[end - 1];
  //     idx++;
  //   }

  //   if (start === end) {
  //     ans = 'YES';
  //     break
  //   }
  // }

  console.log(ans);

  c++;
});

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    main(lines);
});

function main (lines) {
    let n=parseInt(lines[0]);
    let line=lines[1];
    line=line.split(' ');
    for (let i=0; i<n ; i++){
        if (i+1 === parseInt(line[parseInt(line[parseInt(line[i])-1])-1])){
            console.log('YES');
            return;
        }
    }
    console.log('NO');

}

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

function main(lines) {
  const n = lines[0];
  const f = [0].concat(lines[1].split(' ').map(v => +v));
  const visited = new Set();

  for (let v = 1; v <= n; v++) {
    if (visit(f, v, visited, [])) {
      console.log("YES");
      return;
    }
  }
  console.log("NO");
}

function visit(f, v, visited, path) {
  if (visited.has(v)) {
    return false;
  }
  const next_v = f[v];
  const len = path.length;
  if (path[len - 2] === next_v) {
    return true;
  }

  visited.add(v);
  path.push(v);

  return visit(f, next_v, visited, path);
}

// main(['5', '2 4 5 1 3']);
// main(['5', '5 5 5 5 1']);

readline(); const ns = [0, ...readline().split(' ')]
print(ns.find((_,i) => (i !== 0) ? ns[ns[ns[i]]] == i : null) ? 'YES' : 'NO')

const s = readline(); const ns = [0, ...readline().split(' ')]
for (var i = 1; i <= s; i++)
if(ns[ns[ns[i]]] == i) break
print(i <= s ? 'YES' : 'NO')

var doesntExist = true;

var n = parseInt(readline());
var planes = readline().split(' ').map(function(x) {
    return parseInt(x);
});

for (var i = 0; i < n; i++) {
    firstPlanesLove = planes[i];
    secondPlanesLove = planes[firstPlanesLove - 1];

    thirdPlanesLove = planes[secondPlanesLove - 1];

    if (thirdPlanesLove === i + 1) {
        print('YES');
        doesntExist = false;
        break;
    }
}

if (doesntExist) {
    print('NO');
}

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = ('0 ' + readline()).split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 1; i <= n; i++) {
    var a = i;
    var b = ar[i];
    var c = ar[b];
    var d = ar[c];

    if (a === d) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

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

var isTri = false;
var traverse = (i) => {
    return input[i - 1]
}
for (var i = 1; i <= n; i++) {
    if (traverse(traverse(traverse(i))) == i) {
        isTri = true;
        break;
    }

}

isTri ? print('YES') : print('NO');

//demo(5, '5 5 5 5 1')

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

var isTri = false;
var traverse = (i) => {
    return input[i - 1]
}
for (var i = 1; i <= n; i++) {
    var start = i;
    if (traverse(traverse(traverse(i))) == i) {
        isTri = true;
        break;
    }

}

isTri ? print('YES') : print('NO')

//demo(5, '5 5 5 5 1')

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[b[i]-1]-1]-1] === b[i]){
		if(b[b[b[i]-1]-1] !== b[i]){
			print("YES");
			break
		}
	} else if (i === b.length - 1){
		print('NO');
	}
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={}

	for(let i =0;i<arr.length;i++){
		obj[i+1] = arr[i];

	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			console.log(obj[obj[obj[arr[i]]]]);
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	console.log(obj);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={}

	for(let i =0;i<arr.length;i++){
		obj[i+1] = arr[i];

	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			//console.log(obj[obj[obj[arr[i]]]]);
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	console.log(obj);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={};

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

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	console.log(obj);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={};

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

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	//console.log(obj);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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

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

  let ans = 'NO';
  const arr = d.split(' ').map(Number);

  for (let i = 0; i < arr.length; i++) {
    let idx = 0;
    let start = arr[i];
    let end = start;

    while (idx < 3) {
      end = arr[end];
      idx++;
    }

    if (start === end) {
      ans = 'YES';
      break
    }
  }

  console.log(ans);

  c++;
});

readline(); const ns = readline().split(' ')
print(ns.map(n => +n + 1).find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')

readline(); const ns = [0, ...readline().split(' ')];
print(ns.find((_,i) => ns[ns[ns[i + 1]]] == i + 1) ? 'YES' : 'NO')

readline(); const ns = readline().split(' ')
print(ns.map(n => n - 1).find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')

var print = this.print || require("lol-io").print;
var readline = this.readline || require("lol-io").readline;

readline(); const ns = readline().split(' ')
print(ns.find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')

readline(); const ns = [0, ...readline().split(' ')];
print(ns.find((_,i) => ns[ns[ns[i - 1]]] == i - 1) ? 'YES' : 'NO')

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = readline().split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 0; i < n; i++) {
    if (i = ar[ar[i]]) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = ('0' + readline()).split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 1; i <= n; i++) {
    if (i = ar[ar[ar[i]]]) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = ('0' + readline()).split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 1; i <= n; i++) {
    if (i = ar[ar[i]]) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[i]]] === b[i]){
		print('YES');
	} else if (i === b.length - 1){
		print('NO');
	}
}

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[i]-1]-1] === b[i]){
		print('YES');
		break
	} else if (i === b.length - 1){
		print('NO');
	}
}

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[i]-1]-1] === b[i]){
		print('YES');
	} else if (i === b.length - 1){
		print('NO');
	}
}

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[i]-1]-1] === b[i]){
		if(!(b[b[i]-1] === b[i])){
			print("YES");
			break
		}
	} else if (i === b.length - 1){
		print('NO');
	}
}

	var nr = readline();
	var planes = readline().split(" ");
	var pivot;
    var pivotLoves;
    var loved;

    var res = "NO";

	for (var i = 1; i<=nr; i++) {
       	pivot = i;
        pivotLoves = planes[i];
        if (planes[planes[pivotLoves]] == pivot) {
        	res = "YES";
        }
    }
    print(res);


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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline());
        const arr = readline().split(' ');
        divisionBy2(arr)
    }
}
const divisionBy2= (arr)=>{

    let arrNum = arr.map(el=>parseInt(el));
    let n = arrNum.length;
    let set = new Set();

    for(let i =0; i<arrNum.length; ++i){
        let num = arrNum[i];

        while(num){
            if(num <= n){
                if(!set.has(num)){
                    set.add(num);
                    break;
                }
            }
            num = Math.floor(num/2);
        }

    }

    if(set.size == n){
        console.log("YES");
    }
    else{
        console.log("NO");
    }
}

const readline = require('readline')
// Generated by CoffeeScript 1.8.0
;(function() {
  var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min, nlargest, nsmallest, updateItem, _siftdown, _siftup;

  floor = Math.floor, min = Math.min;

  /*
  Default comparison function to be used
   */

  defaultCmp = function(x, y) {
    if (x < y) {
      return -1;
    }
    if (x > y) {
      return 1;
    }
    return 0;
  };

  /*
  Insert item x in list a, and keep it sorted assuming a is sorted.

  If x is already in a, insert it to the right of the rightmost x.

  Optional args lo (default 0) and hi (default a.length) bound the slice
  of a to be searched.
   */

  insort = function(a, x, lo, hi, cmp) {
    var mid;
    if (lo == null) {
      lo = 0;
    }
    if (cmp == null) {
      cmp = defaultCmp;
    }
    if (lo < 0) {
      throw new Error('lo must be non-negative');
    }
    if (hi == null) {
      hi = a.length;
    }
    while (lo < hi) {
      mid = floor((lo + hi) / 2);
      if (cmp(x, a[mid]) < 0) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    return ([].splice.apply(a, [lo, lo - lo].concat(x)), x);
  };

  /*
  Push item onto heap, maintaining the heap invariant.
   */

  heappush = function(array, item, cmp) {
    if (cmp == null) {
      cmp = defaultCmp;
    }
    array.push(item);
    return _siftdown(array, 0, array.length - 1, cmp);
  };

  /*
  Pop the smallest item off the heap, maintaining the heap invariant.
   */

  heappop = function(array, cmp) {
    var lastelt, returnitem;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    lastelt = array.pop();
    if (array.length) {
      returnitem = array[0];
      array[0] = lastelt;
      _siftup(array, 0, cmp);
    } else {
      returnitem = lastelt;
    }
    return returnitem;
  };

  /*
  Pop and return the current smallest value, and add the new item.

  This is more efficient than heappop() followed by heappush(), and can be
  more appropriate when using a fixed size heap. Note that the value
  returned may be larger than item! That constrains reasonable use of
  this routine unless written as part of a conditional replacement:
      if item > array[0]
        item = heapreplace(array, item)
   */

  heapreplace = function(array, item, cmp) {
    var returnitem;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    returnitem = array[0];
    array[0] = item;
    _siftup(array, 0, cmp);
    return returnitem;
  };

  /*
  Fast version of a heappush followed by a heappop.
   */

  heappushpop = function(array, item, cmp) {
    var _ref;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    if (array.length && cmp(array[0], item) < 0) {
      _ref = [array[0], item], item = _ref[0], array[0] = _ref[1];
      _siftup(array, 0, cmp);
    }
    return item;
  };

  /*
  Transform list into a heap, in-place, in O(array.length) time.
   */

  heapify = function(array, cmp) {
    var i, _i, _j, _len, _ref, _ref1, _results, _results1;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    _ref1 = (function() {
      _results1 = [];
      for (var _j = 0, _ref = floor(array.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); }
      return _results1;
    }).apply(this).reverse();
    _results = [];
    for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
      i = _ref1[_i];
      _results.push(_siftup(array, i, cmp));
    }
    return _results;
  };

  /*
  Update the position of the given item in the heap.
  This function should be called every time the item is being modified.
   */

  updateItem = function(array, item, cmp) {
    var pos;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    pos = array.indexOf(item);
    if (pos === -1) {
      return;
    }
    _siftdown(array, 0, pos, cmp);
    return _siftup(array, pos, cmp);
  };

  /*
  Find the n largest elements in a dataset.
   */

  nlargest = function(array, n, cmp) {
    var elem, result, _i, _len, _ref;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    result = array.slice(0, n);
    if (!result.length) {
      return result;
    }
    heapify(result, cmp);
    _ref = array.slice(n);
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      elem = _ref[_i];
      heappushpop(result, elem, cmp);
    }
    return result.sort(cmp).reverse();
  };

  /*
  Find the n smallest elements in a dataset.
   */

  nsmallest = function(array, n, cmp) {
    var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    if (n * 10 <= array.length) {
      result = array.slice(0, n).sort(cmp);
      if (!result.length) {
        return result;
      }
      los = result[result.length - 1];
      _ref = array.slice(n);
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        elem = _ref[_i];
        if (cmp(elem, los) < 0) {
          insort(result, elem, 0, null, cmp);
          result.pop();
          los = result[result.length - 1];
        }
      }
      return result;
    }
    heapify(array, cmp);
    _results = [];
    for (i = _j = 0, _ref1 = min(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
      _results.push(heappop(array, cmp));
    }
    return _results;
  };

  _siftdown = function(array, startpos, pos, cmp) {
    var newitem, parent, parentpos;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    newitem = array[pos];
    while (pos > startpos) {
      parentpos = (pos - 1) >> 1;
      parent = array[parentpos];
      if (cmp(newitem, parent) < 0) {
        array[pos] = parent;
        pos = parentpos;
        continue;
      }
      break;
    }
    return array[pos] = newitem;
  };

  _siftup = function(array, pos, cmp) {
    var childpos, endpos, newitem, rightpos, startpos;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    endpos = array.length;
    startpos = pos;
    newitem = array[pos];
    childpos = 2 * pos + 1;
    while (childpos < endpos) {
      rightpos = childpos + 1;
      if (rightpos < endpos && !(cmp(array[childpos], array[rightpos]) < 0)) {
        childpos = rightpos;
      }
      array[pos] = array[childpos];
      pos = childpos;
      childpos = 2 * pos + 1;
    }
    array[pos] = newitem;
    return _siftdown(array, startpos, pos, cmp);
  };

  Heap = (function() {
    Heap.push = heappush;

    Heap.pop = heappop;

    Heap.replace = heapreplace;

    Heap.pushpop = heappushpop;

    Heap.heapify = heapify;

    Heap.updateItem = updateItem;

    Heap.nlargest = nlargest;

    Heap.nsmallest = nsmallest;

    function Heap(cmp) {
      this.cmp = cmp != null ? cmp : defaultCmp;
      this.nodes = [];
    }

    Heap.prototype.push = function(x) {
      return heappush(this.nodes, x, this.cmp);
    };

    Heap.prototype.pop = function() {
      return heappop(this.nodes, this.cmp);
    };

    Heap.prototype.peek = function() {
      return this.nodes[0];
    };

    Heap.prototype.contains = function(x) {
      return this.nodes.indexOf(x) !== -1;
    };

    Heap.prototype.replace = function(x) {
      return heapreplace(this.nodes, x, this.cmp);
    };

    Heap.prototype.pushpop = function(x) {
      return heappushpop(this.nodes, x, this.cmp);
    };

    Heap.prototype.heapify = function() {
      return heapify(this.nodes, this.cmp);
    };

    Heap.prototype.updateItem = function(x) {
      return updateItem(this.nodes, x, this.cmp);
    };

    Heap.prototype.clear = function() {
      return this.nodes = [];
    };

    Heap.prototype.empty = function() {
      return this.nodes.length === 0;
    };

    Heap.prototype.size = function() {
      return this.nodes.length;
    };

    Heap.prototype.clone = function() {
      var heap;
      heap = new Heap();
      heap.nodes = this.nodes.slice(0);
      return heap;
    };

    Heap.prototype.toArray = function() {
      return this.nodes.slice(0);
    };

    Heap.prototype.insert = Heap.prototype.push;

    Heap.prototype.top = Heap.prototype.peek;

    Heap.prototype.front = Heap.prototype.peek;

    Heap.prototype.has = Heap.prototype.contains;

    Heap.prototype.copy = Heap.prototype.clone;

    return Heap;

  })();

  (function(root, factory) {
    // if (typeof define === 'function' && define.amd) {
    //   return define([], factory);
    // } else if (typeof exports === 'object') {
    //   return module.exports = factory();
    // } else {
      return root.Heap = factory();
    // }
  })(this, function() {
    return Heap;
  });

}).call(this);
const Heap = this.Heap

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) {
    // arr.sort((a, b) => b - a)
    const h = new Heap((a, b) => b - a)
    h.nodes = arr
    h.heapify()
    for (let i = n; i >= 1; i--) {
        if (!h.size()) return false
        let found = false
        while (h.size()) {
            let x = h.peek()
            if (x < i) break

            x = h.pop()
            let skip = false
            while (x >= i) {
                if (x === i && !found) {
                    found = true
                    skip = true
                }
                x = Math.floor(x / 2)
            }
            if (!skip) h.push(x)
        }
        // console.log(arr)
        if (!found) return false
    }
    return true
}

const solve = (n,arr)=>{
    let obj = {};
     for(let i=0;i<n;i++){
          let t = arr[i];
          while(t>n) t>>=1;
          if(obj[t]){
               if(t===1) return "NO";
               let k = t;
               let flag = 0;
               while(k>=1){
                    if(!obj[k]){
                         obj[k] = 1;
                         flag  = 1;
                         break;
                    }
                    k>>=1
               }
               if(flag===0) return "NO";
          }
          else obj[t] = 1;
     }
     return "YES";
}

function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(n,arr));
  }
}
main();

'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, a) {
  let set = new Set(),
      st = [];
  for (let [i, num] of a.entries()) {
    if (num <= n && !set.has(num)) {
      st[i] = 1;
      set.add(num);
    }
  }
  let max = n.toString(2).length;
  next: for (let [i, num] of a.entries()) {
    if (st[i]) continue;
    const len = num.toString(2).length;
    for (let i = Math.min(max, len); i > 0; i--) {
      const num1 = num >> len - i;
      if (num1 > n) continue;
      if (!set.has(num1)) {
        set.add(num1);
        continue next;
      }
    }
    return 'NO';
  }
  return 'YES';
}

async function main(read) {
  let res = [];
  let t = Number(await read());
  while (t--) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    res.push(solve(n, a));
  }
  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);
}();

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();
		a.sort((x, y) => y - x);

		function canreduce (a, n) {
			while (n > a) {
				n = n >> 1;
			}
			return a == n;
		}

		let ok = true;
		for (let i = n; ok && i >= 1; i--) {
			ok = false;
			for (let j = 0; !ok && j < n; j++) {
				if (canreduce(i, a[j])) {
					ok = true;
					a[j] = 0;
				}
			}
		}

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

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

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

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const tsc = await readInt();
    const can_num = (n, mask) => {
        while (n > mask) {
           n = n >> 1;
        }
        return n === mask;
    }

    for(let sc = 0; sc < tsc; sc++) {
        const n = await readInt();
        const a = await readIntArray();
        let can = true;
        for(let i = n; i >= 1; i--) {
            let fnd = false;
            for(let j = 0; j < n; j++)
                if (a[j] !== 0 && can_num(a[j], i)) {
                    a[j] = 0;
                    fnd = true;
                    break;
                }
            if (!fnd) {
                can = false;
                break;
            }
        }
        if (can)
            console.log("YES");
        else
            console.log("NO");
    }
}

solve();

var t = parseInt(readline());

  function solve() {
    var n = parseInt(readline());
    var inp = readline()
      .split(" ")
      .map((data) => +data);

    var ans = [];

    for (var i = 0; i < n; i++) {
      if (inp[i] <= n && !ans.includes(inp[i])) {
        ans.push(inp[i]);
      } else {
        var val = inp[i];
        while (val > 0) {
          if (val <= n && !ans.includes(val)) {
            ans.push(val);
            break;
          }
          val = Math.floor(val / 2);
        }
      }
    }

    for (var i = 1; i <= n; i++) {
      if (!ans.includes(i)) {
        return "NO";
      }
    }

    return "YES";
  }

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

/*
===== READ INPUT DATA START =====
=================================
*/

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

let inputString = '';

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

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

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

  while (T--) {
    N = Number(lines[index++]);
    arr = lines[index++].split(' ').map(Number);

    solve(N, arr);
  }
}

function solve(N, input) {
  const arr = input.slice();
  const seen = new Set();

  for (let i = 0; i < N; ++i) {
    while (arr[i]) {
      if (arr[i] <= N && !seen.has(arr[i])) {
        seen.add(arr[i]);
        break;
      }

      arr[i] = Math.floor(arr[i] / 2);
    }
  }

  for (let i = 1; i <= N; ++i) {
    if (!seen.has(i)) {
      console.log('NO');
      return;
    }
  }

  console.log('YES');
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    let j = 2;
    for (let i = 0; i < lines[0]; ++i) {
        const arr = lines[j].split(' ').map((el) => +el);

        const n = arr.length;

        let copy = new Array(n);

        for (let i = 0; i < n; ++i) {
            copy[i] = [];
            while (arr[i] > 0) {
                if (arr[i] <= n) {
                    copy[i].push(arr[i]);
                }
                arr[i] = Math.floor(arr[i] / 2);
            }
        }

        let found = false;

        const visited = new Set();

        const dp = (pos, set, str) => {
            if (pos === n || found) {
                if (set.size === n) {
                    found = true;
                }
                return;
            }
            for (let i = 0; i < copy[pos].length; ++i) {
                if (!set.has(copy[pos][i]) && !visited.has(str)) {
                    set.add(copy[pos][i]);
                    visited.add(str);
                    dp(pos + 1, set, str + copy[pos][i]);
                    set.delete(copy[pos][i]);
                }
            }
        }

        dp(0, new Set(), '');

        console.log(found ? 'YES' : 'NO');

        j += 2;
    }
});

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    let j = 2;
    for (let i = 0; i < lines[0]; ++i) {
        const arr = lines[j].split(' ').map((el) => +el);

        const n = arr.length;

        let copy = new Array(n);

        for (let i = 0; i < n; ++i) {
            copy[i] = [];
            while (arr[i] > 0) {
                if (arr[i] <= n) {
                    copy[i].push(arr[i]);
                }
                arr[i] = Math.floor(arr[i] / 2);
            }
        }

        let set = new Set();
        for (let i = 0; i < n; ++i) {
            for (let j = 0; j < copy[i].length; ++j) {
                set.add(copy[i]);
            }
        }

        let found = false;

        if (set.size === n) {
            found = true;
        }

        //const visited = new Set();

        // const dp = (pos, set, str) => {
        //     if (pos === n || found) {
        //         if (set.size === n) {
        //             found = true;
        //         }
        //         return;
        //     }
        //     for (let i = 0; i < copy[pos].length; ++i) {
        //         if (!set.has(copy[pos][i]) || visited.has(str)) {
        //             set.add(copy[pos][i]);
        //             visited.add(str);
        //             dp(pos + 1, set, str + copy[pos][i]);
        //             set.delete(copy[pos][i]);
        //         }
        //     }
        // }

        // dp(0, new Set(), '');

        console.log(found ? 'YES' : 'NO');

        j += 2;
    }
});

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) {
    const map = {}
    const rmap = []
    arr.forEach((x, i) => {
        rmap[i] = []
        while (x) {
            map[x] = map[x] || []
            map[x].push(i)
            rmap[i].push(x)
            x = Math.floor(x / 2)
        }
    })
    rmap.sort((a, b) => a.length - b.length)
    // console.log(rmap)
    const single = {}
    const now = {}
    for (let i = 1; i <= n; i++) {
        if (!map[i]) return false
        rmap[i - 1].forEach(x => {
            now[x] = 1
        })
        if (Object.keys(now).length < i) return false
        if (map[i] && map[i].length === 1) {
            const x = map[i][0]
            if (single[x]) return false
            single[x] = 1
        }
    }
    // console.log(map)
    // console.log(single)
    return true
}

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) {
    const map = {}
    arr.forEach((x, i) => {
        while (x) {
            map[x] = map[x] || []
            map[x].push(i)
            x = Math.floor(x / 2)
        }
    })
    const single = {}
    for (let i = 1; i <= n; i++) {
        if (!map[i]) return false
        if (map[i] && map[i].length === 1) {
            const x = map[i][0]
            if (single[x]) return false
            single[x] = 1
        }
    }
    // console.log(map)
    // console.log(single)
    return true
}


let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var a = ''
        var s = lines[j].split('').sort()
        for(k = 0; k < s.length; k++){
        a += s[k]
        }
        console.log(a)

    }
});

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let s = nl.line();
		ans.push(s.split('').sort().join(''));
	}
	console.log(ans.join('\n'));
};

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

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

// LIBRARY START //

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

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

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

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

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

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

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

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

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

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

const unique = (str) => {
    const cleanStr = str.replace(/ /gi, '');
    const set = [...new Set(cleanStr)];
    return set;
}

const sortASC = (array) => {
    // var numArray = new Uint32Array(array)
    // var numArray = new Int32Array(array)
    var numArray = new Float64Array(array)
    numArray = numArray.sort()
    return numArray
}

const removeDuplicates = (array) => [...new Set(array)]

// LIBRARY END

function main() {
    let tc = +readline();
    for (let i = 0; i < tc; i++) {
        let s = readline().split('');
        s.sort();
        s = s.join('');
        console.log(s);
    }
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});

	//------------------------------<Solution>-------------------------------//
	let t = inputReader.readNumber();
	//let t = 1;

	function solve() {
	  let s = inputReader.readLine();
	  s = s.split("").sort((a, b) => {
	    if(a > b) return 1;
	    else if(a == b) return 0;
	    else return -1;
	  }).join("");
	  console.log(s);
	}

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

	//------------------------------<Solution>-------------------------------//

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readLine(){
		return _inputLines[_lineNumber++];
	}

	return {
		readNumber,
		readLine,
	}
}

"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() {
  let tc = parseInt(readline());
  for (let t=0; t<tc; t++) {
      let str = readline()
      let obj = {}
      for (let i=0; i<str.length; i++) {
      if(!obj[str[i]]) {
            obj[str[i]] = 1;
          } else {
           obj[str[i]] += 1;
  }

  }

    let str2 = '';
    for (const elem in obj){
             if(obj[elem] == 2) {

              str2 += elem + elem;

          } else {
             str2 += elem;
      }
     }
      console.log(str2)
      }
  }

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

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

let count = -1
let inputArr = []

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

function solve(str) {
    const arr = str.split('')
    const mp = new Map()
    const res = [], res2 = [], res3 = []
    arr.forEach((i) => {
        mp.set(i, mp.get(i) ? mp.get(i) + 1 : 1)
        if (mp.get(i) === 2) {
            res.push(i)
        }
    })
    for (let [key, value] of mp.entries()) {
        if (value == 1) {
            res2.push(key)
        }
    }
    res.forEach(i => {
        res3.push(i)
    })
    res2.forEach(i => {
        res3.push(i)
    })
    res.forEach(i => {
        res3.push(i)
    })
    console.log(res3.join(''))
}

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

var t = parseInt(readline());
  function solve(){
    var inp = readline().split("")

    inp.sort((a,b) =>{
       if(a>b){
           return 1
       }else if(a < b){
           return -1
       }else{
           return 0
       }
   })
    return inp.join("")
  }

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

function reduce(number,denomin){
  var gcd = function gcd(a,b){
    return b ? gcd(b, a%b) : a;
  };
    gcd = gcd(number,denomin);
  return [number/gcd, denomin/gcd];
}
let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j].split('').sort();
        var ans = '';
        for(i = 0; i < k.length; i++){
            ans += k[i];
        }
        console.log(ans);
    }
});

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
    let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++];
    let t = inp[0];
    let i = 1;
    while(t--) {
        let arr = inp[i].split('');
        arr.sort();
        arr.forEach(element => process.stdout.write(element));
        process.stdout.write("\n");
        ++i;
    }
}

'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();
        output(s.split('').sort().join(''));
    }
}

//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();
		S.sort();
		myout(myconv(S, 0));
	}
}

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

let inputString = ''
let currentLine = 0

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

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

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

  main()
})

function charsort(s) {
  return s.split('').sort().join('')
}

function main() {
  let t = readLine()
  while (t--) {
    let s = readLine()
    s = charsort(s)
    console.log(s)
  }
}

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    let s = readline()
    let mp = new Map()

    for(let c of s) {
      if(mp.has(c)) mp.set(c, 1 + mp.get(c))
      else mp.set(c, 1)
    }

    let ans = ""

    for(let [key, val] of mp.entries()) {
      if(val === 2)
        ans += key + key
      else
        ans += key
    }

    console.log(ans)
  }
}

function reduce(number,denomin){
  var gcd = function gcd(a,b){
    return b ? gcd(b, a%b) : a;
  };
    gcd = gcd(number,denomin);
  return [number/gcd, denomin/gcd];
}
let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var h = lines[j];
        var g = reduce(h, 100);
            console.log(g[1]);

    }
});

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
    let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++];
    let t = inp[0];
    console.log(inp);
    let i = 1;
    while(t--) {
        let arr = inp[i].split('');
        arr.sort();
        arr.forEach(element => process.stdout.write(element));
        process.stdout.write("\n");
        ++i;
    }
}


process.stdin.resume();
process.stdin.setEncoding('utf8');
var input = '';
process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const f = (a, b) => {
    const sa = a.toString().split('').reverse();
    const sb = b.toString().split('').reverse();
    const buf = {};
    const res = [];
    for (const i of Array(Math.max(sa.length, sb.length)).keys()) {
        res[i] = (parseInt(sa[i]) || 0) + (parseInt(sb[i]) || 0) + (buf[i] || 0);
        if (res[i] >= 10) {
            res[i] -= 10;
            buf[i + 2] = (buf[i + 2] || 0) + 1;
        }
        buf[i] = 0;
    }
    for (const i in buf) {
        if (buf[i] != 0) res[i] = buf[i];
    }
    for (const i of Array(res.length).keys()) {
        if (!(res[i] >= 0)) {
            res[i] = 0;
        }
    }
    return parseInt(res.reverse().join(''));
}

/*
for (const i of Array(100).keys()) {
    const a = Math.floor(Math.random()*1000);
    const b = Math.floor(Math.random()*1000);
    console.log(`${a}, ${b}: ${f(a, b)} - ${a + b} = ${f(a, b) - a - b}`);
}
*/

/*
//const n = 10000;
const n = 2021;

let start = 0;

while (parseInt(start.toString(2).replace(/1/g, 9)) < n) {
    start += 1;
    console.log(parseInt(start.toString(2).replace(/1/g, 9)));
}

console.log(start);
*/

ans = (n) => {
    const a = [];
    const b = [];
    Array.from(n.toString()).map((e, idx) => {
        if (idx % 2 == 0) a.push(e);
        else b.push(e);
    })
    return ((parseInt(a.join('')) || 0) + 1)*((parseInt(b.join('')) || 0) + 1) - 2;
};

const main = (input) => {
    input = input.split('\n');
    const n = +input[0];
    input.shift();
    const res = input.map(e => e.length > 0 ? ans(e) : '').join('\n');
    console.log(res);
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const s = rl();
		const n = s.length;
		const dp = Array.from(Array(n + 1), _ => Array.from(Array(2), _ => Array(2))); //like int dp [n+1][2][2];
		dp[n] = [[1, 0], [0, 0]];

		for (let i = n - 1; i >= 0; i--) {
			const d = s[i] - 0;
			dp[i][0][0] = dp[i+1][0][0] * (d + 1) + dp[i+1][0][1] * ((d - 1) + 1);
			dp[i][0][1] = dp[i+1][1][0] * (d + 1) + dp[i+1][1][1] * ((d - 1) + 1);
			dp[i][1][0] = dp[i+1][0][0] * (9 - d) + dp[i+1][0][1] * (9 - (d - 1));
			dp[i][1][1] = dp[i+1][1][0] * (9 - d) + dp[i+1][1][1] * (9 - (d - 1));
		}

		console.log(dp[0][0][0] - 2);
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		let n = rn();

		let a = [0, 0], d = 0;
		while (n) {
			let cur = n % 10;
			cur *= 10 ** (d >> 1);
			a[d % 2] += cur;

			n = Math.floor(n / 10);
			d++;
		}

		const ans = (a[0] + 1) * (a[1] + 1) - 2;

		console.log(ans);
	}
}