#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<char> ans;
int anchorT = -1;
vector<pair<int,int>> need_fix;
vector<int> make_query(int L, int R) {
vector<int> vc;
int len = R - L + 1;
for (int j = 0; j < len; j++) {
for (int h = 0; h < (1 << j); h++) vc.pb(L + j);
}
return query_machine(vc);
}
void solve_leaf(int L, int R) {
int len = R - L + 1;
vector<int> p = make_query(L, R);
int msk = p.back();
int full = (1 << len) - 1;
if (msk != full) {
for (int j = 0; j < len; j++) {
if (msk & (1 << j)) {
ans[L + j] = 'T';
if (anchorT == -1) anchorT = L + j;
} else {
ans[L + j] = 'R';
}
}
} else {
need_fix.pb({L, R});
}
}
void fix_uniform_blocks() {
if (need_fix.empty()) return;
if (anchorT == -1) {
// You still need one toxic sample from somewhere else
// to resolve all-uniform blocks.
return;
}
for (auto [L, R] : need_fix) {
vector<int> vc;
vc.pb(anchorT);
for (int i = L; i <= R; i++) vc.pb(i);
vector<int> p = query_machine(vc);
if (p.back() == 1) {
for (int i = L; i <= R; i++) ans[i] = 'R';
} else {
for (int i = L; i <= R; i++) ans[i] = 'T';
}
}
}
void build(int L, int R, int lvl) {
if (L > R) return;
int len = R - L + 1;
if (len <= 8) {
solve_leaf(L, R);
return;
}
int parts;
if (lvl == 0) parts = 8;
else if (lvl == 1) parts = 8;
else parts = 2;
int sz = (len + parts - 1) / parts;
for (int i = 0; i < parts; i++) {
int x = L + i * sz;
int y = min(R, x + sz - 1);
if (x <= y) build(x, y, lvl + 1);
}
}
void determine_type(int n) {
ans.assign(n, 'R');
need_fix.clear();
anchorT = -1;
build(0, n - 1, 0);
fix_uniform_blocks();
answer_type(ans);
}