勿急
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define PII pair<int, int>
using namespace std;
const int N = 1010;
vector<PII> ans;
int n, T, t, w[N], tmp[N];
void swap(int* A, int l1,int r1, int l2, int r2){
memcpy(tmp, w, sizeof(int) * (n + 5));
int idx = l1;
for(int i = l2;i <= r2;i++) w[idx++] = tmp[i];
for(int i = l1;i <= r1;i++) w[idx++] = tmp[i];
}
int fx(int x){
if(x > n) x-= n;
if(x < 1) x+= n;
return x;
}
void solve(){
cin >> n >> t; ans.clear();
for(int i = 1;i <= n;i++) cin >> w[i];
if(n == 1){cout << 0;return;}
bool isOK = false; int idx = -1;
for(int st = 1;st <= n;st++){
bool f = true;
for(int j = st + 1;j <= st + n - 1;j++){
int nw = fx(j);
int pr = fx(j-1);
if(w[nw] < w[pr]){f = false; break;}
}
if(f){isOK = true; idx = st; break;}
}
if(t == 1) cout << ((isOK && idx == 1) ? 0 : -2);
else if(t == 2){
if(not isOK) cout << -2;
else{
if(idx == 1) cout << 0;
else{
cout << "1
2
0 " << idx - 1 << " " << n << "
2 1";
}
}
}else{
for(int i = 1;i < n;i++){
int mn = INT_MAX; int idx = -1;
for(int j = i;j <= n;j++){
if(w[j] <= mn){
mn = w[j];
idx = j;
}
}
if(idx == i)continue;
swap(w, i, idx - 1,idx, n);
ans.push_back({i - 1, idx - 1});
}
if(ans.empty()){ cout << 0;return;}
cout << ans.size() << '
';
for(int i = 0;i < ans.size();i++){
auto& p = ans[i];
if(p.first == 0) cout << "2
0 " << p.second << " " << n << "
2 1";
else cout << "3
0 " << p.first << " " << p.second << " " << n << "
1 3 2";
if(i + 1 < ans.size()) cout << '
';
}
}
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0);
cin >> T;
while(T--){
solve();
if(T) cout << '
';
}
}