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

void generate_derangement(int N)
{
	int s[N + 1];
	priority_queue<int, vector<int>, greater<int> > PQ;
	for (int i = 1; i <= N; i++) {
		s[i] = i;
		PQ.push(s[i]);
	}
	int D[N + 1];
	for (int i = 1; i <= N; i++) {
		int d = PQ.top();
		PQ.pop();
		if (d != s[i] || i == N) {
			D[i] = d;
		}
		else {
			D[i] = PQ.top();
			PQ.pop();
			PQ.push(d);
		}
	}

	if (D[N] == s[N])
	swap(D[N-1], D[N]);
	for (int i = 1; i <= N; i++)
		printf("%d ", D[i]);
}

// Driver code
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n;
	cin>>n;
	generate_derangement(n);
	cout<<endl;
	}
	return 0;
}