#include #include #include using namespace std; typedef long long LL; LL M[25], R[25]; bool vis[25]; LL extEuclid(LL a, LL b, LL &x, LL &y) { if (!b) { x = 1, y = 0; return a; } LL d, tmp; d = extEuclid(b, a % b, x, y); x = y % b; y = (d - a * x) / b; return d; } LL MLE(LL a, LL b, LL n) { a = (a % n + n) % n, b = (b % n + n) % n; LL x, y, g = extEuclid(a, n, x, y); if (b % g) return -1; return ((x % n + n) % n * (b / g)) % n; } LL lcm(LL a, LL b) { return a * b / __gcd(a, b); } LL CRT(LL r[], LL w[], int len) { LL ret = r[0], ww = w[0]; for (int i = 1; i < len; i ++) { LL x = MLE(ww, r[i] - ret, w[i]); if (x == -1) return -1; ret = x * ww + ret; ww = lcm(ww, w[i]); ret %= ww; } return (ww + ret % ww) % ww; } int a[25]; int main() { int T, n; for (scanf("%d", &T); T --; ) { scanf("%d", &n); int prv = 0, nxt; memset(vis, 0, sizeof vis); LL LCM = 1; bool bf = 0; for (int i = 1; i <= n; i ++) { int x; scanf("%d", &x); a[x] = i; } for (int i = n; i; i --) { nxt = a[n + 1 - i]; if (nxt < 1 || n < nxt || vis[nxt]) bf = 1; if (bf) continue; int a = 0; if (prv < nxt) { for (int j = prv + 1; j <= nxt; j ++) { if (!vis[j]) a ++; } } else { for (int j = prv + 1; j <= n; j ++) { if (!vis[j]) a ++; } for (int j = 1; j <= nxt; j ++) { if (!vis[j]) a ++; } } M[i - 1] = i, R[i - 1] = a % i; vis[nxt] = 1, prv = nxt; LCM = lcm(LCM, i); } if (bf) puts("Creation August is a SB!"); else { LL rlt = CRT(R, M, n); if (rlt < 0) puts("Creation August is a SB!"); else if (!rlt) printf("%I64d\n", LCM); else printf("%I64d\n", rlt); } } return 0; }