#include <bits/stdc++.h>

using namespace std;
const int N = 505;
int T, n, cnt, a[N], op[N * N];
int s[10][4] = {
	{},
	{0, 1, 2, 3},
	{0, 1, 3, 2},
	{0, 3, 1, 2},
	{0, 3, 2, 1},
	{0, 2, 3, 1},
	{0, 2, 1, 3},
	{0, 1, 2, 3}
};
int to[10] = {0, 2, 1, 2, 1, 2, 1};

void out() {
	cout << cnt << '\n';
	for(int i = 1; i <= cnt; i++) {
		cout << op[i] << ' ';
	}
	cout << '\n';
}

void move(int x) {
	int pos = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] == x) {
			pos = i;
			break;
		}
	}
	while(pos != x) {
//		cout << pos << ' ' << cnt << '\n';
		if(pos % 2 == (cnt + 1) % 2) {
			swap(a[pos], a[pos + 1]);
			op[++cnt] = pos;
			++pos;
		} else {
			if(pos >= x - 2) {
				op[++cnt] = pos - 1;
				op[++cnt] = pos;
				op[++cnt] = pos - 1;
				op[++cnt] = pos;
				op[++cnt] = pos - 1;
				swap(a[pos], a[pos + 1]);
				++pos;
			} else {
				op[++cnt] = pos + 1;
				swap(a[pos + 2], a[pos + 1]);
			}
		}
	}
}

bool eq(int x) {
	for(int i = 1; i <= 3; i++) {
		if(a[i] != s[x][i]) return false;
	}
	return true;
}

void work() {
	if(n == 2) {
		if(a[1] == 2) op[cnt = 1] = 1;
		out();
	} else {
		for(int i = n; i >= 4; i--) {
			move(i);
		}
		for(int i = 1; i <= 7; i++) {
			if(eq(i)) {
				if(i == 1 || i == 7) break;
				if((cnt + 1) % 2 == to[i] % 2)
					for(int j = i; j < 7; j++) op[++cnt] = to[j];	
				else 
					for(int j = i - 1; j >= 1; j--) op[++cnt] = to[j];
				break;
			}
		}
		out();
	}
}

int main() {
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	#ifdef ONLINE_JUDGE
	ios::sync_with_stdio(false); cin.tie(0);
	#endif
	cin >> T;
	while(T--) {
		cnt = 0;
		cin >> n;
		for(int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		work();
	}
	
	return 0;
}
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vector<int> >

const ll mod = 1000000007;
const int INF = 1001001001;

struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

int main(){
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    mint ans;
    ans = a[0] + 1;
    rep(i, n-1){
        ans *= a[i+1] - a[i] + 1;
    }
    cout << ans << endl;
}