#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b) {
    while (b) {
        a = a % b;
        swap(a, b);
    }
    return a;
}

void solve() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    int C = v[0];
    for (int i = 0; i < n; ++i)
        C = gcd(C, v[i]);
    for (int i = 0; i < n; ++i)
        v[i] /= C;
   for (int i = 0; i < n; ++i)
        v.push_back(v[i]);
   map<int, int> cur;
   int ans = 0;
   for (int i = 0; i < n + n; ++i) {
        vector<int> res;
        for (int j = 2; j * j <= v[i]; ++j) {
            if (v[i] % j == 0) {
                res.push_back(j);
                if (j * j != v[i])
                    res.push_back(v[i] / j);
            }
        }
        if (res.size() == 0 && v[i] != 1)
            res.push_back(v[i]);
        map<int, int> nw;
        for (auto x : res)
            nw[x] = 1 + cur[x];
        for (auto x : nw)
            ans = max(ans, x.second);
        swap(nw, cur);
   }
   cout << ans << '\n';
}

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