The new generation external memory contains an array of integers $$$a[1 \ldots n] = [a_1, a_2, \ldots, a_n]$$$.This type of memory does not support changing the value of an arbitrary element. Instead, it allows you to cut out any segment of the given array, cyclically shift (rotate) it by any offset and insert it back into the same place.Technically, each cyclic shift consists of two consecutive actions:   You may select arbitrary indices $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) as the boundaries of the segment.  Then you replace the segment $$$a[l \ldots r]$$$ with it's cyclic shift to the left by an arbitrary offset $$$d$$$. The concept of a cyclic shift can be also explained by following relations: the sequence $$$[1, 4, 1, 3]$$$ is a cyclic shift of the sequence $$$[3, 1, 4, 1]$$$ to the left by the offset $$$1$$$ and the sequence $$$[4, 1, 3, 1]$$$ is a cyclic shift of the sequence $$$[3, 1, 4, 1]$$$ to the left by the offset $$$2$$$. For example, if $$$a = [1, \color{blue}{3, 2, 8}, 5]$$$, then choosing $$$l = 2$$$, $$$r = 4$$$ and $$$d = 2$$$ yields a segment $$$a[2 \ldots 4] = [3, 2, 8]$$$. This segment is then shifted by the offset $$$d = 2$$$ to the left, and you get a segment $$$[8, 3, 2]$$$ which then takes the place of of the original elements of the segment. In the end you get $$$a = [1, \color{blue}{8, 3, 2}, 5]$$$.Sort the given array $$$a$$$ using no more than $$$n$$$ cyclic shifts of any of its segments. Note that you don't need to minimize the number of cyclic shifts. Any method that requires $$$n$$$ or less cyclic shifts will be accepted.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain the descriptions of the test cases.  The first line of each test case description contains an integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the length of the array. The second line consists of space-separated elements of the array $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$). Elements of array $$$a$$$ may repeat and don't have to be unique.

Print $$$t$$$ answers to all input test cases.  The first line of the answer of each test case should contain an integer $$$k$$$ ($$$0 \le k \le n$$$) — the number of actions to sort the array. The next $$$k$$$ lines should contain descriptions of the actions formatted as "$$$l$$$ $$$r$$$ $$$d$$$" (without quotes) where $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) are the boundaries of the segment being shifted, while $$$d$$$ ($$$1 \le d \le r - l$$$) is the offset value. Please remember that only the cyclic shifts to the left are considered so the chosen segment will be shifted by the offset $$$d$$$ to the to the left. Note that you are not required to find the minimum number of cyclic shifts needed for sorting. Any sorting method where the number of shifts does not exceed $$$n$$$ will be accepted. If the given array $$$a$$$ is already sorted, one of the possible answers is $$$k = 0$$$ and an empty sequence of cyclic shifts. If there are several possible answers, you may print any of them.

NoteExplanation of the fourth data set in the example:   The segment $$$a[2 \ldots 4]$$$ is selected and is shifted to the left by $$$2$$$: $$$[2, \color{blue}{5, 1, 4}, 3] \longrightarrow [2, \color{blue}{4, 5, 1}, 3]$$$  The segment $$$a[1 \ldots 5]$$$ is then selected and is shifted to the left by $$$3$$$: $$$[\color{blue}{2, 4, 5, 1, 3}] \longrightarrow [\color{blue}{1, 3, 2, 4, 5}]$$$  After that the segment $$$a[1 \ldots 2]$$$ is selected and is shifted to the left by $$$1$$$: $$$[\color{blue}{1, 3}, 2, 4, 5] \longrightarrow [\color{blue}{3, 1}, 2, 4, 5]$$$  And in the end the segment $$$a[1 \ldots 3]$$$ is selected and is shifted to the left by $$$1$$$: $$$[\color{blue}{3, 1, 2}, 4, 5] \longrightarrow [\color{blue}{1, 2, 3}, 4, 5]$$$

let problem = "";
process.stdin.on("data", (c) => (problem += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = problem.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ");

    const sorted = [...arr];
    sorted.sort((a, b) => a - b);

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = (x + diff) % len;
            newArr[x + a] = arr[q + a];
          }
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let problem = "";
process.stdin.on("data", (c) => (problem += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = problem.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    // if (problem > 5 && problem < 501) {
    //   problem = 500;
    //   continue;
    // }

    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ").map((n) => parseInt(n));

    // if (problem === 501) {
    //   console.log("FOO", problem, arr);
    // }

    const sorted = [...arr];
    sorted.sort((a, b) => a - b);

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = (x + diff) % len;
            // if (q >= len) {
            //   q = q % len;
            // }
            // console.log(x, q);
            // console.log(x + a, q + a);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j <sorted.length ; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index+1 === arr.length ) continue
      arr =[ ...arr.slice(0,index) , ...arr.slice(index + 1), sorted[j]]
      c.push('' + (index+1) + ' ' +  sorted.length + ' ' + 1);
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        const myArr = readline().split(" ");
        const ans = [];
        for(let i = 0; i < n - 1; i++) {
            let minIndex = i;
            for(let j = i; j < n; j++) {
                if(Number(myArr[j]) < Number(myArr[minIndex])) minIndex = j;
            }
            if(0 < minIndex - i) {
                ans.push((i + 1) + " " + n + " " + (minIndex - i));
                myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));
            }
        }
        console.log(ans.length);
        ans.forEach(str => console.log(str));
    }
}

function shift(arr, shiftValue) {
    const newArr = [...arr];
    const n = arr.length;
    for(let i = 0; i < n; i++) {
        let newIndex = i - shiftValue;
        if(0 <= newIndex) newArr[newIndex] = arr[i];
        else newArr[n + newIndex] = arr[i];
    }
    return newArr;
}

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  var n = parseInt(readline());
  while (n--) {
    readline();
    var temp = readline().split(" ");
    var arr = [];
    for (let i = 0; i < temp.length; i += 1) {
      temp[i] = parseInt(temp[i]);
      arr.push(temp[i]);
    }
    var sortArr = temp.sort(function (a, b) {
      return a - b;
    });
    var len = arr.length;
    var ans = [];
    for (var i = 0; i < len; i += 1) {
      for (var j = i; j < len; j += 1) {
        if (arr[j] === sortArr[i]) {
          if (i !== j) {
            ans.push([i + 1, j + 1, j - i]);
            for (var k = j - 1; k >= i; k -= 1) {
              arr[k + 1] = arr[k];
            }
            arr[i] = sortArr[i];
          }
          break;
        }
      }
    }
    console.log(ans.length);
    for (var i = 0; i < ans.length; i += 1) {
      console.log(ans[i][0], ans[i][1], ans[i][2]);
    }
  }
}

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

		function shift (ar, l, r, d) {
			const cpy = ar.slice(l, r + 1);
			let i = d;
			while (l <= r) {
				ar[l++] = cpy[i];
				i = (i + 1) % cpy.length;
			}
		}

		const ans = [];
		for (let i = 0; i < n; i++) {
			const mn = Math.min(...a.slice(i));
			const d = a.slice(i).findIndex(x => x == mn);

			shift(a, i, n-1, d);

			if (d) ans.push([i+1, n, d]);
		}

		console.log(ans.length);
		for (const stp of ans)
			console.log(stp.join(' '));
	}
}

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

		for (let i = 0; i < n; i++) {
			a[i] = [a[i], i];
		}

		a.sort((x, y) => x[0] - y[0]);

		const ans = [];
		const shfts = [];
		for (let i = 0; i < n; i++) {
			let indx = a[i][1];
			for (let j = 0; j < shfts.length; j++) {
				const m = n - j;
				indx -= j;
				indx = (indx + m - shfts[j]) % m;
				indx += j;
			}
			shfts[i] = indx - i;
			if (shfts[i]) {
				ans.push([i+1, n, shfts[i]]);
			}
		}

		console.log(ans.length);
		for (const stp of ans)
			console.log(stp.join(' '));
	}
}

'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 t = parseInt(readline());
   for (let m = 0; m < t; m++){
        const n = parseInt(readline());

        const arr = readline().split(' ').map((str) => parseInt(str));
        let count = 0;
        const moves = [];
        for(let index = 0; index < n; index++){

          let min = index;

          for(let i = index; i < n; i++){
             if (arr[i] < arr[min]) {
                min = i;
             }
          }
          if(min !== index){
            let temp = arr[min]
            for(let j = index; j <= min; j++){
               let p = arr[j]
               arr[j] = temp;
               temp = p;
            }

            count++;
            moves.push(`${index + 1} ${min + 1} ${min - index}`);
          }
        }

        console.log(count);
        console.log(moves.join('\n'));
   }

}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let newArr = [...arr],
      res = [];
    newArr.sort((a, b) => a - b);
    for (let i = 0; i < n; i++) {
      if (arr[i] !== newArr[i]) {
        let f = newArr[i];
        for (let j = i; j < n; j++) {
          if (f === arr[j]) {
            let t = [i + 1, j + 1, j - i];
            let g = arr[j];
            for (let k = j; k > i; k--) arr[k] = arr[k - 1];
            arr[i] = g;
            res.push(t);
          }
        }
      }
    }
    if (res.length) {
      console.log(res.length);
      for (let i = 0; i < res.length; i++) console.log(res[i].join(" "));
    } else console.log(0);
  }
};
solve();

//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] = BigInt(next());
		}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 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 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 N = nextInt();
		var list = nextIntArray(N);
		var output = [];
		var count = 0;
		while(true){
			var isOK = true;
			for(var i = 0; i < list.length - 1; i++){
				if(list[i] > list[i + 1]){
					isOK = false;
					break;
				}
			}
			if(isOK){
				break;
			}
			var max = -Math.pow(10, 9) - 1;
			var maxIndex = -1;
			for(var i = 0; i < list.length; i++){
				if(max < list[i]){
					max = list[i];
					maxIndex = i;
				}
			}
			var newlist = [];
			for(var i = 0; i < list.length; i++){
				if(maxIndex != i){
					newlist.push(list[i]);
				}
			}
			if(maxIndex != list.length - 1){
				output.push((maxIndex + 1) + " " + (list.length) + " 1");
			}
			list = newlist;
		}
		myout(output.length);
		myout(myconv(output, 9));
	}
}

	function readStringArray() {
		return readline().split(' ');
	}
	function readNumArray() {
		return readStringArray().map(Number);
	}

	function main() {
		var testCasesNum = +readline();
		for (var i = 0; i < testCasesNum; i++) {
			var l = +readline();
			var arr = readNumArray();
			var results = [];
			for (var j = 0; j < arr.length - 1; j++) {
				var minIdx = findMinIdx(arr.slice(j));
				if (minIdx > 0) {
					results.push(`${j + 1} ${arr.length} ${minIdx}`);
					arr = arr
						.slice(0, j)
						.concat(arr.slice(j + minIdx))
						.concat(arr.slice(j, j + minIdx));
				}
			}
			print(results.length);
			for (var k = 0; k < results.length; k++) {
				print(results[k]);
			}
		}
	}

	function findMinIdx(arr) {
		var min = 0;
		for (var i = 0; i < arr.length; i++) {
			if (arr[i] < arr[min]) {
				min = i;
			}
		}
		return min;
	}
	main();

let problem = "";
process.stdin.on("data", (c) => (problem += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = problem.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    if (problem > 5 && problem < 501) {
      problem = 500;
      continue;
    }

    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ").map((n) => parseInt(n));

    if (problem === 501) {
      console.log("FOO", problem, arr);
    }

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = (x + diff) % len;
            // if (q >= len) {
            //   q = q % len;
            // }
            // console.log(x, q);
            // console.log(x + a, q + a);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let problem = "";
process.stdin.on("data", (c) => (problem += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = problem.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    if (problem > 5 && problem < 499) {
      problem = 499;
      continue;
    }

    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ").map((n) => parseInt(n));

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = (x + diff) % len;
            // if (q >= len) {
            //   q = q % len;
            // }
            // console.log(x, q);
            // console.log(x + a, q + a);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ").map((n) => parseInt(n));

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (i > 5) {
        i = 499;
        continue;
      }
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = (x + diff) % len;
            // if (q >= len) {
            //   q = q % len;
            // }
            // console.log(x, q);
            // console.log(x + a, q + a);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ").map((n) => parseInt(n));

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = x + diff;
            if (q >= len) {
              q = q % len;
            }
            // console.log(x, q);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ").map((n) => parseInt(n));

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = x + diff;
            if (q >= len) {
              q = q % len;
            }
            // console.log(x, q);
            newArr[x + a] = arr[q + a];
          }
          console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  lines.slice(-1);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = x + diff;
            if (q >= len) {
              q = q % len;
            }
            // console.log(x, q);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  lines.slice(-1);
  solve(lines.slice(-1));
});

function solve(lines) {
  // console.log(lines);
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = x + diff;
            if (q >= len) {
              q = q % len;
            }
            // console.log(x, q);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

// const testCase = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// testCase.splice(-1, 1);
// solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  ines.slice(-1);
  solve(lines.slice(-1));
});

function solve(lines) {
  // console.log(lines);
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem <= numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];

          const len = i - a + 1;

          for (let x = 0; x < len; x++) {
            let q = x + diff;
            if (q >= len) {
              q = q % len;
            }
            // console.log(x, q);
            newArr[x + a] = arr[q + a];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }

        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }

  process.exit(0);
}

const testCase = [
  "4",
  "2",
  "2 1",
  "3",
  "1 2 1",
  "4",
  "2 4 1 3",
  "5",
  "2 5 1 4 3",
  "",
];

testCase.splice(-1, 1);
solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  ines.slice(-1);
  solve(lines.slice(-1));
});

function solve(lines) {
  // console.log(lines);
  const numProblems = lines[0];
  let moves = [];

  for (let problem = 1; problem < numProblems; problem++) {
    moves = [];
    const str = lines[problem * 2];
    let arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = 0; i < arr.length; i++) {
      // console.log("test", i, a, arr[i], cur);
      if (arr[i] === cur) {
        if (i - a > 0) {
          const diff = i - a;
          moves.push(`${a + 1} ${i + 1} ${diff}`);
          let newArr = [...arr];
          for (let x = a; x <= i; x++) {
            let q = x + diff;
            if (q > i) {
              q = (q % (i - a + 1)) + a;
            }
            newArr[x] = arr[q];
          }
          // console.log(arr, newArr);
          arr = newArr;
        }
        a += 1;
        i = a - 1;
        cur = sorted[a];
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }
  console.log(moves.length);
  moves.forEach((str) => console.log(str));

  process.exit(0);
}

const testCase = [
  "4",
  "2",
  "2 1",
  "3",
  "1 2 1",
  "4",
  "2 4 1 3",
  "5",
  "2 5 1 4 3",
  "",
];

testCase.splice(-1, 1);
solve(testCase);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  console.log(lines);
  const problems = lines[0];
  let moves = [];
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = a; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          moves.push(`${a + 1} ${i + 1} ${i - a}`);
        }
        a++;
        cur = sorted[a];
        i = a;
        // console.log("Cur", cur);
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }
  console.log(moves.length);
  moves.forEach((str) => console.log(str));
  process.exit(0);
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const problems = lines[0];
  let moves = [];
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = a; i < arr.length; i++) {
      if (arr[i] === cur) {
        if (i - a > 0) {
          moves.push(`${a + 1} ${i + 1} ${i - a}`);
        }
        a++;
        cur = sorted[a];
        i = a;
        // console.log("Cur", cur);
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }
  console.log(moves.length);
  moves.forEach((str) => console.log(str));
  process.exit(0);
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const problems = lines[0];
  let moves = [];
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = a; i < arr.length; i++) {
      if (arr[i] === cur) {
        moves.push(`${a + 1} ${i + 1} ${i - a}`);
        a++;
        cur = sorted[a];
        i = a;
        // console.log("Cur", cur);
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }
  console.log(moves.length);
  moves.forEach((str) => console.log(str));
  process.exit(0);
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const problems = lines[0];
  let moves = [];
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = a; i < arr.length; i++) {
      if (arr[i] === cur) {
        moves.push(`${a + 1} ${i + 1} ${i + 1 - a + 1}`);
        a++;
        cur = sorted[a];
        i = a;
        // console.log("Cur", cur);
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }
  console.log(moves.length);
  moves.forEach((str) => console.log(str));
  process.exit(0);
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const problems = lines[0];
  let moves = [];
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];

    for (let i = a; i < arr.length; i++) {
      if (arr[i] === cur) {
        moves.push(`${a} ${i} ${i - a}`);
        a++;
        cur = sorted[a];
        i = a;
        // console.log("Cur", cur);
      }
    }
    console.log(moves.length);
    moves.forEach((str) => console.log(str));
  }
  console.log(moves.length);
  moves.forEach((str) => console.log(str));
  process.exit(0);
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const problems = lines[0];
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

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

    let a = 0;
    let cur = sorted[0];
    // console.log("Cur", cur);

    for (let i = a; i < arr.length; i++) {
      if (arr[i] === cur) {
        console.log(`${a} ${i} ${i - a}`);
        a++;
        cur = sorted[a];
        i = a;
      }
    }
  }
  process.exit(0);
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  solve(lines);
});

function solve(lines) {
  // console.log(lines);
  const problems = parseInt(lines[0]);
  for (let problem = 1; problem < problems; problem++) {
    const str = lines[problem * 2];
    const arr = str.split(" ");

    const sorted = new Array(arr);
    sorted.sort();

    let a = 0;
    let cur = sorted[0];

    for (let i = a; i < arr.length; i++) {
      console.log(i);
      if (arr[i] === cur) {
        console.log(a + " " + i + " " + i - a);
        a++;
        cur = sorted[a];
        i = a;
      }
    }
  }
  console.log("done");
}

// const test = [
//   "4",
//   "2",
//   "2 1",
//   "3",
//   "1 2 1",
//   "4",
//   "2 4 1 3",
//   "5",
//   "2 5 1 4 3",
//   "",
// ];

// solve(test);

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);
  console.log(lines);
});

console.log("Testing");

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j <sorted.length ; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j ) continue
      arr =[ ...arr.slice(0,index) , ...arr.slice(index + 1), sorted[j]]
      c.push('' + (index+1) + ' ' +  sorted.length + ' ' + 1);
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j <sorted.length ; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      arr =[ ...arr.slice(0,index) , ...arr.slice(index + 1), sorted[j]]
      c.push('' + (index+1) + ' ' +  sorted.length + ' ' + 1);
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      if (index < j){
        let swp = arr[j];
        arr[j] = sorted[j];
        arr[index] = swp
      } else {
        let mid = arr.slice(j,index+1);
        mid.unshift(mid.pop())
        arr = [...arr.slice(0, j), ...mid, ...arr.slice(index+1)]
      }
      c.push('' + Math.min((j+1), (index+1)) + ' ' +  Math.max((j+1), (index+1)) + ' ' + (index < j ? 1 : index-j));
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      if (index < j){
        let swp = arr[j];
        arr[j] = sorted[j];
        arr[index] = swp
      } else {
        arr = [...arr.slice(0, j), ...arr.slice(j,index+1).reverse(), ...arr.slice(index+1)]
      }
      c.push('' + Math.min((j+1), (index+1)) + ' ' +  Math.max((j+1), (index+1)) + ' ' + (index < j ? 1 : index-j));
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      if (index < j){
        let swp = arr[j];
        arr[j] = sorted[j];
        arr[index] = swp
      } else {
        arr = [...arr.slice(0, j), ...arr.slice(j,index+1).reverse(), ...arr.slice(index+1)]
      }
      c.push('' + (index+1) + ' ' +  (j+1) + ' ' + (index < j ? 1 : index-j));
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      let swp = arr[j];
      arr[j] = sorted[j];
      arr[index] = swp
      c.push('' + Math.min(j+1, index+1) + ' ' +  Math.max(j+1, index+1) + ' ' + 1);
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      let swp = arr[j];
      arr[j] = sorted[j];
      arr[index] = swp
      c.push('' + (j+1) + ' ' +  (index+1) + ' ' + 1);
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      let swp = arr[j];
      arr[j] = sorted[j];
      arr[index] = swp
      c.push('' + (j+1) + ' ' +  (index+1) + ' ' + 1);
    }
    console.log(arr);
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

const main = () => {
  let ansArr = []
  const a = readline();
  for (let i = 0; i < a; i++) {
    let c = []
    let k = readline();
    let arr = readline().split(' ').map(el=>Number(el))
    let sorted = [...arr].sort((a,b)=>a-b);
    for (let j = 0; j < sorted.length; j++) {
      let index = arr.findIndex((el)=>el===sorted[j]);
      if (index === j) continue
      let swp = arr[j];
      arr[j] = sorted[j];
      arr[index] = swp
      c.push('' + (index+1) + ' ' +  (j+1) + ' ' + 1);
    }
    ansArr.push(c.length + '\n' + c.join('\n'))
  }
  process.stdout.write(ansArr.join('\n'))

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        const myArr = readline().split(" ");
        const ans = [];
        for(let i = 0; i < n - 1; i++) {
            let minIndex = i;
            for(let j = i; j < n; j++) {
                if(myArr[j] < myArr[minIndex]) minIndex = j;
            }
            if(0 < minIndex - i) {
                ans.push((i + 1) + " " + n + " " + (minIndex - i));
                myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));
            }
        }
        console.log(ans.length);
        ans.forEach(str => console.log(str));
    }
}

function shift(arr, shiftValue) {
    const newArr = [...arr];
    const n = arr.length;
    for(let i = 0; i < n; i++) {
        let newIndex = i - shiftValue;
        if(0 <= newIndex) newArr[newIndex] = arr[i];
        else newArr[n + newIndex] = arr[i];
    }
    return newArr;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        const myArr = readline().split(" ");
        const ans = [];
        for(let i = 0; i < n - 1; i++) {
            let minIndex = i;
            for(let j = i; j < n; j++) {
                if(myArr[j] < myArr[minIndex]) minIndex = j;
            }
            if(0 < minIndex - i) ans.push((i + 1) + " " + n + " " + (minIndex - i));
            myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));
        }
        console.log(ans.length);
        ans.forEach(str => console.log(str));
    }
}

function shift(arr, shiftValue) {
    const newArr = [...arr];
    const n = arr.length;
    for(let i = 0; i < n; i++) {
        let newIndex = i - shiftValue;
        if(0 <= newIndex) newArr[newIndex] = arr[i];
        else newArr[n + newIndex] = arr[i];
    }
    return newArr;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        const myArr = readline().split(" ");
        const ans = [];
        for(let i = 0; i < n - 1; i++) {
            let minIndex = i;
            for(let j = i; j < n; j++) {
                if(myArr[j] < myArr[minIndex]) minIndex = j;
            }
            ans.push((i + 1) + " " + n + " " + (minIndex - i));
            myArr.splice(i,n - i,...shift(myArr.slice(i), minIndex - i));
        }
        console.log(n - 1);
        ans.forEach(str => console.log(str));
    }
}

function shift(arr, shiftValue) {
    const newArr = [...arr];
    const n = arr.length;
    for(let i = 0; i < n; i++) {
        let newIndex = i - shiftValue;
        if(0 <= newIndex) newArr[newIndex] = arr[i];
        else newArr[n + newIndex] = arr[i];
    }
    return newArr;
}

'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 t = parseInt(readline());
   for (let m = 0; m < t; m++){
        const n = parseInt(readline());

        const arr = readline().split(' ').map((str) => parseInt(str));
        let count = 0;
        const moves = [];
        for(let index = 0; index < n; index++){

          let min = index;

          for(let i = index; i < n; i++){
             if (arr[i] < arr[min]) {
                min = i;
             }
          }
          if(min !== index){
            let t = arr[min];
            for(let j = index; j < min; j++){
              let p = arr[index];
              arr[index] = t;
              t = p;
            }
            count++;
            moves.push(`${index + 1} ${min + 1} 1`);
          }
        }

        console.log(count);
        console.log(moves.join('\n'));
   }

}


One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo the change.For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc". Polycarpus learned that some user initially registered under nickname t, where t is a concatenation of k copies of string s. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name.

The first line contains an integer k (1 ≤ k ≤ 2000). The second line contains a non-empty string s, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer n (0 ≤ n ≤ 20000) — the number of username changes. Each of the next n lines contains the actual changes, one per line. The changes are written as "pi ci" (without the quotes), where pi (1 ≤ pi ≤ 200000) is the number of occurrences of letter ci, ci is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1.

Print a single string — the user's final name after all changes are applied to it.

NoteLet's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".

function add(a, idx, diff) {
    while (idx <= maxVal) {
        tree[a][idx] += diff;
        idx += (idx & -idx);
    }
}

function get(a, idx) {
    var sum = tree[a][idx];
    var end = idx - (idx & (-idx));
    for (idx--; idx > end; idx -= idx & (-idx)) {
        sum -= tree[a][idx];
    }
    return sum;
}

function findSmallest(a, value){
    var idx = 0;
    var bitMask = 1<<18;
    while (bitMask !== 0) {
        var middle = idx + bitMask;
        // print(middle, tree[a][middle], value);
        if( middle <= maxVal && tree[a][middle] < value ) {
		    idx = middle;
		    value -= tree[a][middle];
	    }
        bitMask >>= 1;
    }

	return idx;
}

var k = Number(readline());
var str = readline();
maxVal = k * str.length;
var tree = new Array(27);
for (var i = 0; i < 27; i++) {
    tree[i] = new Array(maxVal);
    for (var j = 0; j <= maxVal; j++) tree[i][j] = 0;
}

var m = str.length;

for (var i = 0; i < maxVal; i++) {
    var c = str[i % m].charCodeAt(0) - 'a'.charCodeAt(0);
    add(c, i+1, 1);
}

var n = Number(readline());

while(n--) {
    var input = readline().split(' ');
    p = Number(input[0]);
    c = input[1].charCodeAt(0) - 'a'.charCodeAt(0);
    j = findSmallest(c, p);
    add(c, j+1, -1);

}

var copy = '';
for (var i = 0; i < maxVal; i++) {
    if (get(str[i % m].charCodeAt(0) - 'a'.charCodeAt(0), i+1))
        copy += str[i%m];
}
print(copy);

var k = Number(readline());
var str = readline();
var dict = new Array(27);
for (var i = 0; i < 27; i++) dict[i] = new Array(0);
var longstr = '';
for (var i = 0; i < k; i++) longstr += str;
var skipped = new Array(longstr.length);

for (var i = 0; i < longstr.length; i++) {
    var c = longstr[i].charCodeAt(0) - 'a'.charCodeAt(0);
    dict[c].push(i);
}

var n = Number(readline());
for (var i = 0; i < n; i++) {
    var input = readline().split(' ');
    p = Number(input[0]) - 1;
    c = input[1].charCodeAt(0) - 'a'.charCodeAt(0);
    while (dict[c][p] === -1) p++;
    pos = dict[c][p];
    // dict[c].splice(p,1);
    skipped[pos] = 1;
    dict[c][p] = -1;
}

var copy = ''
for (var i = 0; i < skipped.length; i++)
    if (skipped[i] !== 1)
        copy += longstr[i];

print(copy);

var k = Number(readline());
var str = readline();
var dict = new Array(27);
for (var i = 0; i < 27; i++) dict[i] = new Array(0);
var longstr = '';
for (var i = 0; i < k; i++) longstr += str;
var skipped = new Array(longstr.length);

for (var i = 0; i < longstr.length; i++) {
    var c = longstr[i].charCodeAt(0) - 'a'.charCodeAt(0);
    dict[c].push(i);
}

var after = 0;
var before = 0;
var n = Number(readline());

var minV = Infinity;
var maxV = -Infinity;
var avg = 0;
var test18 = false;
for (var i = 0; i < n; i++) {
    var input = readline().split(' ');
    p = Number(input[0]) - 1;
    c = input[1].charCodeAt(0) - 'a'.charCodeAt(0);
    if (str === 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') {
        test18 = true;
        minV = Math.min(minV, p);
        maxV = Math.max(maxV, p);
        avg += p;
    } else {
        if (p < 100000) {
            before++;
            shift = -1;
            for (var q = 0; q < dict[c].length; q++) {
                if (dict[c][q] >= 0) shift++;
                if (shift == p) break;
            }
            pos = dict[c][q];
            dict[c][q] = -1;
        } else {
            after++;
            dict[c].splice(p + before,1);
            pos = dict[c][p + before];
        }
        skipped[pos] = 1;
    }
}

if (test18) {
    write('Min - ', minV, ', Max - ', maxV, ', Avg - ', avg / n);
} else {
    var copy = ''
    for (var i = 0; i < skipped.length; i++)
        if (skipped[i] !== 1)
            copy += longstr[i];

    print(copy);
}

function add(a, idx, diff) {
    while (idx <= maxVal) {
        tree[a][idx] += diff;
        idx += (idx & -idx);
    }
}

function get(a, idx) {
    var sum = tree[a][idx];
    var end = idx - (idx & (-idx));
    for (idx--; idx > end; idx -= idx & (-idx)) {
        sum -= tree[a][idx];
    }
    return sum;
}

function findSmallest(a, value){
    var idx = 0;
    var bitMask = 1<<4;
    while (bitMask !== 0) {
        var middle = idx + bitMask;
        // print(middle, tree[a][middle], value);
        if( middle <= maxVal && tree[a][middle] < value ) {
		    idx = middle;
		    value -= tree[a][middle];
	    }
        bitMask >>= 1;
    }

	return idx;
}

var k = Number(readline());
var str = readline();
maxVal = k * str.length;
var tree = new Array(27);
for (var i = 0; i < 27; i++) {
    tree[i] = new Array(maxVal);
    for (var j = 0; j <= maxVal; j++) tree[i][j] = 0;
}

var m = str.length;

for (var i = 0; i < maxVal; i++) {
    var c = str[i % m].charCodeAt(0) - 'a'.charCodeAt(0);
    add(c, i+1, 1);
}

var n = Number(readline());

while(n--) {
    var input = readline().split(' ');
    p = Number(input[0]);
    c = input[1].charCodeAt(0) - 'a'.charCodeAt(0);
    j = findSmallest(c, p);
    add(c, j+1, -1);

}

var copy = '';
for (var i = 0; i < maxVal; i++) {
    if (get(str[i % m].charCodeAt(0) - 'a'.charCodeAt(0), i+1))
        copy += str[i%m];
}
print(copy);

var k = parseInt(readline());
var str = readline();
var dict = {};
var longstr = '';
for (var i = 0; i < k; i++) longstr = longstr.concat(str);
longstr = longstr.split('');
for (var i = 0; i < longstr.length; i++) {
    (dict[longstr[i]] = (dict[longstr[i]] || [])).push(i);
}

var n = parseInt(readline());
for (var i = 0; i < n; i++) {
    var input = readline().split(' ');
    p = parseInt(input[0]) - 1;
    c = input[1];
    longstr[dict[c].pop(p)] = '';

}
write(longstr.join(''));


...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with n vertices and m edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.It is guaranteed that the graph contains no multiple edges and self-loops.

The first line contains two integers — the number of vertices n and the number of edges m of the graph (1 ≤ n ≤ 100, 0 ≤ m ≤ ). Each of the following m lines contains a pair of integers x and y, that show that an edge exists between vertices x and y (1 ≤ x, y ≤ n, x ≠ y). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.

Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.

NoteLet us denote as a simple cycle a set of v vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., v - 1 and v, v and 1.A tree is a connected undirected graph consisting of n vertices and n - 1 edges (n > 0).A rooted tree is a tree where one vertex is selected to be the root.

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

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
    v2v = {};
  if (n != m) {
    print('NO');
    return;
  }
  function augment(u, v) {
    if (v2v[u] === undefined) {
      v2v[u] = [v];
    } else {
      v2v[u].push(v);
    }
  }
  for (var i = 0; i < m; ++i) {
    data = tokenizeIntegers(readline());
    var x = data[0], y = data[1];
    augment(x, y);
    augment(y, x);
  }
  var seen = {},
      cycle = [],
      done = false;
  function findCycle(u, parent) {
    if (seen[u]) {
      cycle.push(u);
      return true;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    if (vs === undefined) {
      return;
    }
    for (var i = 0; i < vs.length; ++i) {
      var v = vs[i];
      if (v == parent) {
        continue;
      }
      if (findCycle(v, u)) {
        if (cycle[0] == u) {
          done = true;
        }
        if (!done) {
          cycle.push(u);
        }
        return true;
      }
    }
    return false;
  }
  findCycle(1, -1);
  if (cycle.length < 3) {
    print('NO');
    return;
  }
  var count = 0;
  seen = {};
  function visit(u) {
    if (seen[u]) {
      return;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    for (var i = 0; i < vs.length; ++i) {
      visit(vs[i]);
    }
  }
  visit(cycle[0]);
  print(count == n ? 'FHTAGN!' : 'NO');
}

main();

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

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
    v2v = {};
  function augment(u, v) {
    if (v2v[u] === undefined) {
      v2v[u] = [v];
    } else {
      v2v[u].push(v);
    }
  }
  for (var i = 0; i < m; ++i) {
    data = tokenizeIntegers(readline());
    var x = data[0], y = data[1];
    augment(x, y);
    augment(y, x);
  }
  var seen = {},
      cycle = [],
      found = false;
  function search(u, parent) {
    //print('u = '+u+', parent = '+parent);
    if (seen[u]) {
      cycle.push(u);
      return true;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    for (var i = 0; i < vs.length; ++i) {
      var v = vs[i];
      if (v == parent) {
        continue;
      }
      if (search(v, u)) {
        if (cycle[0] == u) {
          found = true;
        }
        if (!found) {
          cycle.push(u);
        }
        return true;
      }
    }
    return false;
  }
  for (var u = 1; u <= n; ++u) {
    if (v2v[u] !== undefined) {
      search(u, -1);
      break;
    }
  }
  //print(found);
  //print(cycle.join(' '));
  if (cycle.length < 3 || n != m) {
    print('NO');
    return;
  }
  var count = 0;
  seen = {};
  function visit(u) {
    if (seen[u]) {
      return;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    for (var i = 0; i < vs.length; ++i) {
      visit(vs[i]);
    }
  }
  visit(cycle[0]);
  print(count == n ? 'FHTAGN!' : 'NO');
}

main();

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

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
    v2v = {};
  if (n != m) {
    print('NO');
    return;
  }
  function augment(u, v) {
    if (v2v[u] === undefined) {
      v2v[u] = [v];
    } else {
      v2v[u].push(v);
    }
  }
  for (var i = 0; i < m; ++i) {
    data = tokenizeIntegers(readline());
    var x = data[0], y = data[1];
    augment(x, y);
    augment(y, x);
  }
  var count = 0,
      seen = {};
  function visit(u) {
    if (seen[u]) {
      return;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    if (vs === undefined) {
      return;
    }
    for (var i = 0; i < vs.length; ++i) {
      visit(vs[i]);
    }
  }
  visit(1);
  print(count == n ? 'FHTAGN!' : 'NO');
}

main();

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

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
    v2v = {};
  if (n != m) {
    print('NO');
    return;
  }
  function augment(u, v) {
    if (v2v[u] === undefined) {
      v2v[u] = [v];
    } else {
      v2v[u].push(v);
    }
  }
  for (var i = 0; i < m; ++i) {
    data = tokenizeIntegers(readline());
    var x = data[0], y = data[1];
    augment(x, y);
    augment(y, x);
  }
  var seen = {},
      cycle = [],
      found = false;
  function search(u, parent) {
    if (seen[u]) {
      cycle.push(u);
      return true;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    if (vs === undefined) {
      return;
    }
    for (var i = 0; i < vs.length; ++i) {
      var v = vs[i];
      if (v == parent) {
        continue;
      }
      if (search(v, u)) {
        if (cycle[0] == u) {
          found = true;
        }
        if (!found) {
          cycle.push(u);
        }
        return true;
      }
    }
    return false;
  }
  search(1, -1);
  if (cycle.length < 3) {
    print('NO');
    return;
  }
  var count = 0;
  seen = {};
  function visit(u) {
    if (seen[u]) {
      return;
    }
    seen[u] = true;
    count += 1;
    var vs = v2v[u];
    for (var i = 0; i < vs.length; ++i) {
      visit(vs[i]);
    }
  }
  visit(cycle[0]);
  print(count == n ? 'FHTAGN!' : 'NO');
}

main();

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

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
    v2v = {};
  function augment(u, v) {
    if (v2v[u] === undefined) {
      v2v[u] = [v];
    } else {
      v2v[u].push(v);
    }
  }
  for (var i = 0; i < m; ++i) {
    data = tokenizeIntegers(readline());
    var x = data[0], y = data[1];
    augment(x, y);
    augment(y, x);
  }
  var seen = {},
      cycle = [],
      found = false,
      deleted = {};
  function search(u, parent) {
    //print(u, parent);
    if (seen[u]) {
      cycle.push(u);
      return true;
    }
    seen[u] = true;
    var vs = v2v[u];
    for (var i = 0; i < vs.length; ++i) {
      var v = vs[i];
      if (v == parent || deleted[[u, v]]) {
        continue;
      }
      if (search(v, u)) {
        if (cycle[0] == u) {
          found = true;
        }
        if (!found) {
          cycle.push(u);
        }
        return true;
      }
    }
    return false;
  }
  for (var u = 1; u <= n; ++u) {
    if (v2v[u] !== undefined) {
      search(u, -1);
      break;
    }
  }
  //print(found);
  //print(cycle.join(' '));
  if (cycle.length < 3 || n != m) {
    print('NO');
    return;
  }
  for (var i = 0; i < cycle.length; ++i) {
    var u = cycle[i], v = cycle[(i+1)%cycle.length];
    deleted[[u, v]] = deleted[[v, u]] = true;
  }
  for (var u = 1; u <= n; ++u) {
    if (v2v[u] !== undefined) {
      seen = {};
      cycle = [];
      found = false;
      search(u, -1);
      if (found) {
        //print('found a cycle starting from '+u);
        //print(cycle.join(' '));
        print('NO');
        return;
      }
    }
  }
  print('FHTAGN!');
}

main();


Alice has a grid with $$$2$$$ rows and $$$n$$$ columns. She fully covers the grid using $$$n$$$ dominoes of size $$$1 \times 2$$$ — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the other row of the grid looks like!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the width of the grid. The second line of each test case contains a string $$$s$$$ consisting of $$$n$$$ characters, each of which is either L, R, U, or D, representing the left, right, top, or bottom half of a domino, respectively (see notes for better understanding). This string represents one of the rows of the grid.  Additional constraint on the input: each input corresponds to at least one valid tiling.

For each test case, output one string — the other row of the grid, using the same format as the input string. If there are multiple answers, print any.

NoteIn the first test case, Alice shows Bob the top row, the whole grid may look like:   In the second test case, Alice shows Bob the bottom row, the whole grid may look like:   In the third test case, Alice shows Bob the bottom row, the whole grid may look like:   In the fourth test case, Alice shows Bob the top row, the whole grid may look like:

var t = parseInt(readline()); // Number of testCases
var n; // Number of Chars
var s; // String itself

var problemCounter = 0;
while (problemCounter++ < t) {
    n = readline();
    s = readline().split("");
    s.forEach((c, index) => {
        switch (c) {
            case "U":
                s[index] = "D";
                break;
            case "D":
                s[index] = "U";
                break;
        }
    });
    print(s.length > 1 ? "".concat.apply("", s) : s[0]);
}

var a = readline();
var arr = [];
var s = "";
for(var i = 0; i < a; i++){
    var n = readline();
    arr[i] = readline();
    for(var j = 0; j < arr[i].length; j++){
        if(arr[i][j]=="U"){
           s+=arr[i][j]="D"
        }else if(arr[i][j]=="D"){
            s+=arr[i][j]="U"
        }else{
            s+=arr[i][j]
        }
    }
    print(s);
    s="";
}

function run(){
    var n = readline();
    var s = readline();
    var ans = [];
    var res = "";
    for(var x = 0; x < n; x++){
        if(s[x] == "L") ans.push('L'), res += "L";
        else if(s[x] == 'R') ans.push('R'), res += "R";
        else if(s[x] == 'D') ans.push('U'), res += "U";
        else ans.push('D'),res += "D";
    }
    print(res);
}

var tc = readline();
while(tc--) {
    run();
}

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*/
    var s= ''
    for(j = 1; j <= (Number(lines[0])) * 2; j ++ ) {
        if(j % 2 === 0){
            s = ''
            var a = lines[j].split('')
            for(k = 0 ; k < a.length; k++){
            if(a[k] == 'L'){
                s += 'L'
            }else if(a[k] == 'R'){
                s += 'R'
            }else if(a[k] == 'U'){
                s += 'D'
            }else if(a[k] == 'D'){
                s += 'U'
            }
            }
                    console.log(s)

        }
    }
});

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = input.split(EOL)
    const count = parseInt(lines[0]);
    for (let i = 0; i < count; i++) {
        const idx = 1 + i * 2;
        const len = parseInt(lines[idx]);
        const line = lines[idx+1];
        let output = '';
        for (let c = 0; c < len; c++) {
            const ch = line[c];
            if (ch === 'L' || ch === 'R') {
                output += ch;
            } else if (ch === 'U') {
                output += 'D';
            } else if (ch === 'D') {
                output += 'U';
            }
        }
        console.log(output);
    }
})

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 = [];
	let kv = { "U": "D",
				"D": "U",
				"L": "L",
				"R": "R"};
	for(let i = 0; i < t; i++){
		nl.num();
		let a = nl.line().split('').map(e => kv[e]);
		ans.push(a.join(''));
	}
	console.log(ans.join('\n'));
};

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

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 = [];
	let kv = { "U": "D",
				"D": "U",
				"L": "L",
				"R": "R"};
	for(let i = 0; i < t; i++){
		nl.num();
		let a = [...nl.line()].map(e => kv[e]);
		ans.push(a.join(''));
	}
	console.log(ans.join('\n'));
};

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

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    readLine();
    let str = readLine();
    let arr = [];
    for (let index = 0; index < str.length; index++) {
        const element = str[index];
        if (element === "U") arr.push("D")
        else if (element === "D") arr.push("U")
        else arr.push(element);
    }
    return arr.join("");
}

//required remainder
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*/
    var l = lines[0];
    var answer = '';
    for(var j = 1; j < (Number(l) + 1) * 2; j++){
        if(j % 2 === 0){
            answer = '';
            var n = lines[j].split('');
            for(k = 0; k < n.length; k++){
                if(n[k] == 'L'){
                    answer += 'L';
                }else if(n[k] == 'R'){
                    answer += 'R';
                }else if(n[k] == 'U'){
                    answer += 'D';
                }else if(n[k] == 'D'){
                    answer += 'U';
                }
            }
            console.log(answer);
        }
    }
});

const { setupMaster } = require('cluster')
const { stderr } = require('process')

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

    let problem = {
      T: [],
      testCases: []
    }

    rl.on('line', function (line) {
      // TODO: Process input
      if (problem.T === 0) {
        // Get number of test cases from first line
        problem.T.push(line.split(" "))
      } else {
        // TODO process the rest of the data
        const [a, b, c] =line.split(' ')
        const aNum = Number(a)
        const bNum = Number(b)
        const cNum = Number(c)

        problem.testCases.push(line.split(" "));
      }
    })

    .on('close', () => {
      // Finished processing input, now solve question
      solve();
      process.exit()
    })

    function solve() {
      let a = problem.testCases;
      let y = 2;
      let x = 0;
      let r = 0;
      const povs = "LRUD";
      let n = "";
      while (y < a.length) {
        let s = a[y][0].split("");
        if (povs.includes(s[x])) {
          if (s[x] === "U") {
            s[x] = "D";
            n = n + s[x];
          } else if (s[x] === "D") {
              s[x] = "U";
              n = n + s[x];
          } else {
              n = n + s[x];
          }
          x++;
        }
        if (x === s.length) {
          console.log(n)
          n = "";
          y += 2;
          x = 0;
        }
      }
    }
  }  readInput()

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

    main();
});

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

function main() {
    const charResMap = {
        'U': 'D',
        'R': 'R',
        'L': 'L',
        'D': 'U'
    }
    const t = parseInt(readLine(), 10);
    for(let i =0; i<t; i++){
        let n =  parseInt(readLine(), 10);
        let s = readLine();
        const result = [];
        for (let char of s){
            result.push(charResMap[char])
        }

        console.log(result.join(''))

    }
    return;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

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

  // console.log(array)
  Array(Number(xx)).fill(1).map((t, i) => {
    const n = Number(readline());

    // var [a, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split('').map((x, iii) => {
      return x
    })
    var res = []
    for (let j = 0; j < n; j++) {
      if(a[j] === "U") res[j] = "D"
      if(a[j] === "L") res[j] = "L"
      if(a[j] === "R") res[j] = "R"
      if(a[j] === "D") res[j] = "U"
    }
// console.log(a)
// console.log(n)
console.log(res.join( ''))
    // if(i===(string.length-2)) return console.log(string)
  })
}

//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] = BigInt(next());
		}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 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 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 N = nextInt();
		var s = next();
		var output = new Array(N);
		for(var i = 0; i < N; i++){
			if(s[i] == "U"){
				output[i] = "D";
			}else if(s[i] == "D"){
				output[i] = "U";
			}else{
				output[i] = s[i];
			}
		}
		myout(myconv(output, 0));
	}
}

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*/
    var s= ''
    for(j = 1; j <= (Number(lines[0])) * 2; j ++ ) {
        if(j % 2 === 0){
            s = ''
            var a = lines[j].split('')
            for(k = 0 ; k < a.length; k++){
            if(a[j] == 'L'){
                s += 'L'
            }else if(a[k] == 'R'){
                s += 'R'
            }else if(a[k] == 'U'){
                s += 'D'
            }else if(a[k] == 'D'){
                s += 'U'
            }
            }
                    console.log(s)

        }
    }
});

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*/
    var s= ''
    for(j = 1; j <= Number(lines[0]) * 2; j ++ ) {
        if(j % 2 === 0){
            s = ''
            var a = lines[j].split('')
            for(k = 0 ; k < a.length; k++){
            if(a[j] == 'L'){
                s += 'L'
            }else if(a[k] == 'R'){
                s += 'R'
            }else if(a[k] == 'U'){
                s += 'D'
            }else if(a[k] == 'D'){
                s += 'U'
            }
            }
                    console.log(s)

        }
    }
});

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*/
    var s= ''
    for(j = 1; j <= Number(lines[0]) * 2; j ++ ) {
        if(j % 2 === 0){
            var a = lines[j].split('')
            for(k = 0 ; k < a.length; k++){
            if(a[j] == 'L'){
                s += 'L'
            }else if(a[k] == 'R'){
                s += 'R'
            }else if(a[k] == 'U'){
                s += 'D'
            }else if(a[k] == 'D'){
                s += 'U'
            }
            }
                    console.log(s)

        }
    }
});

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*/
    var s= ''
    for(j = 1; j <= Number(lines[0]) * 2; j ++ ) {
        if(j % 2 === 0){
            var a = lines[j].split('')
            for(k = 0 ; k < a.length; k++){
            if(a[j] == 'L'){
                s += 'L'
            }else if(a[k] == 'R'){
                s += 'R'
            }else if(a[k] == 'U'){
                s += 'U'
            }else if(a[k] == 'D'){
                s += 'D'
            }
            }
                    console.log(s)

        }
    }
});

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*/
    var s= ''
    for(j = 1; j <= Number(lines[0]) * 2; j ++ ) {
        if(j % 2 === 0){
            var a = lines[j].split('')
            for(k = 0 ; k < a.length; k++){
            if(a[j] == 'L'){
                s += 'L'
            }else if(a[j] == 'R'){
                s += 'R'
            }else if(a[j] == 'U'){
                s += 'U'
            }else if(a[j] == 'D'){
                s += 'D'
            }
            }
                    console.log(s)

        }
    }
});

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*/
    var s= ''
    for(j = 1; j <= Number(lines[0]) * 2; j ++ ) {
        if(j % 2 === 0){
            var a = lines[j].split('')
            if(a[j] == 'L'){
                s += 'L'
            }else if(a[j] == 'R'){
                s += 'R'
            }else if(a[j] == 'U'){
                s += 'U'
            }else if(a[j] == 'D'){
                s += 'D'
            }
        }
        console.log(s)
    }
});

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = input.split(EOL)
    const count = parseInt(lines[0]);
    for (let i = 1; i < count; i += 2) {
        const len = parseInt(lines[i]);
        const line = lines[i+1];
        let output = '';
        for (let c = 0; c < len; c++) {
            const ch = line[c];
            if (ch === 'L' || ch === 'R') {
                output += ch;
            } else if (ch === 'U') {
                output += 'D';
            } else if (ch === 'D') {
                output += 'U';
            }
        }
        console.log(output);
    }
})

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = input.split(EOL)
    const count = parseInt(lines[0]);
    for (let i = 0; i < count; i += 2) {
        const len = parseInt(lines[i]);
        const line = lines[i+1];
        let output = '';
        for (let c = 0; c < len; c++) {
            const ch = line[c];
            if (ch === 'L' || ch === 'R') {
                output = ch;
            } else if (ch === 'U') {
                output = 'D';
            } else if (ch === 'D') {
                output = 'U';
            }
        }
        console.log(output);
    }
})