#include <cstdio>
#include <cctype>
using namespace std;

const int max_n = 200000;
int a[max_n], wa[max_n], ps[max_n], wa_cnt = 0;
bool us[max_n] = {};

#define gc getchar
inline int read()
{
	int c = gc(), t = 1, n = 0;
	while (isspace(c)) { c = gc(); }
	if (c == '-') { t = -1, c = gc(); }
	while (isdigit(c)) { n = n * 10 + c - '0', c = gc(); }
	return n * t;
}
#undef gc

int main()
{
	int n;

	n = read();
	for (int i = 0; i < n; i++)
	{
		a[i] = read() - 1;
		ps[a[i]] = i;
	}

	for (int i = 0; i < n; i++)
	{
		if (ps[i] == i)
			continue;
		
		for (int j = ps[i] - 1; j >= i; j--)
		{
			ps[a[j]]++, a[j+1] = a[j];
			wa[wa_cnt++] = j + 1;
			if (us[j] || wa_cnt >= n)
			{
				puts("-1");
				return 0;
			}
			us[j] = true;
		}

		a[i] = ps[i] = i;

		/*
		for (int i = 0; i < n; i++)
			fprintf(stderr, "%d ", a[i]);
		putc('\n', stderr);
		*/
	}

	if (wa_cnt != n - 1)
	{
		puts("-1");
	//	fprintf(stderr, "%d\n", wa_cnt);
		return 0;
	}

	for (int i = 0; i < wa_cnt; i++)
		printf("%d\n", wa[i]);

	return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
int N,P[500];
vector<int> ans;
void f(int a){
  ans.push_back(a);
  swap(P[a],P[a+1]);
}
signed main(){
  int T; cin>>T;
  while(T--){
    cin>>N;
    for(int i=0;i<N;i++) cin>>P[i],P[i]--;
    ans.clear();
    for(int i=0;i<N-2;i++){
      int d=i;
      for(;P[d]!=i;d++);
      if(d==i)continue;
      if(d%2==ans.size()%2){
        if(d-i>=2){
          if(i%2==ans.size()%2) f(i);
          else f(i+1);
        }
        else if(N-d>2){
          f(d);
          f(d+1);
          f(d);
          d+=2;
        }
        else{
          f(d);
          f(d-1);
          d++;
        }
      }
      for(int j=d-1;j>=i;j--) f(j);
    }
    if(P[N-2]!=N-2){
      if(ans.size()%2==N%2)f(N-2);
      else{
        f(N-3);
        f(N-2);
        f(N-3);
        f(N-2);
        f(N-3);
      }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      cout<<ans[i]+1;
      if(i+1!=ans.size())cout<<' ';
    }
    cout<<endl;
    assert(ans.size()<=N*N);
  }
}