// author: xay5421
// created: Sat May 29 20:25:20 2021
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
//#define NDEBUG
#endif
#include<bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=505;
int T,n,a[N];
bool ok(){
	rep(i,1,n)if(a[i]!=i)return 0;
	return 1;
}
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	scanf("%d",&T);
	rep(_,1,T){
		D("_=%d\n",_);
		scanf("%d",&n);
		rep(i,1,n)scanf("%d",&a[i]);
		vector<int>ans;
		while(1){
			if(ok())break;
			bool flg=0;
			for(int i=(n-1)&1?n-1:n-2;i>=1;i-=2){
				if(a[i]>a[i+1]){
					swap(a[i],a[i+1]),ans.push_back(i);
					flg=1;
					break;
				}
			}
			if(flg==0){
				swap(a[1],a[2]),ans.push_back(1);
			}
			if(ok())break;
			flg=0;
			for(int i=2;i<n;i+=2){
				if(a[i]>a[i+1]){
					swap(a[i],a[i+1]),ans.push_back(i);
					flg=1;
					break;
				}
			}
			if(flg==0){
				swap(a[2],a[3]),ans.push_back(2);
			}
		}
		printf("%d\n",SZ(ans));
		for(int x:ans)printf("%d ",x);
		puts("");
	}
	return 0;
}
#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

void solve0(int n){
  rep(i,n){
    print(2*i+1,2*i+2);
  }
}

void solve1(int n,int m){
  if(m+2>n){
    print(-1);
    return;
  }
  li p=n-m+1;
  print(2,p);
  rep(i,n-m-2){
    print(p-(i+1),p+(i+1));
  }
  li q=p+((n-m-3)+1)+1;
  rep(i,m-1){
    print(q+2*i,q+2*i+1);
  }
  li r=2*(m-2)+q+1+1;
  print(r,r+2);
  print(1,r+1);
}

void solve2(int n,int m){
  m*=-1;
  if(m+2>n){
    print(-1);
    return;
  }
  print(-1);
}

int main(){
  int n,m; cin >>n >>m;
  if(m==0) solve0(n);
  if(m>0) solve1(n,m);
  if(m<0) solve2(n,m);
}
