#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; #define X first #define Y second #define pb push_back template inline void chkmin(T &x, T y) { if (y < x) x = y; } template inline void chkmax(T &x, T y) { if (x < y) x = y; } char s[205]; struct Bint { int a[505], n; int d; Bint() { memset(a, 0, sizeof a); } void init(int t) { n = 1; memset(a, 0, sizeof a); a[0] = t; } void input() { scanf("%s", s); int l = strlen(s); int j; for (j = 0; j < l; j++) if (s[j] == '.') break; if (j == l) d = 0; else d = l - 1 - j; n = 0; for (int i = l - 1; i >= 0; i--) { if (s[i] == '.') continue; a[n++] = s[i] - '0'; } while (a[n - 1] == 0 && n > 1) n--; } bool iszero() { if (n == 1 && a[0] == 0) return 1; return 0; } void print() { for (int i = n - 1; i >= 0; i--) printf("%d", a[i]); puts(""); } }A[105]; Bint multi(Bint A, Bint B) { Bint C; C.n = A.n + B.n + 2; C.d = A.d + B.d; for (int i = 0; i < A.n; i++) { for (int j = 0; j < B.n; j++) { C.a[i + j] += A.a[i] * B.a[j]; } } for (int i = 0; i < C.n - 1; i++) { C.a[i + 1] += C.a[i] / 10; C.a[i] %= 10; } while (C.a[C.n - 1] == 0 && C.n > 1) C.n--; return C; } bool equal(Bint A, Bint B) { if (A.iszero() && B.iszero()) return 1; if (A.d > B.d) { for (int i = B.n - 1; i >= 0; i--) B.a[i + A.d - B.d] = B.a[i]; for (int i = 0; i < A.d - B.d; i++) B.a[i] = 0; B.n += A.d - B.d; } else { for (int i = A.n - 1; i >= 0; i--) A.a[i + B.d - A.d] = A.a[i]; for (int i = 0; i < B.d - A.d; i++) A.a[i] = 0; A.n += B.d - A.d; } if (A.n != B.n) return 0; for (int i = 0; i < A.n; i++) { if (A.a[i] != B.a[i]) return 0; } return 1; } int n; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int tn; for (cin >> tn; tn--; ) { scanf("%d", &n); for (int i = 0; i < n; i++) { A[i].input(); } if (n == 1) { puts("Yes"); continue; } int i; for (i = 0; i < n; i++) { if (!A[i].iszero()) break; } if (i == n) { puts("Yes"); continue; } for (i = 0; i < n; i++) { if (A[i].iszero()) break; } if (i < n) { puts("No"); continue; } for (i = 0; i < n - 2; i++) { Bint AA = multi(A[i], A[i + 2]); Bint BB = multi(A[i + 1], A[i + 1]); if (!equal(AA, BB)) break; } if (i < n - 2) puts("No"); else puts("Yes"); } return 0; }