#include <bits/stdc++.h>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
using namespace std;
 
int t, n, a[400010], GCD, ans, st[400010][20];
bool b[400010], bb;
 
int gcd(int x, int y){
    if(!y) return x;
    return gcd(y, x % y);
}
 
int query(int i, int j){    // ST 表查询
    int k = log2(j - i + 1);
    return gcd(st[i][k], st[j - (1 << k) + 1][k]);
}
 
int main(){
 
    cin >> t;
    while(t--){
        cin >> n, ans = bb = 0;
        for(int i = 1; i <= n; i++)
            cin >> a[i], b[i] = 0;
        for(int i = 1; i <= n; i++) a[i + n] = a[i], st[i][0] = st[i + n][0] = a[i];    // 破环为链
        for(int i = 1; i <= n; i++)
            if(a[i] != a[1]){
                bb = 1;
                break;
            }
        if(!bb){
            puts("0");
            continue;
        }
        GCD = a[1];
        for(int i = 2; i <= n; i++) GCD = gcd(GCD, a[i]);
        for(int j = 1; (1 << j) <= n + n; j++)    // 注意这里是 n + n，ST 表需要处理整条链
            for(int i = 1; i + (1 << j) - 1 <= n + n; i++)
                st[i][j] = gcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
        for(int i = 1, L, R, mid; i <= n; i++){
            L = i, R = n + i - 1;
            while(L < R){    
                int mid = (L + R) >> 1;
                if(query(i, mid) != GCD) L = mid + 1;
                else R = mid;
            }
            ans = max(ans, L - i);
        }
        printf("%d\n", ans);
    }
 
    return 0;
}