# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <cctype>
# include <unistd.h>
# include <unordered_map>
# include <unordered_set>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
#define pb push_back
#define mp make_pair
    
template <class T> inline T gcd(T a, T b) { while (b) { T t = a % b; a = b; b = t; } return a; }
 
ll bin_pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n % 2 == 1)
            res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

ll modpow(ll x, ll n, ll m) {
    if (n == 1)
        return 1;
    ll u = modpow(x, n / 2, m);
    u = (u*u) % m;
    if (n % 2 == 1)
        u = (u*x) % m;
    return u;
}

const ll MAXN = 400010;
int a[MAXN], t[4*MAXN];

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(2*v, tl, tm);
        build(2*v + 1, tm + 1, tr);
        t[v] = gcd(t[2*v], t[2*v + 1]);
    }
}

int gcd(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v];
    else {
        int tm = (tl + tr) / 2;
        return gcd(gcd(2*v, tl, tm, l, min(r, tm)), gcd(2*v + 1, tm + 1, tr, max(l, tm + 1), r));
    }
}

void solve() {
    int n;
    cin >> n;
    
    int t = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i + n] = a[i];
    }
    
    int size = 2*n - 1;
    
    build(1, 0, size);
    
    int l = 0, r = n;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        int _gcd = gcd(1, 0, size, 0, mid - 1);
        
//        cout << "mid: " << mid << "\n";
//        cout << "_gcd: " << _gcd << "\n";
//
        bool ok = true;
        for (int i = 1; i < n; ++i) {
            int n_gcd = gcd(1, 0, size, i, i + mid - 1);
            if (_gcd != n_gcd) {
//                cout << "break: " << i << " " << n_gcd << "\n";
                ok = false;
                break;
            }
        }
        
        if (ok)
            r = mid;
        else
            l = mid;
    }
    
    cout << l << "\n";
}

int main()
{
    int t = 1;
    cin >> t;

    while (t --> 0) {
        solve();
    }
}
