#include #include #include using namespace std; void solve() { int n; cin >> n; vector p(n, -1); for (int i = 1; i < n; ++i) { cout << 1 << ' ' << 1 << ' ' << i + 1 << endl; int k; cin >> k; --k; if (k >= 0) p[k] = i; } int cnt = 0; for (int i = 0; i < n; ++i) if (p[i] == -1) ++cnt; auto cal = [&](vector &a) -> int { vector check = a; for (int i = 0; i < n; ++i) { if (a[i] < 0) continue; else if (a[a[i]] == -1) check[a[i]] = a[i]; } int tmp = 0, cp = 0; for (int i = 0; i < n; ++i) { cp += (a[i] == -1); tmp += (check[i] == -1); } if (cp != (n + 1) / 2) return n - cp - (cp < (n + 1) / 2); else return (tmp == 2 ? n / 2 : (n + 1) / 2); }; auto calp = [&](int id, int c) -> void { vector to(n, -1); for (int i = 0; i < n; ++i) if (p[i] != -1) to[p[i]] = i; int tid = -1, mi = n + 1; for (int i = 0; i < n; ++i) { if (i != id && p[i] == -1) { int now = i, tmp = 0; while (now != -1) { now = to[now]; ++tmp; } if (tmp < mi) { mi = tmp; tid = i; } } } if (c * 2 <= n) p[tid] = id; }; vector ans(n, -1); if (cnt == n) { p.assign(n, -1); vector>> g(n); int id1 = 1, id2 = 1; for (int i = 2; i < n; ++i) { cout << 1 << ' ' << id1 + 1 << ' ' << i + 1 << endl; int k; cin >> k; if (k == 1) id2 = i; --k; if (k >= 0) p[k] = i; } cnt = cal(p); calp(id1, cnt); for (int i = 0; i < n; ++i) { if (p[i] != -1) { g[p[i]].push_back({i, cnt}); g[i].push_back({p[i], -cnt}); } } p.assign(n, -1); for (int i = 1; i < n; ++i) { if (i == id2) continue; cout << 1 << ' ' << id2 + 1 << ' ' << i + 1 << endl; int k; cin >> k; --k; if (k >= 0) p[k] = i; } cnt = cal(p); calp(id2, cnt); for (int i = 0; i < n; ++i) { if (p[i] != -1) { g[p[i]].push_back({i, cnt}); g[i].push_back({p[i], -cnt}); } } auto dfs = [&](auto f, int now) -> void { for (auto [to, c] : g[now]) { if (ans[to] == -1) { ans[to] = ans[now] + c; f(f, to); } } }; ans[0] = n; dfs(dfs, 0); } else { int bs = 0; cnt = cal(p); calp(bs, cnt); vector id; if (cnt <= 2) { for (int i = 0; i < n; ++i) if (p[i] == -1) id.push_back(i); vector to(n, -1); for (int i = 0; i < n; ++i) if (p[i] != -1) to[p[i]] = i; if (id.size() == 1) { int now = id[0], v = 1; while (now != -1) { ans[now] = v; now = to[now]; ++v; } } else if (id.size() == 2) { int now = id[0], tmp = 0; while (now != -1) { now = to[now]; ++tmp; } if (tmp == n / 2) swap(id[0], id[1]); now = id[0]; int v = 1; while (now != -1) { ans[now] = v; v += 2; now = to[now]; } now = id[1], v = 2; while (now != -1) { ans[now] = v; v += 2; now = to[now]; } } } else { for (int i = 1; i < n; ++i) if (p[i] == -1) id.push_back(i); while (id.size() > 1) { bs = id[0]; for (auto v : id) { if (v == bs) continue; cout << 1 << ' ' << bs + 1 << ' ' << v + 1 << endl; int k; cin >> k; if (k == -1) continue; p[k - 1] = v; } vector nid; for (auto v : id) { if (v == bs) continue; if (p[v] != -1 && p[p[v]] == -1 && p[v] != bs) nid.push_back(p[v]); } swap(nid, id); } p.assign(n, -1); for (int i = 0; i < n; ++i) { if (i == bs) continue; cout << 1 << ' ' << bs + 1 << ' ' << i + 1 << endl; int k; cin >> k; if (k < 0) continue; p[k - 1] = i; } cnt = cal(p); calp(bs, cnt); vector to(n, -1); for (int i = 0; i < n; ++i) if (p[i] != -1) to[p[i]] = i; int tmp = 0; id.clear(); for (int i = 0; i < n; ++i) if (p[i] == -1) id.push_back(i); if (id.size() == 1) { int now = id[0], v = 1; while (now != -1) { ans[now] = v; now = to[now]; ++v; } } else { int now = id[0], tmp = 0; while (now != -1) { now = to[now]; ++tmp; } if (tmp == n / 2) swap(id[0], id[1]); now = id[0]; int v = 1; while (now != -1) { ans[now] = v; v += 2; now = to[now]; } now = id[1], v = 2; while (now != -1) { ans[now] = v; v += 2; now = to[now]; } } } } cout << 2 << ' '; for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n - 1]; } int main() { int t; cin >> t; while (t--) solve(); }