#define N 200007 int a[N]; bool vis[N]; inlinevoidwork(){ int n = rd(); for (int i = 1; i <= n; ++i) {vis[i] = false; a[i] = rd();} int ans = 0; for (int i = 1, l = 1, r = n; l < r; ++i) { while (vis[a[l]]) ++l; while (vis[a[r]]) --r; if (l >= r) break; if (a[l] != i || a[r] != n - i + 1) ans = i; vis[i] = vis[n - i + 1] = true; } printf("%d\n", ans); }
inline T rd(){ T x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
int n, m, tot;
structnode { int son[10]; voidclear(){for (int i = 0; i < 10; ++i) son[i] = 0;} } c[1000007];
inlinevoidinsert(vector<int> &s){ // build trie int rt = 0; for (int j = 0; j < m; ++j) { if (!c[rt].son[s[j]]) c[rt].son[s[j]] = ++tot; rt = c[rt].son[s[j]]; } }
inlineintsearch(vector<int> &s){ // find the max depth s could reach int rt = 0; for (int j = 0; j < m; ++j) { if (!c[rt].son[s[j]]) return j; rt = c[rt].son[s[j]]; } return m; }
vector<int> a[50007], rev;
inlinevoidwork(){ n = rd(); m = rd(); rev.resize(m); for (int i = 0; i < n; ++i) { a[i].clear(); for (int j = 0; j < m; ++j) { int x = rd() - 1; rev[x] = j; a[i].push_back(x); } insert(rev); } for (int i = 0; i < n; ++i) printf("%d ", search(a[i])); puts(""); for (int i = 0; i <= tot; ++i) c[i].clear(); tot = 0; }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inline T rd(){ T x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 5007
vector<int> d, fac; // fac : prime factors of nw
vector<pii> s; // prime factors of m1m2
unordered_map<ll, ll> mx; // maximum divisor <= n
int n, tot, ans;
voiddfs(ll nw, int step){ if (step == s.size()) return; dfs(nw, step + 1); auto [p, t] = s[step]; fac.push_back(p); for (; t; --t) { nw *= p; for (auto x : fac) { ll y = mx[nw / x]; mx[nw] = max(mx[nw], (y * x <= n ? y * x : y)); } if (nw / mx[nw] <= n) {++tot; ans ^= nw / mx[nw];} elsebreak; dfs(nw, step + 1); } fac.pop_back(); }
inlinevoidwork(){ n = rd(); mx.clear(); d.clear(); s.clear(); mx[1] = 1; tot = ans = 1;
auto getd = [&](int x) { int lim = sqrt(x); for (int i = 2; i <= lim && i <= x; ++i) while (x % i == 0) {d.pb(i); x /= i;} if (x > 1) d.pb(x); }; getd(rd()); getd(rd()); sort(all(d));
int lst = 0, cnt = 0; for (auto x : d) if (x != lst) { if (lst) s.eb(lst, cnt); lst = x; cnt = 1; } else ++cnt; s.eb(lst, cnt);
dfs(1, 0); printf("%d %d\n", tot, ans); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }