#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int>> adj;
vector<bool> visited;
vector<int> path;
// Depth-first search to build the path
bool dfs(int pos) {
if (pos == N) return true;
int last = path[pos-1];
for (int v : adj[last]) {
if (!visited[v]) {
visited[v] = true;
path[pos] = v;
if (dfs(pos+1)) return true;
visited[v] = false;
}
}
return false;
}
// Find one valid “beautiful” permutation for 1..N or return empty on failure
vector<int> find_beautiful_permutation(int N) {
adj.assign(N+1, {});
// build graph: edge u–v if gcd(u,v)==1 and |u−v|>1
for (int u = 1; u <= N; ++u) {
for (int v = u+1; v <= N; ++v) {
if (abs(u - v) > 1 && __gcd(u, v) == 1) {
adj[u].push_back(v);
adj[v].push_back(u);
}
}
}
// sort neighbors by ascending degree to help prune early
for (int u = 1; u <= N; ++u) {
sort(adj[u].begin(), adj[u].end(),
[&](int a, int b){ return adj[a].size() < adj[b].size(); });
}
visited.assign(N+1, false);
path.assign(N, 0);
// try every possible start
for (int start = 1; start <= N; ++start) {
visited[start] = true;
path[0] = start;
if (dfs(1)) {
return path;
}
visited[start] = false;
}
return {}; // no solution
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
cin >> N;
// impossible small cases
if (N==2 || N==3 || N==4 || N==6) {
cout << -1 << "\n";
continue;
}
auto sol = find_beautiful_permutation(N);
if (sol.empty()) {
cout << -1 << "\n";
} else {
for (int x : sol) {
cout << x << " ";
}
cout << "\n";
}
}
return 0;
}