#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> 
#include<vector>
#include<set>
using namespace std;
const int N=200010,M=1000010;
bool prime[M];
int primes[M];
int selve[M];
int e[N];
int num=0;
set<int> fas[N];
int t,n;
void make_prime(int k){
	prime[0]=prime[1]=1;
	for(int i=2;i<=k;i++){
		if(!prime[i]){
			primes[num++]=i;
			selve[i]=i;
		}
		for(int j=0;primes[j]*i<=k;j++){
			prime[i*primes[j]]=1;
			selve[i*primes[j]]=primes[j];
			if(i%primes[j]==0)break;
		}
	}
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
void solve(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		int common=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&e[i]);
			common=gcd(common,e[i]);
		}
		for(int i=1;i<=n;i++){
			int t=e[i]/common;
			while(t!=1){
				fas[i].insert(selve[t]);
				t/=selve[t];
			}
		}
        int res=0;
		for(int i=1;i<=n;i++){
			for(int j:fas[i]){
               int ans=0;
			    int l=i-1;if(l==0)l=n;
			    int r=i;
                while(fas[l].count(j)){
                    ans++;
                    fas[l].erase(j);
                    l--;
                    if(l==0)l=n;
                }
                while(fas[r].count(j)){
                    if(r!=i){
                        fas[r].erase(j);
                    }
                    ans++;
                    r++;
                    if(r==n+1)r=1;
                }
                res=max(res,ans);
            }
            fas[i].clear();
		}
		printf("%d\n",res);
	}
}
int main(){
	make_prime(1000000);
	solve();
	return 0;
} 