#include<bits/stdc++.h>
using namespace std;
#define MAX 200010
#define ll long long

int T,n,ans,a[MAX];
 
int gcd(int x,int y){return x%y?gcd(y,x%y):y;} 

int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);ans=0;
		for(int i=0;i<n;i++)scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int j=i+1,cnt=0,x=a[i],y=a[j%n];
			while(x!=y){
				x=gcd(x,a[j%n]);
				y=gcd(y,a[(j+1)%n]);
				j++;cnt++;
			}
			ans=max(ans,cnt);
		}
		printf("%d\n",ans);
	}
	return 0;
}