# B. Shifting Sort

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The new generation external memory contains an array of integers $a\left[1\dots n\right]=\left[{a}_{1},{a}_{2},\dots ,{a}_{n}\right]$.

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:

1. You may select arbitrary indices $l$ and $r$ ($1\le l) as the boundaries of the segment.
2. Then you replace the segment $a\left[l\dots r\right]$ 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 $\left[1,4,1,3\right]$ is a cyclic shift of the sequence $\left[3,1,4,1\right]$ to the left by the offset $1$ and the sequence $\left[4,1,3,1\right]$ is a cyclic shift of the sequence $\left[3,1,4,1\right]$ to the left by the offset $2$.

For example, if $a=\left[1,3,2,8,5\right]$, then choosing $l=2$$r=4$ and $d=2$ yields a segment $a\left[2\dots 4\right]=\left[3,2,8\right]$. This segment is then shifted by the offset $d=2$ to the left, and you get a segment $\left[8,3,2\right]$ which then takes the place of of the original elements of the segment. In the end you get $a=\left[1,8,3,2,5\right]$.

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\le t\le 1000$) — the number of test cases.

The next  lines contain the descriptions of the test cases.

The first line of each test case description contains an integer $n$ ($2\le n\le 50$) — the length of the array. The second line consists of space-separated elements of the array ${a}_{i}$ ($-{10}^{9}\le {a}_{i}\le {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) 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.

Example
input
Copy
4
2
2 1
3
1 2 1
4
2 4 1 3
5
2 5 1 4 3

output
Copy
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:

1. The segment $a\left[2\dots 4\right]$ is selected and is shifted to the left by $2$$\left[2,5,1,4,3\right]⟶\left[2,4,5,1,3\right]$
2. The segment $a\left[1\dots 5\right]$ is then selected and is shifted to the left by $3$$\left[2,4,5,1,3\right]⟶\left[1,3,2,4,5\right]$
3. After that the segment $a\left[1\dots 2\right]$ is selected and is shifted to the left by $1$$\left[1,3,2,4,5\right]⟶\left[3,1,2,4,5\right]$
4. And in the end the segment $a\left[1\dots 3\right]$ is selected and is shifted to the left by $1$

#### The solution to the Above Problem is

We can simply find the largest number in the subproblems starting from the last index and see if it is in the correct position, if not then we will take a subarray starting from that index to the index where it should be and then simply rotate the array to left by 1.

#include <bits/stdc++.h>

using namespace std;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.<< " " << x.<< endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
int x = 1;
while (b)
{
if (& 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
const char* comma = strchr (names + 1, ',');
cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;

void solve() {
int n;
cin>>n;
vi v(n);
vector<vector<int>>ans;
for(int i=0; i<n; i++)
cin>>v[i];
for(int i=0; i<n; i++){
int itr=max_element(v.begin(),v.end())-v.begin();
// bug(itr);
if(itr!=n-i-1) {ans.push_back({itr+1,n-i,1});}
v.erase(v.begin()+itr);
}
cout<<ans.size()<<endl;
for(auto it:ans)
cout<<it[0]<<" "<<it[1]<<" "<<it[2]<<endl;

}

int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

clock_t z = clock();

int t = 1;
cin >> t;
while (t--) solve();

//   cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

return 0;
}

Thank You For Reading.