#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ull unsigned long long
#define pb push_back

#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define rep(a,b,c) for (int(a) = (b); (a) < (c); (a)++)
#define repl(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define repr(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define deb(x) cout<<#x<<"="<<x<<endl;
#define INF 1000000000000000003
#define ff first
#define ss second
#define pob pop_back
#define mp make_pair
// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())
//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())
// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef double ld;
const int mod = 1e9 + 9;

ll power(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll modInverse(ll a, ll m)
{
    ll g = gcd(a, m);
    if (g != 1)
        cout << "Inverse doesn't exist";
    else
    {
        return power(a, m - 2, m);
    }
}

ll log_a_b(ll a, ll b)
{
    return (a > b - 1)
            ? 1 + log_a_b(a / b, b)
            : 0;
}

vl seg;

void build(vl &a,ll v,ll tl,ll tr){
    if(tl==tr)
        seg[v]=a[tl];
    else{
        ll tm=(tl+tr)/2;
        build(a,v*2+1,tl,tm);
        build(a,v*2+2,tm+1,tr);
        seg[v]=gcd(seg[v*2+1],seg[v*2+2]);
    }
}
ll sum(ll v,ll tl,ll tr,ll l,ll r){
    if(l>r)
        return 0;
    if(l==tl && r==tr)
        return seg[v];

    ll tm=(tl+tr)/2;
    if(l>min(r,tm)){
        return sum(2*v+2,tm+1,tr,max(tm+1,l),r);
    }
    if(max(tm+1,l)>r){
        return sum(2*v+1,tl,tm,l,min(r,tm));
    }

    return gcd(sum(2*v+1,tl,tm,l,min(r,tm)),
            sum(2*v+2,tm+1,tr,max(tm+1,l),r));
}

void update(ll v,ll tl,ll tr,ll ind,ll val){
    if(tl==tr)
        seg[v]=val;
    else{
        ll tm=(tl+tr)/2;
        if(ind<=tm)
            update(2*v+1,tl,tm,ind,val);
        else
            update(2*v+2,tm+1,tr,ind,val);

        seg[v]=seg[2*v+1]+seg[2*v+2];
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(15);
    ll T;
    cin >> T;
    while (T--) {
        ll n,q,k,m,u,v;
        cin>>n;
        vl a(2*n);
        rep(i,0,n){cin>>a[i];a[n+i]=a[i];}
        seg.clear();
        seg.resize(8*n);
        build(a,0,0,2*n-1);
        ll gc=a[0];
        rep(i,0,n){
            gc=gcd(gc,a[i]);
        }
        ll ans=0;
        rep(i,0,n){
            ll l=i;ll r=4*n-2-i;
            ll pos=-1;
            while(l<=r){
                ll mid=(l+r)/2;
                ll x=sum(0,0,2*n-1,i,mid);
                //cout<<x<<" ";
                if(x==gc)r=mid-1;
                else {
                    pos=mid;
                    l=mid+1;
                }
            }
            if(pos==-1)pos=i;
            else pos++;
            //cout<<"{"<<i<<" "<<pos<<"} ";
            ans=max(ans,pos-i);
        }
        cout<<ans<<"\n";

    }
    return 0;
}
/*
1
10 5
1 2 5 3 8 0 5 9 6 19
0 4 8
1 5 21
0 4 8
1 6 -5
0 3 7
*/
