#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X) < 0 ? -(X) : (X))
#define LCM(X, Y) (((X) / (GCD((X), (Y)))) * (Y))
#define MEM(A, B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL) fill(V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A, I) cout << "at pos " << I << "  value is: " << A[I]
#define TURBO                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
using namespace std;
inline ll GCD(ll A, ll B)
{
    if (B == 0)
        return A;
    return GCD((B), (A % B));
}
inline ll POW(ll BASE, ll EXP)
{
    ll RES = 1;
    for (ll I = 0; I < EXP; I++)
        RES *= BASE;
    return RES;
}
inline ll BIGMOD(ll a, ll p, ll m)
{
    ll res = 1 % m;
    ll x = a % m;
    while (p > 0)
    {
        if ((p & 1) > 0)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
inline void FILE_HANDLE()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    TURBO;
    //FILE_HANDLE() ;
    ll n;
    scanf("%lld", &n);
    vector<ll> v;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                v.PB(i);

            else
            {
                v.PB(i);
                v.PB(n / i);
            }
        }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
        printf("%lld\n", v[i]);
}
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int T,n,i,j,k,l;
int a[501];
int d[250001],tot;
bool bz;

void add(int x)
{
	swap(a[x],a[x+1]);
	d[++tot]=x;
	bz^=1;
}

void Checker()
{
	int i;
	fo(i,1,n) if (a[i]!=i) exit(1);
	if (tot>n*n) exit(2);
	fo(i,1,tot) if ((d[i]&1)!=(i&1)) exit(3);
}

int main()
{
	#ifdef file
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
	#endif
	
	scanf("%d",&T);
	for (;T;--T)
	{
		scanf("%d",&n);tot=0;bz=1;
		fo(i,1,n) scanf("%d",&a[i]);
		
		if (n==2)
		{
			if (a[1]>a[2])
			add(1);
		}
		else
		{
			fd(i,n,4)
			if (a[i]>a[i+1])
			{
				if ((i&1)!=bz)
				{
					if (bz) add(1);
					else add(2);
				}
				fo(j,i,n-1) if (a[j]>a[j+1]) add(j); else break;
			}
			if (bz==1)
			{
				fo(j,3,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			else
			{
				add(2);
				fo(j,3,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			
			if (bz)
			{
				fo(j,1,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			else
			{
				fo(j,2,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			if (a[1]!=1 || a[2]!=2)
			{
				if (bz==1)
				{
					add(1);
					fo(j,2,n-1)
					if (a[j]>a[j+1]) add(j); else break;
				}
				else
				{
					fo(j,2,n-1)
					if (a[j]>a[j+1]) add(j); else break;
				}
				
				if (a[1]!=1)
				{
					if (a[1]!=2)
					{
						if (bz==1)
						{
							fo(j,1,n-1)
							if (a[j]>a[j+1]) add(j); else break;
						}
						else
						{
							add(2);
							fo(j,1,n-1)
							if (a[j]>a[j+1]) add(j); else break;
						}
					}
					
					if (a[1]>a[2])
					{
						if (bz) add(1);
						else add(2),add(1),add(2),add(1),add(2);
					}
				}
			}
		}
		
		Checker();
		printf("%d\n",tot);
		fo(i,1,tot) printf("%d ",d[i]);
		printf("\n");
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}