#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
using namespace std;
#define FOR(i,a) for(int i = 0;i < a;i++)
#define REP(i,a,b) for(int i = a;i < b;i++)
#define vi vector<int>
int gcdr ( int a, int b )
{
if ( a==0 ) return b;
return gcdr ( b%a, a );
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,n;
int ar[100001];
cin>>t;
while(t--)
{
cin>>n;
FOR(i,n)
{
cin>>ar[i];
}
int flag=0;
FOR(i,n-1)
{
if(gcdr(ar[i],ar[i+1])==1)
{
flag=1;
break;
}
}
if(flag==0)
cout<<-1<<endl;
else
cout<<n<<endl;
}
cin.get();cin.get();
return 0;
}
I2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPGJpdHNldD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxudW1lcmljPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPG1lbW9yeS5oPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgRk9SKGksYSkgICAgZm9yKGludCBpID0gMD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