#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define el cout<<'\n'
#define pii pair <int,int>
#define ll long long
#define prob "F"
using namespace std;

const int N=2e5;

int n,a[2*N+1],g=0;
int st[8*N+1];

int gcd(int a,int b)
{
    if (1LL*a*b==0) return a+b;
    if (a<b) swap(a,b);
    return gcd(a%b,b);
}

void upd(int id,int l,int r,int i,int x)
{
    if (l==r)
    {
        st[id]=x;
        return ;
    }
    int mid=(l+r)/2;
    if (i<=mid) upd(2*id,l,mid,i,x);
    else upd(2*id+1,mid+1,r,i,x);
    st[id]=gcd(st[2*id],st[2*id+1]);
}

int get(int id,int l,int r,int u,int v)
{
    if (u>r || v<l) return 0;
    if (u<=l && v>=r) return st[id];
    int mid=(l+r)/2;
    return gcd(get(2*id,l,mid,u,v),get(2*id+1,mid+1,r,u,v));
}

int bi(int l,int r,int i)
{
    int mid=(l+r)/2;
    while (mid!=l && mid!=r)
    {
        if (get(1,1,2*n,i,i+mid-1)==g) r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    for (int j=l;j<=r;j++)
        if (get(1,1,2*n,i,i+j-1)==g) return j-1;
    return 0;
}

void input()
{
    cin>>n;
    g=0;

    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        g=gcd(a[i],g);
    }
    for (int i=1;i<n;i++)
    {
        a[n+i]=a[i];
        upd(1,1,2*n,i,a[i]);
        upd(1,1,2*n,i+n,a[i]);
    }
    upd(1,1,2*n,n,a[n]);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int tmp=bi(1,n,i);
        ans=max(ans,tmp);
    }
    cout<<ans;el;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while (t--)
    input();
    return 0;
}

