#include #include #include #include #include using namespace std; const int MAXN = 100000 + 100; const bool IS_DEBUG = false; int result[MAXN], a[MAXN], n; int totalQuestions1, totalQuestions2; char response[10]; bool query (int t, int x, int y, int z = 0) { if (!IS_DEBUG) { if (t == 1) { printf("%d %d %d %d\n", t, x, y, z); fflush(stdout); scanf("%s", response); fflush(stdout); } else { printf("%d %d %d\n", t, x, y); fflush(stdout); scanf("%s", response); fflush(stdout); } return (response[0] == 'Y'); } else { if (t == 1) { ++totalQuestions1; return (abs(a[x] - a[y]) % z == 0); } else if (t == 2) { ++totalQuestions2; return (a[x] < a[y]); } } return false; } void solve (vector allInd, int depth) { if (allInd.size() == 1) { result[allInd[0]] = 0; } else { vector p1, p2; p1.push_back(allInd[0]); for(int i = 1; i < allInd.size(); i++) if ((1 << depth) < n && query(1, allInd[0], allInd[i], 1 << depth)) p1.push_back(allInd[i]); else p2.push_back(allInd[i]); solve(p1, depth + 1); solve(p2, depth + 1); for(int i = 0; i < allInd.size(); i++) result[allInd[i]] *= 2; if (p1.size() != p2.size()) { if (p1.size() > p2.size()) p1.swap(p2); for(int i = 0; i < p1.size(); i++) ++result[p1[i]]; } else { int pos1, pos2; for(int i = 0; i < p1.size(); i++) if (result[p1[i]] == 0) { pos1 = p1[i]; break; } for(int i = 0; i < p2.size(); i++) if (result[p2[i]] == 0) { pos2 = p2[i]; break; } if (query(2, pos1, pos2)) p1.swap(p2); for(int i = 0; i < p1.size(); i++) ++result[p1[i]]; } } } int main(int argc, const char * argv[]) { int testCases; int total = 0; if (!IS_DEBUG) { scanf("%d", &testCases); fflush(stdout); } else { testCases = 1000000; } while (testCases--) { if (!IS_DEBUG) { scanf("%d", &n); fflush(stdout); } else { totalQuestions1 = 0; totalQuestions2 = 0; n = rand() % 10000 + 1; for(int i = 1; i <= n; i++) a[i] = i; for(int i = 1; i <= n; i++) { int j = rand() % n + 1; swap(a[i], a[j]); } } vector allInd; allInd.clear(); for(int i = 1; i <= n; i++) allInd.push_back(i); for(int i = 1; i <= n; i++) result[i] = 0; solve(allInd, 1); if (!IS_DEBUG) { printf("%d", 3); for(int i = 1; i <= n; i++) printf(" %d", result[i] + 1); printf("\n"); fflush(stdout); } else { ++total; if (total % 1000 == 0) cerr << "total " << total << endl; for(int i = 1; i <= n; i++) assert(result[i] + 1 == a[i]); if (!(totalQuestions2 < n)) { cout << n << endl; return 0; } } } return 0; }