#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int MAX = 100010;
const int MV = 1000001;
int t, n;
int a[MAX] = {0};
int u[MV] = {0};
vi f[MV];
void solve() {
memset(u, 0, sizeof(u));
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
int l = 0;
int r = 0;
int res = 0;
vi rf, lf;
lf = f[a[0]];
rf = f[a[0]];
while(1) {
bool canBeAdded = true;
for(int i = 0; i < rf.size(); i++)
if(u[rf[i]]) {
canBeAdded = false;
break;
}
if(canBeAdded) {
for(int i = 0; i < rf.size(); i++)
u[rf[i]] = 1;
res = max(res, r - l + 1);
r++;
if(r == n)
break;
rf = f[a[r]];
} else {
for(int i = 0; i < lf.size(); i++)
u[lf[i]] = 0;
l++;
lf = f[a[l]];
}
}
if(res == 1)
printf("-1\n");
else
printf("%d\n", res);
}
int main() {
for(int i = 2; i <= MV; i++)
if(f[i].size() == 0) {
for(int j = 1; j * i <= MV; j++)
f[i * j].push_back(i);
}
#ifdef _LOCAL_VAN
freopen("in.txt","r",stdin);
#endif
scanf("%d\n" ,&t);
while(t--) {
solve();
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxsaW1pdHMuaD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWVtb3J5Lmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHNldD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsaT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