#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<ll , VLL , greater<ll>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    ll N;  cin >> N;
  	PQG pq;
    for(ll i = 1 ; i*i <= N ; i++)
      if(N % i == 0){  
        pq.push(i);
        if(i*i != N)
        pq.push(N / i);  
      }

  	while(!pq.empty()){
      cout << pq.top() << endl;
      pq.pop();
    }
  
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define yes "YES\n"
#define no "NO\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

vector<int>v,pos;
vector<int>ans;
int n;

void perform_operation(int id)
{
    //cout<<id<<endl;
    assert(id>0);
    assert(id<n);
    int select_odd = ans.size()%2;
    select_odd = 1 - select_odd;
    assert(id%2 == select_odd);

    swap(v[id], v[id+1]);
    pos[v[id]] = id;
    pos[v[id+1]] = id+1;
    ans.pb(id);

    //for(int i=1;i<=n;i++)cout<<v[i]<<" ";
    //cout<<endl;
   // for(int i=1;i<=n;i++)cout<<pos[i]<<" ";
   // cout<<endl;
}


void solve(int test)
{

    cin>>n;
    int i,j;

    v.resize(n+3),pos.resize(n+3);
    ans.clear();

    for(i=1;i<=n;i++)
    {
        cin>>v[i];

        pos[v[i]] = i;
    }

    for(int k=1;k<=n;k++){
    for(i=1;i<=n-1;i++)
    {
        if(pos[i] == i)
        {
            continue;
        }
        else
        {
            int select_odd = 1-(ans.size()%2);
            if(select_odd == 1)
            {
                if(pos[i]%2==1)
                {
                    int x1,x2;
                    if((n-1)%2==1)x1 = n-1;
                    else
                        x1 = n-2;
                    if(i%2==1)x2 = i;
                    else
                        x2 = i+1;
                    if(pos[i] != x2 + 1 && pos[i] != x2)
                        perform_operation(x2);
                    else if(pos[i] != x1 + 1 && pos[i] != x1)
                        perform_operation(x1);
                    else
                    {
                        assert(x2 != i);
                        perform_operation(x2);
                        perform_operation(x2-1);
                    }
                }

                while(pos[i] != i)
                {
                    assert(pos[i] > i);
                    perform_operation(pos[i]-1);
                }
            }
            else
            {
                if(pos[i]%2==0)
                {
                    int x1,x2;
                    if((n-1)%2==0)x1 = n-1;
                    else
                        x1 = n-2;
                    if(i%2==0)x2 = i;
                    else
                        x2 = i+1;

                    if(pos[i] != x2 + 1 && pos[i] != x2)
                        perform_operation(x2);
                    else if(pos[i] != x1 + 1 && pos[i] != x1)
                        perform_operation(x1);
                    else
                    {
                        assert(x2!=i);
                        perform_operation(x2);
                        perform_operation(x2-1);
                    }
                }

                while(pos[i] != i)
                {
                    //cout<<pos[i]<<" "<<i<<endl;
                    assert(pos[i] > i);
                    perform_operation(pos[i]-1);
                }
            }
        }
        assert(pos[i] == i);
    }
    }

    for(i=1;i<=n;i++)
    {
        assert(v[i] == i);
    }

    assert(n*n >= ans.size());
    cout<<ans.size()<<endl;
    for(auto a:ans)
    {
        cout<<a<<" ";
    }
    cout<<endl;


    return;

}

int main()
{
  //fast;
  int t = 1;
  cin>>t;

  for(int x=1;x<=t;x++)
  {
      solve(x);
  }

  return 0;
}
