#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int((x).size())) #define bit(x) (1 << (x)) #define cnt1(x) (__builtin_popcount(x)) template inline void chkmax(T& x, T y) { if (x < y) x = y; } template inline void chkmin(T& x, T y) { if (y < x) x = y; } typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; const int MX = 20005; const int M = 1000000007; const int LIM = 400000; char s[MX]; int n; LL pw[MX]; LL lft[MX], rgt[MX]; int odd[MX], even[MX], tot; int ca[MX], cb[MX], T; int a[MX], an; int b[MX], bn; void init() { pw[0] = 1; for (int i = 1; i < MX; i++) pw[i] = pw[i - 1] * 26 % M; } bool test(int st, int en) { int k = en - st + 1; return (lft[en] - rgt[st] - (lft[st - 1] - rgt[en + 1]) * pw[k]) % M == 0; } inline int rnd() { #ifdef _WIN32 return (rand() << 15) + rand(); #else return rand() / 2; #endif } inline int rnd(int m) { return rnd() % m; } bool check() { int i, j, k, tr, mx; if (an * bn < LIM) { for (i = 0; i < an; i++) { for (j = 0; j < bn; j++) { if (a[i] + 1 < b[j] && test(a[i] + 1, b[j] - 1)) return 1; } } return 0; } tot = 0; for (i = 1; i <= n; i++) tot += odd[i] + even[i]; if (tot < LIM) { for (i = 1; i <= n; i++) { for (j = odd[i]; j > 0; j--) { if (ca[i - j] == T && cb[i + j] == T) return 1; } for (j = even[i]; j > 0; j--) { if (ca[i - j] == T && cb[i + j + 1] == T) return 1; } } return 0; } tr = LIM / n; for (i = 1; i <= n; i++) { if (odd[i]) { for (k = 0; k < tr; k++) { j = rnd(odd[i]) + 1; if (ca[i - j] == T && cb[i + j] == T) return 1; } } if (even[i]) { for (k = 0; k < tr; k++) { j = rnd(even[i]) + 1; if (ca[i - j] == T && cb[i + j + 1] == T) return 1; } } } mx = an * bn; for (k = 0; k < LIM; k++) { tr = rnd(mx); i = tr / bn, j = tr % bn; if (a[i] + 1 < b[j] && test(a[i] + 1, b[j] - 1)) return 1; } return 0; } int main() { int tc, i, st, en, md; init(); for (scanf("%d", &tc); tc--; ) { scanf("%s", s + 1); n = strlen(s + 1); lft[0] = 0; for (i = 1; i <= n; i++) lft[i] = (lft[i - 1] * 26 + (s[i] - 'a')) % M; rgt[n + 1] = 0; for (i = n; i > 0; i--) rgt[i] = (rgt[i + 1] * 26 + (s[i] - 'a')) % M; for (i = 1; i <= n; i++) { st = 1, en = min(i, n - i + 1) + 1; while (st + 1 < en) { md = (st + en) / 2; if (test(i - md + 1, i + md - 1)) st = md; else en = md; } odd[i] = st; st = 0, en = min(i, n - i) + 1; while (st + 1 < en) { md = (st + en) / 2; if (test(i - md + 1, i + md)) st = md; else en = md; } even[i] = st; } T++; an = bn = 0; for (i = 1; i <= n; i++) { if (test(1, i)) { ca[i] = T; a[an++] = i; } if (test(i, n)) { cb[i] = T; b[bn++] = i; } } puts(check() ? "Yes" : "No"); } return 0; }