#include<bits/stdc++.h>
using namespace std;

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int, int> > vii;
typedef   vector<long long> vl;
typedef   pair<int, int> pii;
typedef   pair<ll, ll> pll;
typedef   vector< pair<ll, ll> > vll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto dist = uniform_int_distribution<int>(l, r);
// int dx[] = {1, 0, -1, 0};
// int dy[] = {0, 1, 0, -1};
// int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1};
// int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0};


void omae_wa_mou_shindeiru(int tc) {
	ll n;
	cin >> n;
	vl p(n + 1), f(n), ans;
	fi(1, n + 1) {
		ll temp;
		cin >> temp;
		p[i] = temp;
	}
	vl temp = p;
	sort(temp.begin(), temp.end());
	set<int>odd, even;
	fi(1, n) {
		if (p[i] > p[i + 1]) {
			if (i % 2)
				odd.insert(i);
			else
				even.insert(i);
		}
	}

	fi(1, n * n + 1) {
		if (p == temp) {
			break;
		}
		if (i % 2) {
			int kk;
			if (odd.size() == 0) {
				kk = n - 1 - (n % 2);
			}
			else {
				kk = *odd.begin();
				odd.erase(odd.begin());
			}
			swap(p[kk], p[kk + 1]);
			ans.push_back(kk);
			if (even.find(kk + 1) != even.end()) {
				even.erase(kk + 1);
			}
			if (even.find(kk - 1) != even.end()) {
				even.erase(kk - 1);
			}
			if (kk + 2 <= n) {
				if (p[kk + 1] > p[kk + 2]) {
					even.insert(kk + 1);
				}
			}
			if (kk - 1 >= 1) {
				if (p[kk - 1] > p[kk]) even.insert(kk - 1);
			}
		}
		else {
			int kk;
			if (even.size() == 0) {
				kk = n - 1 - (n + 1) % 2;
			}
			else {
				kk = *even.begin();
				even.erase(even.begin());
			}
			swap(p[kk], p[kk + 1]);
			ans.push_back(kk);
			if (odd.find(kk + 1) != odd.end()) {
				odd.erase(kk + 1);
			}
			if (odd.find(kk - 1) != odd.end()) {
				odd.erase(kk - 1);
			}
			if (kk + 2 <= n) {
				if (p[kk + 1] > p[kk + 2]) odd.insert(kk + 1);
			}
			if (kk - 1 >= 1) {
				if (p[kk - 1] > p[kk]) odd.insert(kk - 1);
			}
		}
		// pr(p);
	}
	cout << ans.size() << endl;
	pr(ans);

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tc = 1;
	cin >> tc;
	fi(1, tc + 1) {
		omae_wa_mou_shindeiru(i);
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 998244353   

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ll gcd(ll x,ll y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}

bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

void swap(int &x,int &y){
    int temp = x;
    x = y;
    y = temp;
}
  
unsigned int onesComplement(unsigned int n) 
{ 
   // Find number of bits in the given integer 
   int number_of_bits = floor(log2(n))+1; 
  
   // XOR the given integer with poe(2,  
   // number_of_bits-1 and print the result  
   return ((1 << number_of_bits) - 1) ^ n; 
}

bool comp1(pair<int,int> x, pair<int,int> y)
{
    return x.second < y.second;
}

// class cmp      //comrootator for priority_queue 
// {               //declaration: priority_queue<int,vector<int>,cmp>
// public:         
//     bool operator()(E& A,E& B)
//     {
//         // if(A.first == B.first)
//         //     return A.second < B.second;
//         return A.wt > B.wt;
//     }
// };


void solve(){   
    int n;
    cin >> n;
    vector<int> p(n + 1);
    for(int i = 1; i <= n; ++i)
        cin >> p[i];
    int par = 1;
    vector<int> moves;
    while(true) {
        bool f = true;
        bool f2 = false;
        for(int i = 1; i <= n - 1; ++i) {
            if(p[i] > p[i + 1]) {
                f = false;
                if(i % 2 == par) {
                    f2 = true;
                    swap(p[i], p[i + 1]); 
                    moves.push_back(i);
                    par ^= 1;
                    break;
                }
            }
        }

        if(f)
            break;
        if(f2)
            continue;
        for(int i = n - 1; i >= 1; --i) {
            if(p[i]  < p[i + 1] and i % 2 == par) {
                moves.push_back(i);
                swap(p[i], p[i + 1]);
                par ^= 1;
                break;
            }
        }
   
    }

    cout << moves.size() << '\n';
    for(int x: moves)
        cout << x << ' ';
    cout << '\n';
}   

int main()                   
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    // solve();
  
}   