#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
vector<int> solve(vector<int> P) {
    int N = P.size();
    for (auto &p : P) p--;
    vector<int> ans;
    int pos = 0;
    auto op = [&](int n) {
        assert(ans.size() % 2 == n % 2);
        ans.push_back(n);
        swap(P[n], P[n + 1]);
        if (pos == n) pos++;
        else if (pos == n + 1) pos--;
    };
    for (int t = N - 1; t >= 3; t--) {
        pos = find(begin(P), end(P), t) - begin(P);
        if (pos == t) {
            continue;
        }
        while (pos != t && pos % 2 != ans.size() % 2) {
            if (ans.size() % 2 == 0) {
                if (pos == 1) {
                    op(2);
                } else {
                    op(0);
                }
            } else {
                if (t >= 4 && pos == 2) {
                    op(3);
                } else {
                    op(1);
                }
            }
        }
        while (pos != t) {
            op(pos);
        }
    }
    while (!is_sorted(begin(P), end(P))) {
        op(ans.size() % 2);
    }
    for (auto &a : ans) a++;
    return ans;
}
int main() {
    int T; cin >> T;
    while (T--) {
        int N; cin >> N;
        vector<int> P(N); for (auto &p : P) cin >> p;
        auto ans = solve(P);
        cout << ans.size() << '\n';
        for (auto a : ans) cout << a << ' ';
        cout << '\n';
    }
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;

const int N=4e5+5;

int s[N],t,n;

struct node {
	int x,id;
	inline bool operator < (const node &a) const {return x!=a.x?x<a.x:id<a.id;}
}a[N];

bool tp[N];

int main() {
	scanf("%d",&n);
	for(int i=1,x ; i<=2*n ; ++i) scanf("%d",&x),a[i].x=x,a[i].id=i;
	sort(a+1,a+2*n+1);
	for(int i=n+1 ; i<=2*n ; ++i) tp[a[i].id]=1;
	for(int i=1 ; i<=2*n ; ++i) {
		if(!t) printf("("),s[++t]=i;
		else if(tp[s[t]]!=tp[i]) printf(")"),--t;
		else printf("("),s[++t]=i;
	}
	return 0;
}