#include <iostream>
#include <unordered_map>
using namespace std;
namespace Syxqwq {
inline int read() {
int x = 0, s = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') s = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c - '0');
c = getchar();
}
return x * s;
}
void Write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) Write(x / 10);
putchar(x % 10 + '0');
}
inline void write(int x, char c) {
Write(x), putchar(c);
}
}
using namespace Syxqwq;
const int _N = 1e8 + 19, N = 5e5 + 19;
int isprime[_N], prime[_N], cnt, a[N];
void getprime() {
int n = 1e8;
for (long long i = 2; i <= n; ++i) {
if (isprime[i] == 0) {
isprime[i] = i;
prime[++cnt] = i;
for (int j = 1; j <= cnt && prime[j] * i <= n; ++j) {
isprime[i * prime[j]] = i;
if (i % prime[j] == 0) break;
}
}
}
}
int main() {
getprime();
int T;
scanf("%d", &T);
while (T--) {
unordered_map<int, int> mp;
int n = read();
for (int i = 1; i <= n; ++i) a[i] = read();
if (n == 1) {
puts("No");
continue;
}
if (n == 2) {
puts("Yes");
continue;
}
bool flag = 0;
for (int i = 1; i <= n && flag == 0; ++i) {
while (1) {
if (mp[isprime[a[i]]] != i && mp[isprime[a[i]]] != 0) {
flag = 1;
break;
}
mp[isprime[a[i]]] = i;
if (a[i] == isprime[a[i]]) break;
a[i] /= isprime[a[i]];
}
}
if (flag) puts("No");
else puts("Yes");
}
return 0;
}