#include #include using namespace std; using namespace atcoder; //const long nPrime = 1000000007; //const long nPrime = 998244353; typedef long long ll; void Swap(long i, vector &viNum, vector &viAns){ viAns.push_back(i+1); swap(viNum[i], viNum[i+1]); } int main() { long t; cin >> t; while(t--){ long n; cin >> n; vector viNum(n), viInv(n); for(long i = 0; i < n; i++){ cin >> viNum[i]; } long nSum = 0; for(long i = 0; i < n; i++){ if(viNum[i] == i+1 && nSum != i*(i+1)/2){ cout << -1 << endl; break; } nSum += viNum[i]; } vector viAns; viAns.resize(n*n); for(long i = 0; i < n; i++){ vector viSum(n,0); long nTmp = 0; for(long j = 0; j < n; j++){ nTmp += viNum[j]; viSum[j] = nTmp; } long k = i; while(viNum[k] != i+1){ k++; } while(k > i){ long m = k-1; while(viNum[m] == m+2 && viSum[m]+i+1 != (m+2)*(m+3)/2){ m--; } for(; m < k-1; m++){ Swap(m,viNum,viAns); } Swap(k-1,viNum,viAns); } } cout << viAns.size() << endl; for(long i = 0; i < viAns.size(); i++){ cout << viAns[i] << " "; } cout << endl; } return 0; }