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.


-----Input-----

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.


-----Output-----

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.


-----Examples-----

Input
4
2
2 1
3
1 2 1
4
2 4 1 3
5
2 5 1 4 3
Output
1
1 2 1
1
1 3 2
3
2 4 1
2 3 1
1 3 2
4
2 4 2
1 5 3
1 2 1
1 3 1


-----Note-----

Explanation 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]$

Difficulty: EASY
Tags: Sorting

Implementation
Skill types: Sorting

Starter code:

Solutions:
def rotate(sliced):
	rotated = [sliced[len(sliced) - 1]]
	for i in range(len(sliced) - 1):
		rotated.append(sliced[i])
	return rotated
t = int(input())
for i in range(t):
	ans = []
	shifts = []
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(len(a)):
		for j in range(len(a) - 1):
			end = 0
			start = 0
			if a[j + 1] < a[j]:
				end = j + 1
				for x in range(end - 1, -1, -1):
					if a[x] >= a[end]:
						start = x
					else:
						break
			if end > start:
				ans.append([start + 1, end + 1])
				a[start:end + 1] = rotate(a[start:end + 1])
				shifts.append(len(a[start:end + 1]) - 1)
				break
	print(len(ans))
	for p in range(len(ans)):
		ans[p].append(shifts[p])
		for z in range(len(ans[p])):
			print(ans[p][z], end=' ')
		print('')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a_sorted = sorted(a)
	(ans, ans_list) = (0, [])
	for i in range(n):
		if a[i] == a_sorted[i]:
			continue
		(left, right) = (i + 1, n)
		for m in range(i + 1, n):
			if a[m] == a_sorted[i]:
				move = m - i
				break
		a = a[:i] + a[i + move:n] + a[i:i + move]
		ans += 1
		ans_list.append((left, right, move))
	print(ans)
	for answer in ans_list:
		print(*answer)


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			a = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not a:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(a), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			a = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = a.count(b'\n') + (not a)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(a), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 1000000007
for _ in range(inp()):
	n = inp()
	arr = int_arr()
	lst = arr.copy()
	lst.sort()
	ans = []
	for i in range(n):
		if arr[i] != lst[i]:
			for j in range(i + 1, n):
				if arr[j] == lst[i]:
					temp = arr[i:j]
					arr = arr[:i] + [arr[j]] + arr[j + 1:] + temp
					break
			ans.append([i + 1, n, j - i])
	print(len(ans))
	for i in ans:
		print(*i)


def shift(l, n):
	return l[n:] + l[:n]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	ans = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		num = b[i]
		j = a[i:].index(num) + i
		d = j - i
		ans.append([i + 1, j + 1, d])
		c = a[i:j + 1]
		c = shift(c, d)
		a[i:j + 1] = c
	print(len(ans))
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	c = 0
	for i in range(n - 1):
		ind = arr.index(min(arr))
		if ind > 0:
			temp = str(i + 1) + ' ' + str(ind + i + 1) + ' ' + str(ind)
			ans.append(temp)
			c += 1
		arr = arr[:ind] + arr[ind + 1:]
	print(c)
	print('\n'.join(ans))


from sys import stdin, stdout

def ilist_from_str():
	return list(map(int, stdin.readline().strip().split()))

def ints_from_str():
	return map(int, stdin.readline().strip().split())

def strs_from_str():
	return stdin.readline().strip().split()

def print_(for_print):
	stdout.write(str(for_print) + '\n')

def str_():
	return stdin.readline().strip()

def int_():
	return int(stdin.readline().strip())

def print_nl():
	stdout.write('\n')

def gcd_sum(n):
	return gcd(n, sum(map(int, list(str(n)))))

def solve(n, l):
	(k, l_ans) = (0, [])
	for i in range(n):
		mn = min(l[i:n])
		ind = l[i:n].index(mn) + i
		if ind > i:
			for j in range(ind - i):
				l[ind - j] = l[ind - j - 1]
			l[i] = mn
			k += 1
			l_ans.append(str(i + 1) + ' ' + str(ind + 1) + ' ' + str(ind - i))
	print_(k)
	for i in l_ans:
		print_(i)
sets = int_()
for _ in range(sets):
	solve(int_(), ilist_from_str())


def main():
	t = int(input())
	while t:
		n = int(input())
		arr = list(map(int, input().split()[:n]))
		sortedArr = sorted(arr)
		res = []
		for i in range(n):
			d = 0
			while arr[i] != sortedArr[i]:
				arr = arr[:i] + arr[i + 1:] + [arr[i]]
				d += 1
			if d != 0:
				res.append([i + 1, n, d])
		print(len(res))
		for i in res:
			print(*i, sep=' ')
		t -= 1
main()


t = int(input())
for _ in range(t):
	n = int(input())
	actions = []
	a = list(map(int, input().split()))
	for i in range(len(a) - 1):
		min_pos = i
		for j in range(i + 1, len(a)):
			if a[j] < a[min_pos]:
				min_pos = j
		if min_pos > i:
			actions.append((i, min_pos))
			opt = a[min_pos]
			for j in range(min_pos, i, -1):
				a[j] = a[j - 1]
			a[i] = opt
	print(len(actions))
	for ac in actions:
		print(ac[0] + 1, ac[1] + 1, ac[1] - ac[0])


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
from math import cos, sin
from itertools import permutations
from operator import itemgetter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def solve(id, x):
	l = id
	for i in range(id, n):
		if a[i] == x:
			l = i
			break
	ct = [a[l]] + a[id:l]
	ans.append([id + 1, l + 1, len(ct) - 1])
	for i in range(len(ct)):
		a[i + id] = ct[i]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	ck = sorted(a)
	for i in range(n):
		if a[i] != ck[i]:
			solve(i, ck[i])
	print(len(ans))
	for i in ans:
		print(*i)


def shifts(arr):
	steps = []
	req = sorted(arr)
	while arr != req:
		(nomat, ind) = nonmatch(arr, req)
		shift = ind - nomat
		changed = [arr[ind]]
		changed.extend(arr[nomat:ind])
		arr[nomat:ind + 1] = changed
		steps.append([nomat, ind, shift])
	return steps

def nonmatch(arr, req):
	curr = -1
	for i in range(len(arr)):
		if arr[i] != req[i]:
			curr = i
			break
	nex = -1
	for i in range(curr, len(arr)):
		if arr[i] == req[curr]:
			nex = i
	return (curr, nex)
for j in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	steps = shifts(arr)
	print(len(steps))
	for i in steps:
		print(f'{i[0] + 1} {i[1] + 1} {i[2]}')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = []
	for i in range(n - 1):
		ind = a.index(min(a))
		if ind > 0:
			ans.append(str(i + 1) + ' ' + str(ind + 1 + i) + ' ' + str(ind))
		a = a[:ind] + a[ind + 1:]
	print(len(ans))
	print('\n'.join(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = sorted(arr)
	if arr == arr1:
		print(0)
	else:
		i = 0
		ans = []
		while i < n:
			cnt = arr[i:].index(arr1[i])
			ans.append([i + 1, n, cnt])
			arr = arr[:i] + arr[i:][cnt:] + arr[i:][:cnt]
			i += 1
		ans1 = []
		for (p, q, r) in ans:
			if r != 0:
				ans1.append([p, q, r])
		print(len(ans1))
		for i in ans1:
			for j in i:
				print(j, end=' ')
			print()


t = int(input())
for ti in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	q = [[a[i], i] for i in range(n)]
	q.sort()
	for i in range(n):
		a[q[i][1]] = i
	aa = []
	for i in range(n):
		if a[i] != i:
			b = a.index(i)
			aa.append([i + 1, b + 1, b - i])
			a = a[:i] + a[b:b + 1] + a[i:b] + a[b + 1:]
	print(len(aa))
	for i in aa:
		print(' '.join(list(map(str, i))))


import sys
fin = sys.stdin.readline
fout = sys.stdout.write

def ints(collection=None):
	inmap = map(int, fin().split())
	return collection(inmap) if collection else inmap

def print_list(collection, delimiter=' '):
	fout(delimiter.join(map(str, collection)) + '\n')

def check_sort(a):
	for i in range(1, len(a)):
		if a[i - 1] > a[i]:
			return False
	return True

def s(a):
	ans = []
	i = 0
	while i != len(a):
		r = i
		l = r
		for j in range(i + 1, len(a)):
			if a[j] < a[i]:
				r = j
		if l != r:
			tmp = a[l]
			for v in range(l, r):
				a[v] = a[v + 1]
			a[r] = tmp
			ans.append((l + 1, r + 1, 1))
		else:
			i += 1
	print(len(ans))
	for k in ans:
		print(*k)

def solve():
	input()
	a = ints(list)
	s(a)
t = int(input())
while t:
	t -= 1
	solve()


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = []
	for i in range(1, n):
		md = a.index(min(a))
		if md:
			res.append([i, i + md, md])
		a = a[:md] + a[md + 1:]
	print(len(res))
	for i in res:
		print(*i)


from sys import stdin, stdout
for t in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().strip().split()))
	a_sorted = sorted(a)
	res = []
	for i in range(n - 1, -1, -1):
		if a_sorted[i] != a[i]:
			idx = a.index(a_sorted[i])
			a = a[:idx] + a[idx + 1:i + 1] + [a[idx]] + a[i + 1:]
			res.append((idx, i, 1))
	print(len(res))
	for (l, r, d) in res:
		print(l + 1, r + 1, d)


from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		r = a[i:]
		k = r.index(min(a[i:]))
		k = k + i
		z = deque(a[i:])
		z.rotate(-(k - i))
		l = 0
		for j in range(i, n):
			a[j] = z[l]
			l += 1
		if k > i:
			b.append([i + 1, n, k - i])
	print(len(b))
	for i in b:
		print(i[0], i[1], i[2], end=' ')
		print()


def cyc(arr, d):
	nw = [0] * len(arr)
	for i in range(len(arr)):
		nw[i] = arr[(i + d) % len(arr)]
	return nw
for _ in range(int(input())):
	llen = int(input())
	l = list(map(int, input().split()))
	ans = []
	sortedp = 0
	for i in range(sortedp, llen - 1):
		mn = 10000000000.0
		idx = -1
		for j in range(sortedp, llen):
			if l[j] < mn:
				mn = l[j]
				idx = j
		x = abs(sortedp - idx)
		if x == 0:
			sortedp += 1
			continue
		nxt = cyc(l[sortedp:idx + 1], x)
		for k in range(len(nxt)):
			l[k + sortedp] = nxt[k]
		ans.append([sortedp + 1, idx + 1, x])
		sortedp += 1
	print(len(ans))
	for el in ans:
		print(*el)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for i in range(n - 1):
		idx = a.index(min(a))
		if idx > 0:
			ans.append([i + 1, i + idx + 1, idx])
		a = a[:idx] + a[idx + 1:]
	print(len(ans))
	for k in ans:
		print(*k)


def rotate_left(lst, l, r):
	hold = [lst[r]]
	for k in range(l, r):
		hold.append(lst[k])
	for k in range(l, r + 1):
		lst[k] = hold[k - l]
	return lst
T = int(input())
for t in range(T):
	N = int(input())
	vals = [int(s) for s in input().split()]
	v2 = [s for s in vals]
	v2.sort()
	rots = []
	for (i, v) in enumerate(v2):
		if v != vals[i]:
			j = i + 1
			while vals[j] != v:
				j += 1
			vals = rotate_left(vals, i, j)
			rots.append((i + 1, j + 1, j - i))
	print(len(rots))
	for (l, r, d) in rots:
		print(l, r, d)


from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = a.copy()
	b.sort()
	ans = 0
	out = []
	start = 0
	while True:
		if a == b:
			break
		for i in range(start, n):
			if a[i] == b[i] and i == start:
				start += 1
				break
			if a[i] == b[start]:
				temp = deque(a[start:i + 1])
				temp.rotate(-(i - start))
				a = a[:start] + list(temp) + a[i + 1:]
				out.append([start + 1, i + 1, i - start])
				start += 1
				ans += 1
				break
	print(ans)
	for i in out:
		print(*i)


import bisect
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = l.copy()
	o.sort()
	if l == o:
		sys.stdout.write('0\n')
		continue
	cnt = 0
	ans = 0
	w = []
	while cnt < n:
		if l[cnt] == o[cnt]:
			cnt += 1
			continue
		for i in range(cnt, n):
			if l[i] == o[cnt]:
				ans += 1
				w.append((cnt + 1, i + 1, i - cnt))
				h = l[cnt:i]
				q = l[i]
				e = l[0:cnt] + [q] + h + l[i + 1:n]
				l = e
				break
		cnt += 1
	sys.stdout.write(str(ans) + '\n')
	for i in w:
		sys.stdout.write(str(i[0]) + ' ' + str(i[1]) + ' ' + str(i[2]) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = []
	for i in range(n):
		min_val = min(arr)
		min_ind = arr.index(min_val)
		if min_ind:
			res.append([i + 1, i + 1 + min_ind, min_ind])
		del arr[min_ind]
	print(len(res))
	for x in res:
		print(*x)


from sys import stdin
import collections, heapq, bisect, math
input = stdin.readline

def rint():
	return int(input())

def rstr():
	return input().strip()

def rlstr():
	return list(input().strip().split())

def rlint():
	return list(map(int, input().split()))

def main():
	n = rint()
	arr = rlint()
	s = sorted(arr)
	res = []

	def shift(i, j):
		for k in range(j - 1, i - 1, -1):
			(arr[k], arr[k + 1]) = (arr[k + 1], arr[k])
	for i in range(n):
		j = i
		while j < n and s[i] != arr[j]:
			j += 1
		if i != j:
			shift(i, j)
			res.append([i + 1, j + 1, j - i])
	print(len(res))
	for row in res:
		print(*row)
for _ in range(rint()):
	main()


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ans = []
	for i in range(n):
		B = A[i:n]
		m = min(B)
		for j in range(i, n):
			if A[j] == m:
				break
		if i == j:
			continue
		A[i:j + 1] = [A[j]] + A[i:j]
		ans.append((i + 1, j + 1, j - i))
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(__) for __ in input().split()]
	ans = []
	arr_sorted = arr[:]
	arr_sorted.sort()
	for _ in range(n):
		if arr[_] != arr_sorted[_]:
			idx = arr[_:].index(arr_sorted[_]) + _
			ans.append([_ + 1, idx + 1, idx - _])
			deq_rotated = deque(arr[_:idx + 1])
			deq_rotated.rotate(_ - idx)
			arr = arr[:_] + list(deq_rotated) + arr[idx + 1:]
	print(len(ans))
	for _ in ans:
		print(*_)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	d = [int(i) for i in sys.stdin.readline().split()]
	(r, rr) = ('', 0)
	for i in range(n - 1):
		x = d[i:]
		a = x.index(min(x))
		if a != 0:
			r += '%d %d %d\n' % (i + 1, a + 1 + i, a)
			rr += 1
			d = d[:i] + [d[a + i]] + d[i:a + i] + d[a + 1 + i:]
	sys.stdout.write('%d\n%s' % (rr, r))


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	temp = arr[:]
	temp.sort()
	i = 0
	ans = []
	while i < n:
		if arr[i] == temp[i]:
			i += 1
			continue
		else:
			l = i
			r = i
			for j in range(i, n):
				if arr[j] == temp[i]:
					r = j
					break
			tempVal = arr[r]
			arr[l + 1:r + 1] = arr[l:r]
			arr[l] = tempVal
			ans.append([l + 1, r + 1, r - l])
		i += 1
	print(len(ans))
	for i in ans:
		print(*i)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(1, ii() + 1):
		n = ii()
		a = li()
		b = a[:]
		b.sort()
		res = []
		for i in range(n):
			if a[i] == b[i]:
				continue
			for j in range(i + 1, n):
				if a[j] == b[i]:
					d = j - i
					res.append([i + 1, j + 1, d])
					a[i] = a[j]
					a[i + 1:j + 1] = a[i:j]
		print(len(res))
		for i in res:
			print(*i)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	step = 0
	proc = []
	for j in range(n - 1, 0, -1):
		pos = a.index(max(a[0:j + 1]))
		l_val = a[pos]
		if pos != j:
			for k in range(pos, j):
				a[k] = a[k + 1]
			a[j] = l_val
			step += 1
			proc.append([pos + 1, j + 1, 1])
	print(step)
	for j in range(0, step):
		print(proc[j][0], proc[j][1], proc[j][2])


def rotate(arr, left, cnt):
	return arr[:left] + arr[left + cnt:] + arr[left:left + cnt]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	st = sorted(a)
	ans = []
	for i in range(1, n + 1):
		if a[i - 1] != st[i - 1]:
			index = a.index(st[i - 1], i - 1)
			r = index - i + 1
			ans.append((i, n, r))
			a = rotate(a, i - 1, r)
	print(len(ans))
	for x in ans:
		print(*x)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = []
	end = n - 1
	while end >= 0:
		m = max(arr[:end + 1])
		idx = arr.index(m)
		if idx != end:
			ans.append([idx + 1, end + 1, 1])
			for i in range(idx, end):
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		end = end - 1
	print(len(ans))
	for x in ans:
		print(*x)


try:
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		count = 0
		output = []
		for j in range(n):
			mn = a[j]
			mnpos = j
			for k in range(j, n):
				if a[k] < mn:
					mn = a[k]
					mnpos = k
			if mnpos != j:
				output.append((j + 1, mnpos + 1, mnpos - j))
				count += 1
				temp = mn
				for k in range(mnpos, j, -1):
					a[k] = a[k - 1]
				a[j] = temp
		print(count)
		for j in range(count):
			print(output[j][0], output[j][1], output[j][2])
except:
	pass


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for i in range(n - 1):
		x = a[i:]
		idx = x.index(min(x))
		if not idx:
			continue
		ans.append((i + 1, n, idx))
		a = a[:i] + a[idx + i:] + a[i:idx + i]
	print(len(ans))
	for i in ans:
		print(*i)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	b = []
	for j in arr:
		b.append(j)
	b.sort()
	pt = []
	for j in range(n):
		mini = arr.index(b[j], j, n)
		if j == mini:
			continue
		pt.append([j, mini])
		arr = arr[:j] + [arr[mini]] + arr[j:mini] + arr[mini + 1:]
	print(len(pt))
	for i in pt:
		print(i[0] + 1, i[1] + 1, i[1] - i[0])


def rolling(s, n):
	l = len(s)
	return s[n % l:] + s[:n % l]

def solve():
	N = int(input())
	A = list(map(int, input().split()))
	ans = []
	for i in range(N):
		minA = min(A[i:])
		idx = A[i:].index(minA)
		if idx != 0:
			ans.append((i + 1, i + idx + 1, idx))
			A[i:i + idx + 1] = rolling(A[i:i + idx + 1], idx)
	print(len(ans))
	for a in ans:
		print(*a)
Q = int(input())
for _ in range(Q):
	solve()


def is_sorted(seq):
	for x in range(len(seq) - 1):
		if seq[x] > seq[x + 1]:
			return False
	return True
for _ in range(int(input())):
	input()
	values = list(map(int, input().split()))
	n = len(values)
	ops = []
	for sp in range(n):
		(min_val, min_index) = (values[sp], sp)
		if is_sorted(values):
			break
		for x in range(sp, n):
			if values[x] < min_val:
				min_val = values[x]
				min_index = x
		if min_index == sp:
			continue
		ops.append((sp + 1, n, min_index - sp))
		values = values[:sp] + values[min_index:] + values[sp:min_index]
	print(len(ops))
	for (a, b, c) in ops:
		print('{} {} {}'.format(a, b, c))


def leftshift(a, d):
	right = a[d:]
	left = a[:d]
	a = right + left
	return a
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = a.copy()
	c.sort()
	ans = []
	count = 0
	dic = {}
	for i in range(n):
		dic[a[i]] = i
	for i in range(n):
		tem = c[i]
		act_i = dic[tem]
		req_i = i
		if act_i == req_i:
			continue
		else:
			count += 1
			d = abs(req_i - act_i)
			a_tem = a[i:]
			a_old = a[:i]
			a_rem = leftshift(a_tem, d)
			a = a_old + a_rem
			ans.append([i + 1, n, d])
			for i in range(n):
				dic[a[i]] = i
			if a == c:
				break
	print(count)
	for i in ans:
		print(*i)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	out = []
	for i in range(n - 1):
		mi = a.index(min(a))
		if mi > 0:
			out.append([i + 1, n, mi])
		a = a[mi:] + a[:mi]
		a.remove(min(a))
	print(len(out))
	for e in out:
		print(e[0], e[1], e[2])


from sys import stdin
input = stdin.readline

def cycshift(a: list, n: int) -> list:
	lenlist = len(a)
	b = [0] * lenlist
	for i in range(len(a)):
		b[i - n] = a[i]
	return b
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	count = 0
	res = 0
	b = []
	for i in range(n):
		mn = min(a)
		if a[0] == mn:
			a.pop(0)
			count += 1
		else:
			id = a.index(mn)
			b.append([1 + count, id + 1 + count, id])
			a[0:id + 1] = cycshift(a[0:id + 1], id)
			a.pop(0)
			count += 1
			res += 1
	print(res)
	for j in b:
		print(*j)


t = int(input())
while t != 0:
	n = int(input())
	arr = [int(k) for k in input().split()]
	b = []
	c = 0
	for i in range(n):
		m = arr.index(min(arr))
		if m != 0:
			c += 1
			b.append([i + 1, n, m])
		arr = arr[m:] + arr[:m]
		arr.pop(0)
	print(c)
	for i in b:
		print(*i)
	t -= 1


m = int(input())
for i in range(m):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	c = 0
	li = []
	for i in range(n):
		ind = 0
		for j in range(n - i):
			if arr[j] >= arr[ind]:
				ind = j
		if ind == n - i - 1:
			continue
		c += 1
		l = ind
		r = n - i - 1
		d = l - r
		for k in range(l, r):
			temp = arr[k]
			arr[k] = arr[k + 1]
			arr[k + 1] = temp
		li.append([l + 1, r + 1, -d])
	print(c)
	for l in li:
		print(str(l[0]) + ' ' + str(l[1]) + ' ' + str(1))


def solve():
	N = int(input())
	arr = list(map(int, input().split()))
	count1 = 0
	output = []
	for i in range(N):
		min1 = min(arr[i:])
		l1 = arr[i:].index(min1)
		if l1 != 0:
			count1 += 1
			output.append([i + 1, N, l1])
			a2 = []
			for j in range(i, N):
				a2.append(arr[j])
			last = N - i - l1
			j = len(a2) - last
			j1 = 0
			upto = i
			for k in range(last):
				arr[upto] = a2[j]
				j += 1
				upto += 1
			while upto < N:
				arr[upto] = a2[j1]
				j1 += 1
				upto += 1
	return output
remained_test_cases = 1
remained_test_cases = int(input())
while remained_test_cases > 0:
	output = solve()
	print(len(output))
	for i in range(len(output)):
		print(output[i][0], output[i][1], output[i][2])
	remained_test_cases -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted([x for x in a])
	shifts = []
	for (index, item) in enumerate(b):
		target_index = a[index:].index(item) + index
		if target_index == index:
			continue
		a[index:target_index + 1] = [item] + a[index:target_index]
		shifts.append((index + 1, target_index + 1, target_index - index))
	print(len(shifts))
	for (l, r, d) in shifts:
		print(l, r, d)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = arr[:]
	arr1.sort()
	ans = []
	cnt = 0
	for i in range(n):
		x = arr1[i]
		start = i + 1
		zzz = arr.index(x)
		end = zzz + 1 + i
		arr.pop(zzz)
		if abs(start - end) == 0:
			continue
		ans.append([start, end, end - start])
		cnt += 1
	print(cnt)
	for xx in ans:
		print(*xx)


def new_sub(lis):
	min_index = lis.index(min(lis))
	r = min_index
	d = min_index
	if min_index == 0:
		return (r, d, False)
	return (r, d, True)

def test():
	t = int(input())
	for _ in range(t):
		counter = 0
		n = int(input())
		log = []
		a = list(map(int, input().split(' ')))
		for i in range(n):
			info = new_sub(a[i:])
			if info[1]:
				l = i + 1
				r = i + info[0] + 1
				d = info[0]
				log.append((l, r, d))
				for __ in range(d):
					v = a[l - 1]
					del a[l - 1]
					a.insert(r - 1, v)
				counter += 1
		print(counter)
		for i in log:
			print(i[0], i[1], i[2])
test()


from itertools import product
import itertools
import math
import sys
import heapq
from collections import deque
MOD = 1000000000007

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
K = int(sys.stdin.readline().strip())
x = 0
y = 0
for _ in range(K):
	lt = []
	N = int(sys.stdin.readline().strip())
	ll = list(map(int, sys.stdin.readline().strip().split()))
	for i in range(N):
		lt.append((ll[i], i))
	lt.sort()
	l = [-1 for _ in range(N)]
	for i in range(N):
		l[lt[i][1]] = i + 1
	r = 0
	d = {}
	ans = []
	tt = 0
	for i in range(N):
		d[l[i]] = i
	for i in range(1, N):
		if d[i] == i - 1:
			continue
		tt += 1
		df = d[i] - i + 1
		ans.append((i, N, d[i] - i + 1))
		t = l[i - 1]
		ll = []
		for j in range(i, N + 1):
			ll.append(l[i - 1 + (j - i + df) % (N - i + 1)])
		for j in range(i, N + 1):
			l[j - 1] = ll[j - i]
			d[l[j - 1]] = j - 1
	print(tt)
	for (a, b, c) in ans:
		print(str(a) + ' ' + str(b) + ' ' + str(c))


for s in [*open(0)][2::2]:
	a = s.split()
	r = []
	i = 0
	for x in sorted(a, key=int):
		j = a.index(x, i) + 1
		a[i:j] = a[j - 1:j] + a[i:j - 1]
		i += 1
		r += ([], [i, j, j - i])[j > i]
	print(len(r) // 3, *r)


t = int(input())
while t:
	t -= 1
	n = int(input())
	nums = list(map(int, input().split()))
	nums_ = sorted(nums)
	cnt = 0
	to_ret = []
	for i in range(n):
		if nums[i] != nums_[i]:
			cnt += 1
			idx = nums[i:].index(nums_[i])
			to_ret.append([str(i + 1), str(i + idx + 1), str(idx)])
			nums = nums[:i] + [nums[i + idx]] + nums[i:i + idx] + nums[i + idx + 1:]
	print(cnt)
	for i in range(cnt):
		print(' '.join(to_ret[i]))


for _ in range(int(input())):
	k = int(input())
	l = list(map(int, input().split()))
	n = len(l)
	t = l[:]
	t.sort()
	ans = []
	for i in range(n):
		if l[i] != t[i]:
			idx = -1
			for j in range(i, n):
				if l[j] == t[i]:
					ans.append([i + 1, j + 1, j - i])
					idx = j
					break
			prev = l[idx]
			for j in range(i, idx + 1):
				temp = l[j]
				l[j] = prev
				prev = temp
	print(len(ans))
	for i in ans:
		print(*i)


tests_n = int(input())
for test in range(0, tests_n):
	n = int(input())
	str_arr = input().split(' ')
	arr = []
	for i in range(n):
		arr.append(int(str_arr[i]))
	sort_arr = sorted(arr)
	s = 0
	ops = []
	for i in range(n):
		l = 1
		r = arr.index(sort_arr[i]) + 1
		d = r - l
		del arr[r - 1]
		if d != 0:
			s += 1
			ops.append(str(l + i) + ' ' + str(r + i) + ' ' + str(d))
	print(s)
	for op in ops:
		print(op)


def rotate(array: list, r: int, l: int) -> list:
	array[r:l + 1] = [array[l]] + array[r:l]
	return array

def find(array: list, start: int, val: int) -> int:
	for x in range(start, len(array)):
		if array[x] == val:
			return x
	return -1

def main():
	for test in range(int(input())):
		n = int(input())
		(ans, array) = ([], [int(x) for x in input().split(' ')])
		arr_sorted = sorted(array)
		for i in range(len(arr_sorted)):
			to_rotate = find(array, i, arr_sorted[i])
			if to_rotate - i != 0:
				array = rotate(array, i, to_rotate)
				ans.append([i + 1, to_rotate + 1, to_rotate - i])
		print(len(ans))
		for action in ans:
			print(*action)
main()


t = int(input())
for sdfghbjn in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	l = []
	c = 0
	for i in range(n):
		ind = a[i:].index(b[i]) + i
		if ind != i:
			c += 1
			l.append((i + 1, ind + 1, ind - i))
			a.pop(ind)
			a.insert(i, b[i])
	print(c)
	for i in range(c):
		print(l[i][0], l[i][1], l[i][2])


from math import ceil, log, floor
from collections import defaultdict
import sys
import os.path
sys.setrecursionlimit(200000)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r+')
	sys.stdout = open('output.txt', 'w')

def MI():
	return map(int, input().split())

def solve():
	n = int(input())
	a = list(MI())
	b = sorted(a)
	l = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		for j in range(i + 1, n):
			if a[j] == b[i]:
				break
		l.append([i + 1, j + 1, j - i])
		prev = a[j]
		for k in range(i, j + 1):
			pre = a[k]
			a[k] = prev
			prev = pre
	print(len(l))
	for i in l:
		print(*i)
t = int(input())
for _ in range(t):
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for i in range(n - 1):
		mx = min(a[i:])
		for j in range(i, n):
			if a[j] == mx:
				break
		if j == i:
			continue
		a.insert(i, a.pop(j))
		ans += [[i + 1, j + 1, j - i]]
	print(len(ans))
	for (x, y, z) in ans:
		print(x, y, z)


numberTestCases = int(input())
outputs = []
for i in range(numberTestCases):
	length = int(input())
	arr = input().split(' ')
	arr = list(map(int, arr))
	outputs = []
	for j in range(length):
		temp = j
		number = arr[j]
		shifts = 0
		for k in range(j):
			if number < arr[k]:
				shifts += 1
		if shifts != 0:
			outputs.append([temp - shifts + 1, temp + 1, shifts])
	print(len(outputs))
	for out in outputs:
		print(out[0], out[1], out[2])


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	result = []
	for i in range(n):
		itr = max(range(len(arr)), key=lambda x: arr[x])
		if itr != n - i - 1:
			result.append([itr + 1, n - i, 1])
		arr.pop(itr)
	print(len(result))
	for elem in result:
		print(str(elem[0]) + ' ' + str(elem[1]) + ' ' + str(elem[2]))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = list()
	r = list()
	d = list()
	k = 0
	for i in range(n):
		min_el = min(a[i:])
		if a[i] != min_el:
			rindex = a.index(min_el, i, n)
			a = a[:i] + [min_el] + a[i:rindex] + a[rindex + 1:]
			l.append(i + 1)
			r.append(rindex + 1)
			d.append(rindex - i)
			k += 1
	print(f'{k}')
	for i in range(k):
		print(f'{l[i]} {r[i]} {d[i]}')


def soln(a, b):
	res = []
	for i in range(n):
		tar = b[i]
		for j in range(i + 1, n):
			if a[j] == tar:
				res.append([i + 1, j + 1, j - i])
				cpy = a[i:j]
				a[i] = tar
				a = a[:i + 1] + cpy + a[j + 1:]
				break
	print(len(res))
	for i in res:
		print(*i)
tn = int(input())
for _ in range(tn):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	b.sort()
	soln(a, b)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = []
	for i in range(n):
		x = min(a[i:])
		ind = a.index(x, i)
		if x == a[i]:
			continue
		else:
			a = a[:i] + [x] + a[i:ind] + a[ind + 1:]
			ans += [[i + 1, ind + 1, ind - i]]
	print(len(ans))
	for i in ans:
		print(*i)


def mini(a):
	return a.index(min(a))

def shift(d, seg):
	return seg[d:] + seg[:d]
for _ in range(int(input())):
	a = input()
	p = [int(x) for x in input().split()]
	c = 0
	st = ''
	for i in range(len(p)):
		r = mini(p[i:]) + i
		p[i:r + 1] = shift(r - i, p[i:r + 1])
		if i != r:
			c += 1
			st += str(i + 1) + ' ' + str(r + 1) + ' ' + str(r - i) + '\n'
	print(c)
	print(st, end='')


T = int(input())
while T > 0:
	T -= 1
	input()
	A = [int(x) for x in input().split()]
	output = []
	start = 1
	while len(A) != 0:
		i = min(list(((a, i) for (i, a) in enumerate(A))))[1]
		if i > 0:
			output.append((start, start + i, i))
		start += 1
		A = A[:i] + A[i + 1:]
	print(len(output))
	for (a, b, c) in output:
		print(a, b, c)


class BIT:

	def __init__(self, A):
		self.t = [0] * (2 * len(A) + 1)
		self.n = len(A)
		self.update(1, A[0].index)
		for i in range(1, len(A)):
			self.update(i + 1, A[i].index - A[i - 1].index)

	@staticmethod
	def lowbit(x):
		return x & -x

	def update(self, x, v):
		while x <= self.n:
			self.t[x] += v
			x += self.lowbit(x)

	def get_value(self, x):
		sum = 0
		while x > 0:
			sum += self.t[x]
			x -= self.lowbit(x)
		return sum

	def add(self, l, r, v):
		self.update(l, v)
		self.update(r + 1, -v)

class obj:

	def __init__(self, value, index):
		self.value = value
		self.index = index

	def __lt__(self, other):
		return self.value < other.value
T = int(input())
while T > 0:
	T -= 1
	input()
	A = [obj(int(x), i + 1) for (i, x) in enumerate(input().split())]
	A_sort = sorted(A)
	output = []
	B = BIT(A)
	for (i, a) in enumerate(A_sort):
		x = B.get_value(a.index)
		if x != i + 1:
			output.append((i + 1, x, x - i - 1))
			B.add(1, a.index - 1, 1)
	print(len(output))
	for (a, b, c) in output:
		print(a, b, c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[:]
	a.sort()
	ans = []
	for i in range(n):
		j = b[i:].index(a[i]) + i
		if i < j:
			ans.append((i + 1, j + 1, j - i))
			b = b[:i] + [b[j]] + b[i:j] + b[j + 1:]
	print(len(ans))
	for i in ans:
		print(*i)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	cnt = 0
	ans = []
	l = 0
	for i in b:
		ind = a[l:].index(i) + l
		if l != ind:
			c = a[l:ind].copy()
			a[l] = a[ind]
			a[l + 1:ind + 1] = c
			cnt += 1
			ans.append([l + 1, ind + 1, ind - l])
			l += 1
		else:
			l += 1
	print(len(ans))
	for i in ans:
		print(*i)


def shift(lst, steps):
	sp = lst[steps:] + lst[:steps]
	return sp
ans = []
for i in range(int(input())):
	ans.append([])
	n = int(input())
	spis = list(map(int, input().split()))
	right = n
	for j in range(n - 1):
		left = j
		otr = spis[left:]
		spis = spis[:left] + shift(spis[left:right], otr.index(min(otr)))
		if otr.index(min(otr)) != 0:
			ans[i].append((left + 1, right, otr.index(min(otr))))
for elem in range(len(ans)):
	print(len(ans[elem]))
	for s in ans[elem]:
		print(*s)


t = int(input())
for p in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	res = 0
	for i in range(0, n - 1):
		ma = a.index(max(a[0:n - i]))
		if ma != n - i - 1 and a[ma] != a[n - i - 1]:
			ans.append(str(ma + 1) + ' ' + str(n - i) + ' 1')
			res += 1
			a[ma:n - i] = a[ma + 1:n - i] + [a[ma]]
	print(res)
	print('\n'.join(ans))


from collections import defaultdict
from sys import stdin, stdout
(input, print) = (stdin.readline, stdout.write)
t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [(i, x) for (i, x) in enumerate(a)]
	a = sorted(a, key=lambda x: x[1])
	a = [(x[0], str(x[0]) + str(x[1])) for x in a]
	d = {}
	for i in range(n):
		d[a[i][1]] = a[i][0]
	queue = []
	for i in range(n):
		queue.append(a[i][1])
	ops = []
	for i in range(n):
		pos = d[queue[i]]
		old_pos = pos
		k = 0
		while pos != i:
			k += 1
			if pos == i:
				pos = n - 1
			else:
				pos -= 1
			for j in range(i + 1, n):
				old_pos = d[queue[j]]
				if old_pos == i:
					new_pos = n - 1
				else:
					new_pos = old_pos - 1
				d[queue[j]] = new_pos
		if k == 0:
			continue
		ops.append(f'{i + 1} {n} {k}')
	print(str(len(ops)))
	print('\n')
	for i in range(len(ops)):
		print(ops[i])
		if tt == t - 1 and i == len(ops) - 1:
			break
		print('\n')


from collections import Counter
from sys import stdin, stdout
import math
from collections import defaultdict
from typing import DefaultDict
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	x = list(map(int, stdin.readline().split()))
	y = x.copy()
	y.sort()
	if y == x:
		print(0)
	else:
		ans = 0
		l = []
		for i in range(n):
			if x[i] == y[i]:
				pass
			else:
				for j in range(len(x[i:])):
					if x[i:][j] == y[i]:
						l.append([i + 1, i + j + 1, j])
						x = x[0:i] + x[i + j:i + j + 1] + x[i:i + j] + x[i + j + 1:]
						ans += 1
						break
		print(ans)
		for i in l:
			print(*i)


import math
from collections import Counter, defaultdict
import sys
mod = 10 ** 9 + 7
input = sys.stdin.readline
readInt = lambda : int(input().strip())
readfloat = lambda : float(input().strip())
readStr = lambda : input().strip()
intList = lambda : list(map(int, input().strip().split()))
intMap = lambda : map(int, input().strip().split())
floatList = lambda : list(map(float, input().strip().split()))
floatMap = lambda : map(float, input().strip().split())
strList = lambda : list(input().strip().split())

def print(*args, end='\n', sep=' '):
	for i in args:
		sys.stdout.write(str(i))
		sys.stdout.write(sep)
	sys.stdout.write(end)

def get_index(arr, val):
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == val:
			return i

def solve():
	brr = sorted(arr)
	res = []
	for i in range(n):
		if arr[i] != brr[i]:
			idx = get_index(arr, brr[i])
			d = idx - i
			temp = arr[i:]
			for j in range(i, n):
				arr[j] = temp[(j - i + d) % len(temp)]
			res.append([i + 1, n, d])
	print(len(res))
	for i in res:
		print(*i)
for _ in range(readInt()):
	n = readInt()
	arr = intList()
	solve()


def rotateArray(arr, n, d):
	temp = []
	i = 0
	while i < d:
		temp.append(arr[i])
		i = i + 1
	i = 0
	while d < n:
		arr[i] = arr[d]
		i = i + 1
		d = d + 1
	arr[:] = arr[:i] + temp
	return arr
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = l.copy()
	x.sort()
	ans = 0
	a = []
	for i in range(n):
		if l[i] == x[i]:
			continue
		else:
			r = i + l[i:].index(x[i])
			if r == i:
				continue
			a.append([i + 1, r + 1, r - i])
			temp = rotateArray(l[i:r + 1], len(l[i:r + 1]), r - i)
			for j in range(len(temp)):
				l[i + j] = temp[j]
			ans += 1
	print(ans)
	for i in a:
		print(i[0], i[1], i[2])


def rolling(s, n):
	l = len(s)
	return s[n % l:] + s[:n % l]
import sys
input = lambda : sys.stdin.readline().rstrip()

def solve():
	N = int(input())
	A = list(map(int, input().split()))
	ans = []
	for i in range(N):
		minA = min(A[i:])
		for j in range(i + 1, N):
			if A[j] == minA:
				A[i:j + 1] = rolling(A[i:j + 1], j - i)
				ans.append((i + 1, j + 1, j - i))
				break
	print(len(ans))
	for a in ans:
		print(*a)
Q = int(input())
for _ in range(Q):
	solve()


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
yy = lambda : print('YES')
nn = lambda : print('NO')
from math import log10, log2, ceil, factorial as fac, gcd, inf, sqrt, log
from bisect import bisect_right as br, bisect_left as bl, insort
from collections import Counter
mod = 10 ** 9 + 7

def Nprime(n):
	if n == 2 or n == 3:
		return 0
	if n == 1:
		return 1
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 1
		i += 1
	return 0

def g():
	(n, m, k) = ll()
	a = []
	vis = []
	fl = 0
	for i in range(n):
		p = list(ss())
		a.append(p)
		vis.append([0] * m)
	for i in range(n):
		for j in range(m):
			if a[i][j] == '*' and vis[i][j] == 0:
				for k in range(j + 1, m):
					if a[i][k] == '*':
						(x, y) = (j, k)
						p = i
						c = 0
						while x < y and p < n:
							if a[p][x] == a[p][y] == '*':
								p -= 1
								x += 1
								y -= 1
								c += 1
							else:
								fl = 1
								break
						if x - 1 != y + 1 or c < k:
							fl = 1
				vis[i][j] = 1
			if fl:
				break
		if fl:
			break
	if fl:
		nn()
for _ in range(t()):
	n = t()
	a = list(ll())
	l = []
	for i in range(1, n):
		if a[i] < a[i - 1]:
			pos = 0
			while pos < i + 1 and a[i] > a[pos]:
				pos += 1
			l.append((pos + 1, i + 1, i - pos))
			a = a[:pos] + [a[i]] + a[pos:i] + a[i + 1:]
	print(len(l))
	for i in l:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	c = []
	for i in range(n):
		if a[i] != b[i]:
			j = a.index(b[i], i)
			c.append((i + 1, j + 1, j - i))
			a[i:j + 1] = [a[j]] + a[i:j]
	print(len(c))
	for v in c:
		print(*v)


from collections import Counter, defaultdict
from sys import stdin, stdout
import io, os, sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def listinput():
	return [int(i) for i in input().split()]

def intinput():
	return int(input())

def rotate(l, r):
	ar = arr[l:r + 1] + []
	ar.append(ar.pop(0))
	for i in range(l, r + 1):
		arr[i] = ar[i - l]

def hihi():
	for i in range(n - 1, -1, -1):
		for j in range(i, -1, -1):
			if arr[j] == arrc[i]:
				if i != j:
					ans.append((j + 1, i + 1, 1))
					rotate(j, i)
					break
testtest = intinput()
for test in range(testtest):
	n = intinput()
	arr = listinput()
	arrc = sorted(arr)
	ans = []
	hihi()
	print(len(ans))
	for i in ans:
		print(*i)


t = int(input())
while t:
	n = int(input())
	w = list(map(int, input().split()))
	r = w.copy()
	r.sort()
	r.reverse()
	cnt = 0
	ansL = []
	ansR = []
	for num in r:
		if n < 0:
			break
		l = w.index(num)
		r = n - 1
		n -= 1
		if l == r:
			continue
		c = w[r]
		w[r] = w[l]
		cnt += 1
		ansL.append(l + 1)
		ansR.append(r + 1)
		while r > l:
			r -= 1
			cambio = w[r]
			w[r] = c
			c = cambio
	print(cnt)
	for i in range(len(ansL)):
		print(str(ansL[i]) + ' ' + str(ansR[i]) + ' 1')
	t -= 1


import sys
import os.path
from collections import *
import math
import bisect
import heapq as hq
from fractions import Fraction
from random import randint
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline

def rotateArray(arr, n, d):
	temp = []
	i = 0
	while i < d:
		temp.append(arr[i])
		i = i + 1
	i = 0
	while d < n:
		arr[i] = arr[d]
		i = i + 1
		d = d + 1
	arr[:] = arr[:i] + temp
	return arr

def solve():
	n = int(input())
	res = []
	arr = [int(x) for x in input().split()]
	brr = arr.copy()
	brr.sort()
	for i in range(n):
		x = arr[i:].index(brr[i])
		if x == 0:
			continue
		else:
			res.append((i + 1, i + x + 1, x))
			arr[i:i + x + 1] = rotateArray(arr[i:i + x + 1], x + 1, x)
	print(len(res))
	for i in res:
		for j in i:
			print(j, end=' ')
		print()
t = int(input())
while t:
	t -= 1
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sorted(arr)
	cnt = 0
	lst = []
	for i in range(n):
		if arr[i] == s[i]:
			continue
		for j in range(i + 1, n):
			if arr[j] == s[i]:
				cnt += 1
				lst.append([i + 1, j + 1, j - i])
				for k in range(j, i, -1):
					arr[k] = arr[k - 1]
				arr[i] = s[i]
				break
	print(cnt)
	for i in lst:
		print(*i)


import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
from sys import stdin, stdout
sys.setrecursionlimit(10 ** 5)

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def mp():
	return map(int, inp().split())

def lmp():
	return list(mp())
t = iinp()
for i in range(t):
	n = iinp()
	a = lmp()
	b = sorted(a)
	ans = []
	for i in range(n):
		if a[0] != b[i]:
			j = a.index(b[i])
			ans.append([i + 1, j + i + 1, j])
			a.pop(j)
		else:
			a.pop(0)
	print(len(ans))
	for (i, j, k) in ans:
		print(i, j, k)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter, defaultdict
import math
import heapq
import bisect

def nck(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr == sorted(arr):
		print(0)
	else:
		ls = sorted(arr)
		o = []
		for i in range(n):
			if ls[i] == arr[i]:
				continue
			else:
				ind = 0
				for j in range(i + 1, n):
					if arr[j] == ls[i]:
						ind = j
						break
				o.append([i + 1, ind + 1, ind - i])
				var = arr[i]
				arr[i] = arr[ind]
				for j in range(i + 1, ind + 1):
					tt = arr[j]
					arr[j] = var
					var = tt
		print(len(o))
		for i in o:
			print(*i)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [(i, x) for (i, x) in enumerate(a)]
	a = sorted(a, key=lambda x: x[1])
	a = [(x[0], str(x[0]) + str(x[1])) for x in a]
	d = {}
	for i in range(n):
		d[a[i][1]] = a[i][0]
	queue = []
	for i in range(n):
		queue.append(a[i][1])
	ops = []
	for i in range(n):
		pos = d[queue[i]]
		old_pos = pos
		k = 0
		while pos != i:
			k += 1
			if pos == i:
				pos = n - 1
			else:
				pos -= 1
			for j in range(i + 1, n):
				old_pos = d[queue[j]]
				if old_pos == i:
					new_pos = n - 1
				else:
					new_pos = old_pos - 1
				d[queue[j]] = new_pos
		if k == 0:
			continue
		ops.append(f'{i + 1} {n} {k}')
	print(len(ops))
	print('\n'.join(ops))


TESTS = int(input())
for _ in range(TESTS):
	size = int(input())
	arr = list(map(int, input().split()))
	fullarr = []
	op = []
	l = 0
	while l < size:
		r = arr.index(min(arr))
		if r > 0:
			d = r
			op.append(f'{l + 1} {r + l + 1} {d}')
		fullarr.append(arr.pop(r))
		l += 1
	print(len(op))
	for s in op:
		print(s)


def rotateList(a, d, n):
	a = a[d:n] + a[0:d]
	return a
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	a1 = list()
	a2 = list()
	count = 0
	l = len(a)
	for j in range(l - 1):
		minn = a.index(min(a))
		a = rotateList(a, minn, len(a))
		if minn != 0:
			count += 1
			a1.append(j + 1)
			a2.append(minn)
		a = a[1:]
	print(count)
	for i in range(count):
		print(a1[i], l, a2[i])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(1, n):
		for j in range(i):
			if l[j] > l[i]:
				l1.append(str(j + 1) + ' ' + str(i + 1) + ' ' + str(i - j))
				l = l[:j] + [l[i]] + l[j:i] + l[i + 1:]
				break
	print(len(l1))
	for i in l1:
		print(i)


n = int(input())
mass = []
for _ in range(n):
	k = 0
	l = 1
	r = 1
	d = 0
	t = int(input())
	q = t
	mass = list(map(int, input().split()))
	mass1 = []
	for _ in range(t):
		if mass.index(max(mass)) != q - 1 and min(mass) != max(mass):
			l = mass.index(max(mass)) + 1
			r = q
			d = 1
			mass1.append([l, r, d])
			k += 1
		mass.pop(mass.index(max(mass)))
		q -= 1
	print(k)
	for i in mass1:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	ans = []
	for i in range(n):
		mn_i = a[i:].index(min(a[i:])) + i
		if mn_i == i:
			continue
		if mn_i < i:
			break
		ans.append((i + 1, mn_i + 1, mn_i - i))
		a[i:mn_i + 1] = [a[mn_i]] + a[i:mn_i]
	print(len(ans))
	for el in ans:
		print(*el)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = sorted(a)
	c = 0
	e = [None] * (n + 1)
	k = 0
	v = 0
	for i in range(n):
		if a[i] != b[i]:
			j = a[i:].index(b[i]) + i
			v = a.pop(j)
			a.insert(i, v)
			c += 1
			e[k] = [i + 1, j + 1, j - i]
			k += 1
		pass
	print(c)
	for i in range(c):
		print(*e[i])


def solve(arr, n):
	soln = []
	for i in range(1, n):
		key = arr[i]
		r = i + 1
		l = 0
		d = 0
		j = i - 1
		while j >= 0 and key < arr[j]:
			arr[j + 1] = arr[j]
			j -= 1
			d += 1
		l = j + 2
		arr[j + 1] = key
		if d >= 1:
			soln.append([l, r, d])
	print(len(soln))
	for i in soln:
		print(f'{i[0]} {i[1]} {i[2]}')
for i in [0] * int(input()):
	n = int(input())
	nlist = list(map(int, input().split()))
	solve(nlist, n)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	store = []
	for i in range(n):
		mini = min(arr[i:])
		indx = -1
		pos = -1
		for j in range(i, n):
			if arr[j] == mini:
				indx = j
				pos = j
				break
		temp = arr[indx]
		for k in range(pos, i, -1):
			arr[k] = arr[k - 1]
		arr[i] = temp
		if indx > i:
			store.append([i, indx, indx - i])
	l = len(store)
	print(l)
	for i in range(l):
		print(store[i][0] + 1, store[i][1] + 1, store[i][2])


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(a)
	k = []
	b.sort()
	c = 0
	for i in range(n - 1):
		if a[i] != b[i]:
			c += 1
			v = a.index(b[i], i)
			d = v - i
			k.append([i + 1, v + 1, d])
			a = a[:i] + a[v:v + 1] + a[i:v] + a[v + 1:]
	print(c)
	for i in k:
		print(*i)


for _t in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = []
	for i in range(n):
		for j in range(i + 1):
			if a[j] >= a[i]:
				break
		if j < i:
			a[j:i + 1] = [a[i]] + a[j:i]
			b.append((j + 1, i + 1, i - j))
	print(len(b))
	for (l, r, d) in b:
		print(l, r, d)


test = int(input())

def returner(lol):
	c = 0
	a = []
	while len(lol) > 1:
		m = max(lol)
		if lol.index(m) != len(lol) - 1:
			a.append([lol.index(m) + 1, len(lol), 1])
			c += 1
		del lol[lol.index(m)]
	return (c, a)
for i in range(test):
	n = int(input())
	lol = list(map(int, input().split()))
	(c, a) = returner(lol)
	print(c)
	for i in a:
		print(*i)


t = int(input())
ans_mas = []
for i in range(t):
	help_mas = []
	n = int(input())
	b = input().split()
	a = list(map(int, b))
	l = 0
	h = n - 1
	while True:
		if h == 0:
			break
		max_a = max(a[0:h + 1])
		max_a_index = a[0:h + 1].index(max_a)
		if max_a_index == h:
			h -= 1
		else:
			y = a[h]
			a[h] = a[max_a_index]
			for j in reversed(range(max_a_index, h)):
				(a[j], y) = (y, a[j])
			help_mas.append(str(str(max_a_index + 1) + ' ' + str(h + 1) + ' ' + '1'))
			l += 1
			h -= 1
	ans_mas.append(l)
	if len(help_mas) != 0:
		for j in range(len(help_mas)):
			ans_mas.append(help_mas[j])
print(*ans_mas, sep='\n')


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		arr = get_list()
		actual = sorted(arr)
		ans = 0
		data = []
		for i in range(n):
			if arr[i] != actual[i]:
				s = i
				e = i
				while e < n and arr[e] != actual[i]:
					e += 1
				ans += 1
				data.append([s + 1, e + 1, e - s])
				arr[s:e + 1] = [arr[e]] + arr[s:e]
		if ans == 0:
			get_print_int(ans)
		else:
			get_print_int(ans)
			for i in data:
				get_print('{} {} {}'.format(i[0], i[1], i[2]))
solve()


n = int(input())
for i in range(n):
	length = int(input())
	data = list(map(int, input().split()))
	test = sorted(data)
	ans = []
	i = 0
	while data != test:
		if test[i] == data[i]:
			i += 1
			continue
		index = data.index(test[i], i)
		data.pop(index)
		data.insert(i, test[i])
		i += 1
		ans.append((i, index + 1, index + 1 - i))
	print(len(ans))
	if len(ans) == 0:
		print()
	for j in ans:
		print(j[0], j[1], j[2])


import os, sys
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)]
inp_enu = lambda dtype: [(i, x) for (i, x) in enumerate(inp(dtype))]
inp_enus = lambda dtype, n: [[i] + inp(dtype) for i in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
for _ in range(int(input())):
	(n, a, ans) = (int(input()), inp(int), [])
	sor = sorted(a)
	for i in range(n):
		if a[i] != sor[i]:
			for j in range(i + 1, n):
				if a[j] == sor[i]:
					ans.append(f'{i + 1} {j + 1} {j - i}')
					a[i:j + 1] = a[j:j + 1] + a[i:j]
					break
	print(len(ans))
	print(*ans, sep='\n')


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	list_print_2 = []
	length = int(stdin.readline())
	cnt = 0
	string = list(map(int, stdin.readline().split()))
	index = 1
	for i in range(length):
		a = min(string)
		x = string.index(a)
		if x != 0:
			list_print_2.append(str(0 + index) + ' ' + str(x + index) + ' ' + str(x) + '\n')
			cnt += 1
		string.remove(a)
		index += 1
	stdout.write(str(cnt) + '\n')
	for k in range(len(list_print_2)):
		stdout.write(list_print_2[k])


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	i = 0
	ans = []
	while a != sorted(a):
		m = min(a[i:])
		w = a[i:].index(m)
		if w:
			ans.append((i, i + w, w))
		del a[i + w]
		a.insert(i, m)
		i += 1
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1, i[2], sep=' ')


from collections import deque
for _ in range(int(input())):
	n = int(input())
	numbers = deque(list(map(int, input().split())))
	answer = []
	for i in range(n - 1):
		elem = min(numbers)
		j = 0
		if numbers[0] == elem:
			numbers.popleft()
			continue
		while numbers[0] != elem:
			x = numbers.popleft()
			numbers.append(x)
			j += 1
		numbers.popleft()
		answer.append([i + 1, n, j])
	print(len(answer))
	for a in answer:
		print(*a)


def insertionSort(array):
	ans = 0
	a = []
	for i in range(1, len(array)):
		key = array[i]
		j = i - 1
		while array[j] > key and j >= 0:
			array[j + 1] = array[j]
			j -= 1
		array[j + 1] = key
		if j + 2 != i + 1:
			ans += 1
			a.append(j + 2)
			a.append(i + 1)
			a.append(i + 1 - j - 2)
	print('\r', ans, sep='')
	for i in range(0, len(a), 3):
		if i + 3 == len(a):
			print(a[i], a[i + 1], a[i + 2], end='')
		else:
			print(a[i], a[i + 1], a[i + 2])
	return ''
n = int(input())
for i in range(n):
	k = int(input())
	a = list(map(int, input().split()))
	print(insertionSort(a))


for i in range(int(input())):
	n = int(input())
	(*l,) = map(int, input().split())
	so = sorted(l)
	amount = 0
	if l == so:
		print(amount)
	else:
		steps = []
		while l != so:
			ind = 0
			ind_2 = 0
			for i in range(n):
				if l[i] != so[i]:
					ind = i
					for j in range(i, n):
						if l[j] == so[i]:
							ind_2 = j
							break
					break
			amount += 1
			steps.append([ind + 1, ind_2 + 1, ind_2 - ind])
			l = l[:ind] + l[ind_2:ind_2 + 1] + l[ind:ind_2] + l[ind_2 + 1:]
		print(amount)
		for i in range(amount):
			print(*steps[i])


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	ss = sorted(s)
	turns = 0
	ans = []
	for i in range(0, n):
		if s[i] != ss[i]:
			turns += 1
			a = n - s[::-1].index(ss[i]) - 1
			ans += [[i + 1, a + 1, a - i]]
			s[i:a + 1] = [s[a]] + s[i:a]
	print(turns)
	for i in ans:
		print(*i)


n = int(input())
for i in range(n):
	a = int(input())
	list_a = list(map(int, input().split()))
	u = 0
	list_of_moves = []
	while u < a:
		if list_a.index(min(list_a)) == u:
			list_a[u] = 10 ** 10
			u += 1
		else:
			l = u
			r = list_a.index(min(list_a))
			lst = list_a[l:r + 1]
			for j in range(len(lst)):
				del list_a[l]
			ret = [0] * len(lst)
			k = len(lst) - 1
			for j in range(len(lst)):
				if j + k < len(lst) and j + k >= 0:
					ret[j] = lst[j + k]
				if j + k >= len(lst):
					ret[j] = lst[j + k - len(lst)]
				if j + k < 0:
					ret[j] = lst[j + k + len(lst)]
			new_l = l
			for j in range(len(ret)):
				list_a.insert(l, ret[j])
				l += 1
			list_a[u] = 10 ** 10
			u += 1
			list_of_moves.append([new_l + 1, r + 1, r - new_l])
	print(len(list_of_moves))
	for weq in range(len(list_of_moves)):
		print(' '.join(map(str, list_of_moves[weq])))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	c = 0
	ans = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		c += 1
		j = a.index(b[i], i)
		ans.append(i + 1)
		ans.append(j + 1)
		x = a[j]
		for z in range(j, i, -1):
			(a[z], a[z - 1]) = (a[z - 1], a[z])
	print(c)
	for d in range(0, len(ans) - 1, 2):
		print(ans[d], ans[d + 1], ans[d + 1] - ans[d])


def solve():
	t = int(input())
	for i in range(t):
		n = int(input())
		m = [int(s) for s in input().split()]
		res = []
		r = n
		for l in range(n - 1):
			d = m.index(min(m))
			m = m[d + 1:] + m[:d]
			if d != 0:
				res.append((l + 1, r, d))
		print(len(res))
		for x in res:
			print(' '.join((str(s) for s in x)))
solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = []
	c = 0
	for j in range(n):
		m = min(a)
		b = a.index(m)
		del a[b]
		l = j + 1
		r = b + j + 1
		if l != r:
			c = c + 1
			x.append([l, r, r - l])
	print(c)
	for k in x:
		print(*k)


tc = int(input())
for _ in range(tc):
	ans = []
	ansn = 0
	n = int(input())
	array = list(map(int, input().split()))
	for i in range(n):
		small = i
		for k in range(i, n):
			if array[k] <= array[small]:
				small = k
		if small > i:
			d = small - i
			end = array[small]
			for m in range(small, i, -1):
				array[m] = array[m - 1]
			array[i] = end
			ansn += 1
			ans.append([i + 1, small + 1, d])
	print(ansn)
	for j in range(ansn):
		print(*ans[j], sep=' ')


def solution(a):
	temp_ans = []
	for i in range(len(a) - 1):
		min_i = i
		min_v = a[i]
		for j in range(i + 1, len(a)):
			if a[j] < min_v:
				min_v = a[j]
				min_i = j
		if min_i - i == 0:
			continue
		else:
			a = a[:i] + [min_v] + a[i:min_i] + a[min_i + 1:]
			temp_ans.append(f'{i + 1} {min_i + 1} {min_i - i}')
	print(len(temp_ans))
	for i in temp_ans:
		print(i)
t = int(input())
data = []
for i in range(t):
	n = int(input())
	temp = list(map(int, input().split()))
	data.append(temp)
for temp in data:
	solution(temp)


n = int(input())
for i in range(0, n):
	y = int(input())
	o = input().rstrip().split(' ')
	x = list(o)
	x.sort(key=int, reverse=True)
	I = 0
	Q = []
	W = []
	count = y
	while I < len(x):
		A = int(x[I])
		I += 1
		for j in range(0, len(o)):
			if int(o[j]) == A:
				G = j
				break
		if G + 1 == count:
			count -= 1
			continue
		D = []
		D.append(G + 1)
		D.append(count)
		count -= 1
		D.append(1)
		Q.append(D)
		E = o[0:G]
		F = o[G:count + 1]
		H = o[count + 1:]
		T = F[0:1]
		Y = F[1:]
		F = Y + T
		o = E + F + H
		o = list(o)
	print(len(Q))
	for j in range(0, len(Q)):
		print(*Q[j])


from math import ceil, gcd
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import array
from collections import Counter as ctr

def li():
	return list(map(int, input().split()))

def arr(a):
	return array('i', a)

def cn(n):
	return (3 * n * n + 7 * n + 4) // 2

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = li()
		b = sorted(a)
		c = n - 1
		ans = []
		for i in range(n - 1):
			l = a.index(b[-(i + 1)])
			if l + 1 == n - i:
				c -= 1
				continue
			a = a[:l] + a[l + 1:n - i] + [a[l]] + a[n - i:]
			ans.append([l + 1, n - i, 1])
		print(c)
		for i in range(len(ans)):
			print(*ans[i])
solve()