///*******************************THINK TWICE CODE ONCE*******************************///
///*******************************NO CODE NO FOOD*******************************///
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define loop(n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
//int f[1001];
//vector<int>a[100001];
int dis[100001];
//int ans(int )
int main()
{
//freopen("team.in", "r", stdin);
//freopen("output.txt","w",stdout);
fast;
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
int f[1001]={0};
map<int,int>m;
loop(n)
{
cin>>a[i];
m[a[i]]=i;
f[a[i]]=1;
}
int mx=0;
loop(1001)
{
for(int j=0;j<1001;j++)
{
if(f[i]==1&&f[j]==1)
{
int c= __gcd(i,j);
if(c==1)
{
//cout<<"a ";
mx=max(mx,(m[i]+m[j]));
}
}
}
}
if(mx==0)
cout<<-1<<endl;
else
cout<<mx+2<<endl;
}
return 0;
}
Ly8vKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKlRISU5LIFRXSUNFIENPREUgT05DRSoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovLy8KLy8vKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKk5PIENPREUgTk8gRk9PRCoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovLy8KI2RlZmluZSBfVVNFX01BVEhfREVGSU5FUwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBmYXN0IGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTtjaW4udGllKDApO2NvdXQudGllKDApCiNkZWZpbmUgbG9vcChuKSBmb3IoaW50IGk9MDtpPG47aSsrKQojZGVmaW5lIGxsIGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwovL2ludCBmWzEwMDFdOwovL3ZlY3RvcjxpbnQ+YVsxMDAwMDFdOwppbnQgZGlzWzEwMDAwMV07Ci8vaW50IGFucyhpbnQgKQppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigidGVhbS5pbiIsICJyIiwgc3RkaW4pOwogICAgLy9mcmVvcGVuKCJvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKICAgIGZhc3Q7CiAgICBpbnQgdDsKICAgIGNpbj4+dDsKICAgIHdoaWxlKHQtLSkKICAgIHsKCiBpbnQgbjsKIGNpbj4+bjsKIGludCBhW25dOwogaW50IGZbMTAwMV09ezB9OwogbWFwPGludCxpbnQ+bTsKIGxvb3AobikKIHsKICAgICBjaW4+PmFbaV07CiAgICAgbVthW2ldXT1pOwogICAgIGZbYVtpXV09MTsKIH0KCiBpbnQgbXg9MDsKIGxvb3AoMTAwMSkKIHsKICAgICBmb3IoaW50IGo9MDtqPDEwMDE7aisrKQogICAgIHsKICAgICAgICAgaWYoZltpXT09MSYmZltqXT09MSkKICAgICAgICAgewoKICAgICAgICAgICAgaW50IGM9IF9fZ2NkKGksaik7CiAgICAgICAgICAgIGlmKGM9PTEpCiAgICAgICAgICAgIHsKLy9jb3V0PDwiYSAiOwogICAgICAgICAgbXg9bWF4KG14LChtW2ldK21bal0pKTsKICAgICAgICAgICAgfQoKICAgICAgICAgfQogICAgIH0KIH0KIGlmKG14PT0wKQogICAgY291dDw8LTE8PGVuZGw7CiBlbHNlCiBjb3V0PDxteCsyPDxlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0K
Main.java:3: error: illegal character: '#'
#define _USE_MATH_DEFINES
^
Main.java:4: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:5: error: illegal character: '#'
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
^
Main.java:5: error: class, interface, or enum expected
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
^
Main.java:5: error: class, interface, or enum expected
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
^
Main.java:6: error: illegal character: '#'
#define loop(n) for(int i=0;i<n;i++)
^
Main.java:6: error: class, interface, or enum expected
#define loop(n) for(int i=0;i<n;i++)
^
Main.java:6: error: class, interface, or enum expected
#define loop(n) for(int i=0;i<n;i++)
^
Main.java:7: error: illegal character: '#'
#define ll long long
^
Main.java:11: error: class, interface, or enum expected
int dis[100001];
^
Main.java:13: error: class, interface, or enum expected
int main()
^
Main.java:18: error: class, interface, or enum expected
int t;
^
Main.java:19: error: class, interface, or enum expected
cin>>t;
^
Main.java:20: error: class, interface, or enum expected
while(t--)
^
Main.java:24: error: class, interface, or enum expected
cin>>n;
^
Main.java:25: error: class, interface, or enum expected
int a[n];
^
Main.java:26: error: class, interface, or enum expected
int f[1001]={0};
^
Main.java:27: error: class, interface, or enum expected
map<int,int>m;
^
Main.java:28: error: class, interface, or enum expected
loop(n)
^
Main.java:31: error: class, interface, or enum expected
m[a[i]]=i;
^
Main.java:32: error: class, interface, or enum expected
f[a[i]]=1;
^
Main.java:33: error: class, interface, or enum expected
}
^
Main.java:36: error: class, interface, or enum expected
loop(1001)
^
Main.java:38: error: class, interface, or enum expected
for(int j=0;j<1001;j++)
^
Main.java:38: error: class, interface, or enum expected
for(int j=0;j<1001;j++)
^
Main.java:44: error: class, interface, or enum expected
if(c==1)
^
Main.java:48: error: class, interface, or enum expected
}
^
Main.java:55: error: class, interface, or enum expected
else
^
Main.java:57: error: class, interface, or enum expected
}
^
Main.java:59: error: class, interface, or enum expected
}
^
30 errors