intf() { int cnt = 0; for (int i = 0; i < n - 1; ++i) { if (b[i] != b[i + 1] - 1) cnt ++; }
return (cnt + 2) / 3; }
boolcheck() { for (int i = 0; i < n - 1; ++i) { if (b[i] != b[i + 1] - 1) returnfalse; } returntrue; }
booldfs(int u, int max_step) { if (u + f() > max_step) returnfalse; if (check()) returntrue;
for (int len = 1; len <= n; ++len) { for (int l = 0; l + len - 1 < n; ++l) { int r = l + len - 1; for (int k = r + 1; k < n; ++k) { memcpy(w[u], b, sizeof w[u]); int x, y; for (x = r + 1, y = l; x <= k; x ++, y ++) b[y] = w[u][x]; for (x = l; x <= r; x ++, y ++) b[y] = w[u][x]; if (dfs(u + 1, max_step)) returntrue; memcpy(b, w[u], sizeof w[u]); } } }
returnfalse; }
intmain() { cin >> c; while(c --) { cin >> n; for (int i = 0; i < n; ++i) cin >> b[i];