#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; typedef long double LD; #define pb push_back #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define counti(x) (__builtin_popcount(x)) #define countl(x) (__builtin_popcountll(x)) #define rep(i, n) for (int (i) = 0; (i) < (int)(n); ++(i)) #define X first #define Y second template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } int get() { char c; while (c = getchar(), (c < '0' || c > '9') && (c != '-')); bool flag = (c == '-'); if (flag) c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - 48; c = getchar(); } return flag ? -x : x; } void output(int x) { if (x < 0) { putchar('-'); x = -x; } int len = 0, data[20]; while (x) { data[len++] = x % 10; x /= 10; } if (!len) data[len++] = 0; while (len--) putchar(data[len] + 48); putchar('\n'); } #define MXLEN 105 // 구하려는 씨수의 자리수 #define MN 8 // 긴 옹근수안의 한개옹근수의 길이 #define BIGLEN MXLEN*5 / 8 // 긴옹근수안의 옹근수 개수 #define MX 1000005 #define MOD 100000000 #define BG BIG_INTEGER using namespace std; typedef long long LL; const char inputString[] = " ,.?abcdefghijklmnopqrstuvwxyz"; const int AT = strlen(inputString); char s[MX]; // plaintext int count_number(LL k); int MAX(int a, int b) { if (a < b) return b; return a; } int val(char c) { return strchr(inputString, c) - inputString; } char re_val(int k) { return inputString[k]; } struct BIG_INTEGER{ int n; int D; LL a[BIGLEN]; void init() { n = 1; D = 0; a[0] = 0; } void input() { scanf("%s", s); int i, j, len; D = 0; n = 0; len = strlen(s); for (i = len - 1; i >= 0; i--) { if (s[i] == '.') { D = len - 1 - i; for (j = i; j < len - 1; j++) s[j] = s[j + 1]; len--; break; } } s[len] = 0; for (i = len - 1; i >= 0; i -= MN) { a[n] = 0; for (j = MAX(i - MN + 1, 0); j <= i; j ++) a[n] = a[n] * 10 + s[j] - '0'; n++; } pop(); } void print() { int i, j, k; for (i = n - 1; i >= 0; i --) { if (i == n - 1) { printf("%I64d", a[i]); continue; } k = count_number(a[i]); for (j = 0; j < MN - k; j ++) cout << "0"; printf("%I64d", a[i]); } puts(""); } void Reverse() { reverse(a, a + n); } void push_head() { while (a[n - 1] >= MOD) { a[n] = a[n - 1] / MOD; a[n - 1] %= MOD; n ++; } } void push_all() { LL mod(0), i, sum; for (i = 0; i < n; i ++) { sum = mod + a[i]; a[i] = sum % MOD; mod = sum / MOD; } if (mod) { a[n ++] = mod; push_head(); } } void pop() { while (n && !a[n - 1]) n --; if (!n) n = 1; } void remove() { rep(i, n) { if (a[i] >= 0) continue; a[i] = MOD + a[i]; a[i + 1] --; } } void valueof(LL k) { init(); a[0] = k; push_head(); } int count() {return (n - 1) * MN + count_number(a[n - 1]);} LL convert() { LL res = 0; rep(i, n) res = res * MOD + a[n - 1 - i]; return res; } BG operator + (const BG &A) const { BG res; res.n = MAX(A.n, n); rep(i, res.n) { res.a[i] = 0; if (i < n) res.a[i] += a[i]; if (i < A.n) res.a[i] += A.a[i]; } res.push_all(); return res; } BG operator * (const BG &A) const { BG res; res.n = A.n + n - 1; int i; for (i = 0; i < res.n; i ++) res.a[i] = 0; for (i = 0; i < n; i ++) rep(j, A.n) res.a[i + j] += a[i] * A.a[j]; res.push_all(); res.pop(); return res; } BG operator - (const BG &A) const { BG res; res.n = n; int i; for (i = 0; i < n; i ++) res.a[i] = a[i]; for (i = 0; i < A.n; i ++) res.a[i] -= A.a[i]; res.remove(); res.push_all(); res.pop(); return res; } bool operator == (const BG &A) const { if (n != A.n) return 0; rep(i, n) if (a[i] != A.a[i]) return 0; return 1; } bool operator != (const BG &A) const { if (n != A.n) return 1; rep(i, n) if (a[i] != A.a[i]) return 1; return 0; } bool operator < (const BG &A) const { if (n != A.n) return n < A.n; for (int i = n - 1; i >= 0; i --) if (a[i] != A.a[i]) return a[i] < A.a[i]; return 0; } void divide(LL k) { LL mod(0); for (int i = n - 1; i >= 0; i --) { a[i] = mod*MOD + a[i]; mod = a[i] % k; a[i] /= k; } pop(); } void copy(const BG &A) { n = A.n; rep(i, n) a[i] = A.a[i]; } int mod_integer(int p) { if (p == 5) return a[0] % 5; LL mod(0), sum; int i; for (i = n - 1; i >= 0; i --) { sum = a[i] + mod*MOD; mod = sum % p; } return mod; } void multiply(int k) { LL mod(0); rep(i, n) { a[i] = a[i] * k + mod; mod = a[i] / MOD; a[i] %= MOD; } if (mod) { a[n ++] = mod; push_head(); } } BG Multiply(int k) { LL mod(0); BG res; res.n = n; rep(i, n) { res.a[i] = a[i] * k + mod; mod = res.a[i] / MOD; res.a[i] %= MOD; } if (mod) { res.a[res.n ++] = mod; res.push_head(); } return res; } void add(LL k) { a[0] += k; push_all(); } BG Get_mod(BG &A) { BG res, cur, B; res.n = 0; cur.init(); int i; LL st, en, mid; for (i = n - 1; i >= 0; i --) { cur.multiply(MOD); cur.add(a[i]); if (cur < A) { res.a[res.n ++] = 0; continue; } st = 1; en = MOD - 1; while (st < en) { mid = (st + en + 1) / 2; B = A.Multiply(mid); if (cur < B) en = mid - 1; else if (cur == B) { st = mid; break; } else st = mid; } res.a[res.n ++] = st; cur = cur - A.Multiply(st); } res.Reverse(); res.pop(); copy(res); return cur; } void fromString(char *s) { int len = strlen(s); n = 1; a[0] = 0; rep(i, len) { multiply(AT); add(val(s[i])); } } void toString(char *s) { int cnt(0); while (1) { if (n == 1 && !a[0]) break; s[cnt ++] = re_val(mod_integer(AT)); divide(AT); } s[cnt] = 0; reverse(s, s + cnt); } }ONE, ZERO; BG pow_mod(BG A, BG B, BG C) { A.copy(A.Get_mod(C)); BG rlt, cur; rlt.copy(ONE); while (1) { if (B == ZERO) return rlt; if (B.a[0] % 2) { cur.copy(rlt * A); rlt.copy(cur.Get_mod(C)); } cur = A*A; A.copy(cur.Get_mod(C)); B.divide(2); } return rlt; } int count_number(LL k) { if (k == 0) return 1; int res(0); while (k) res ++, k /= 10; return res; } int BG_init() { ZERO.init(); ONE.init(); ONE.a[0] = 1; } char a[105][20005]; int n; char d[105]; BG A[105]; bool can() { int i, j; if (n == 1) { return 1; } if (n == 2) { if (A[0].n == 1 && A[0].a[0] == 0 && A[1].n == 1&& A[1].a[0] == 0) return 1; if (A[0].n == 1 && A[0].a[0] == 0) return 0; if (A[1].n == 1 && A[1].a[0] == 0) return 0; return 1; } for (i = 0; i < n; i++) { if (A[i].n != 1 || A[i].a[0] != 0) break; } if (i == n) return 1; for (i = 0; i < n; i++) { if (A[i].n == 1 && A[i].a[0] == 0) return 0; } for (i = 1; i < n - 1; i++) { BG x = A[i] * A[i]; BG y = A[i - 1] * A[i + 1]; int kk = A[i].D * 2 - A[i - 1].D - A[i + 1].D; if (kk > 0) { while (kk--) y.multiply(10); if (x != y) return 0; } else if (kk < 0) { kk = -kk; while (kk--) x.multiply(10); if (x != y) return 0; } else { if (x != y) return 0; } } return 1; } int main() { int Tcase; BG_init(); for (scanf("%d", &Tcase); Tcase--;) { scanf("%d", &n); int i; for (i = 0; i < n; i++) A[i].input(); if (can()) { puts("Yes"); } else { puts("No"); } } return 0; }