#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
int t;
int n;
int nums[100001];
vector<int> Primes[1000001];
int Counter[1000001];
int MoreThanOneCounter=0;
bool IsPrime[1000001];
void Add(int x)
{
int i;
for (i=0;i<Primes[x].size();i++)
{
Counter[ Primes[x][i] ]++;
if (Counter[ Primes[x][i] ]>1)
{
MoreThanOneCounter++;
}
}
return;
}
void Remove(int x)
{
int i;
for (i=0;i<Primes[x].size();i++)
{
Counter[ Primes[x][i] ]--;
if (Counter[ Primes[x][i] ]==1)
{
MoreThanOneCounter--;
}
}
return;
}
int main()
{
//freopen("sample.txt","r",stdin);
int test;
int i,j;
int cp;
int l,r;
int ans=-1;
for (i=1;i<=1000000;i++)
{
IsPrime[i]=true;
}
IsPrime[1]=false;
for (i=2;i<=1000000;i++)
{
if (IsPrime[i])
{
Primes[i].push_back(i);
for (j=i+i;j<=1000000;j+=i)
{
Primes[j].push_back(i);
IsPrime[j]=false;
}
}
}
scanf("%d",&t);
for (test=1;test<=t;test++)
{
memset(Counter,0,sizeof(Counter));
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&nums[i]);
}
l=1;
r=1;
Add(nums[1]);
ans=-1;
while(l<=n)
{
while(MoreThanOneCounter>0)
{
Remove(nums[l]);
l++;
}
if (r-l+1>ans && r-l+1>1)
ans=r-l+1;
if (r==n)
break;
r++;
Add(nums[r]);
}
printf("%d\n",ans);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHN0cmluZy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHQ7CmludCBuOwppbnQgbnVtc1sxMDAwMDFdOwp2ZWN0b3I8aW50PiBQcmltZXNbMTAwMDAwMV07CgppbnQgQ291bnRlclsxMDAwMDAxXTsKaW50IE1vcmVUaGFuT25lQ291bnRlcj0wOwoKYm9vbCBJc1ByaW1lWzEwMDAwMDFdOwoKdm9pZCBBZGQoaW50IHgpCnsKICAgIGludCBpOwoKICAgIGZvciAoaT0wO2k8UHJpbWVzW3hdLnNpemUoKTtpKyspCiAgICB7CiAgICAgICAgQ291bnRlclsgUHJpbWVzW3hdW2ldIF0rKzsKICAgICAgICBpZiAoQ291bnRlclsgUHJpbWVzW3hdW2ldIF0+MSkKICAgICAgICB7CiAgICAgICAgICAgIE1vcmVUaGFuT25lQ291bnRlcisrOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm47Cn0KCnZvaWQgUmVtb3ZlKGludCB4KQp7CiAgICBpbnQgaTsKCiAgICBmb3IgKGk9MDtpPFByaW1lc1t4XS5zaXplKCk7aSsrKQogICAgewogICAgICAgIENvdW50ZXJbIFByaW1lc1t4XVtpXSBdLS07CiAgICAgICAgaWYgKENvdW50ZXJbIFByaW1lc1t4XVtpXSBdPT0xKQogICAgICAgIHsKICAgICAgICAgICAgTW9yZVRoYW5PbmVDb3VudGVyLS07CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybjsKfQoKaW50IG1haW4oKQp7CiAgICAvL2ZyZW9wZW4oInNhbXBsZS50eHQiLCJyIixzdGRpbik7CgogICAgaW50IHRlc3Q7CiAgICBpbnQgaSxqOwogICAgaW50IGNwOwogICAgaW50IGwscjsKICAgIGludCBhbnM9LTE7CgogICAgZm9yIChpPTE7aTw9MTAwMDAwMDtpKyspCiAgICB7CiAgICAgICAgSXNQcmltZVtpXT10cnVlOwogICAgfQogICAgSXNQcmltZVsxXT1mYWxzZTsKCiAgICBmb3IgKGk9MjtpPD0xMDAwMDAwO2krKykKICAgIHsKICAgICAgICBpZiAoSXNQcmltZVtpXSkKICAgICAgICB7CiAgICAgICAgICAgIFByaW1lc1tpXS5wdXNoX2JhY2soaSk7CgogICAgICAgICAgICBmb3IgKGo9aStpO2o8PTEwMDAwMDA7ais9aSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgUHJpbWVzW2pdLnB1c2hfYmFjayhpKTsKICAgICAgICAgICAgICAgIElzUHJpbWVbal09ZmFsc2U7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgc2NhbmYoIiVkIiwmdCk7CgogICAgZm9yICh0ZXN0PTE7dGVzdDw9dDt0ZXN0KyspCiAgICB7CiAgICAgICAgbWVtc2V0KENvdW50ZXIsMCxzaXplb2YoQ291bnRlcikpOwoKICAgICAgICBzY2FuZigiJWQiLCZuKTsKCiAgICAgICAgZm9yIChpPTE7aTw9bjtpKyspCiAgICAgICAgewogICAgICAgICAgICBzY2FuZigiJWQiLCZudW1zW2ldKTsKICAgICAgICB9CgogICAgICAgIGw9MTsKICAgICAgICByPTE7CiAgICAgICAgQWRkKG51bXNbMV0pOwoKICAgICAgICBhbnM9LTE7CiAgICAgICAgd2hpbGUobDw9bikKICAgICAgICB7CiAgICAgICAgICAgIHdoaWxlKE1vcmVUaGFuT25lQ291bnRlcj4wKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBSZW1vdmUobnVtc1tsXSk7CiAgICAgICAgICAgICAgICBsKys7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGlmIChyLWwrMT5hbnMgJiYgci1sKzE+MSkKICAgICAgICAgICAgYW5zPXItbCsxOwoKICAgICAgICAgICAgaWYgKHI9PW4pCiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICAgICAgcisrOwogICAgICAgICAgICBBZGQobnVtc1tyXSk7CiAgICAgICAgfQoKICAgICAgICBwcmludGYoIiVkXG4iLGFucyk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K