#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll mod=1e9+7;
ll lo[200005];

ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}


ll table[200006][MAX];

void buildSparseTable(ll arr[], ll n)
{
    for (ll i = 0; i < n; i++)
        table[i][0] = arr[i];
 
    for (ll j = 1; j <= 20; j++)
        for (ll i = 0; i <= n - (1 << j); i++)
            table[i][j] = gcd(table[i][j - 1],
                    table[i + (1 << (j - 1))][j - 1]);
}

ll query(ll L, ll R)
{
    ll j = lo[(R - L + 1)];
    return gcd(table[L][j], table[R - (1 << j) + 1][j]);
}

void fun()
{
    ll n;
    cin>>n;
    ll a[n];
    ll gc=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        gc=gcd(gc,a[i]);
    }
    // cout<<gc<<'\n';
    buildSparseTable(a,n);
    ll ans[n];
    for(ll i=0;i<n;i++)
    {
        ll left=i;
        ll right = i+(n-1);
        
        while(left<=right)
        {
            ll mid=(left+right)/2;
            ll res;
            if(mid>n-1)
            {
                res=query(i,n-1);
                res=gcd(res,query(0,mid%n));
            }
            else
            {
                res=query(i,mid);
            }
            if(res==gc)
            {
                ans[i]=(mid-i);
                right=mid-1;
            }
            else
            {
                left=mid+1;
            }
        }
    }
    ll mn=0;
    for(ll i=0;i<n;i++)
    {
        mn=max(mn,ans[i]);
        // cout<<ans[i]<<''
    }
    cout<<mn<<'\n';
}

int main()
{
    ll t=1;
    flash;
    cin>>t;
    
    for(ll i = 1; i <= 200004; i++) {
        lo[i] = (ll)log2(i);
    }
    while(t--)
    fun();
    
    return 0;
}