/*
    author : aryan57
    created : 10-July-2021 21:00:01 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

/*
    It is the data structure for monoids i.e., the algebraic structure that satisfies the following properties :
        associativity: (a⋅b)⋅c = a⋅(b⋅c) for all a,b,c ∈ S
        existence of the identity element: a⋅e = e⋅a = a for all a ∈ S

    (1) segtree<S, binary_operation, identity_element> seg(int n)
    (2) segtree<S, binary_operation, identity_element> seg(vector<S> v)
        (1): It creates an array a of length n. All the elements are initialized to identity_element().
        (2): It creates an array a of length n = v.size(), initialized to v.
        0≤n≤10**8
        O(n)

    void seg.set(int p, S x)
        It assigns x to a[p]
        0≤p<n
        O(logn)

    S seg.get(int p)
        It returns a[p]
        0≤p<n
        O(1)

    S seg.prod(int l, int r)
        It returns binary_operation(a[l], ..., a[r - 1]), assuming the properties of the monoid. It returns identity_element() if l=r.
        0≤l≤r≤n
        O(logn)

    S seg.all_prod()
        It returns op(a[0], ..., a[n - 1]), assuming the properties of the monoid. It returns identity_element() if n=0.
        O(1)

    (1) int seg.max_right<check_function>(int l)
    (2) int seg.max_right<F>(int l, F check_function)
        (1): It applies binary search on the segment tree. The function bool check_function(S x) should be defined.
        (2): The function object that takes S as the argument and returns bool should be defined.

        It returns an index r that satisfies both of the following :-
            r = l or check_function(binary_operation(a[l], a[l + 1], ..., a[r - 1])) = true
            r = n or check_function(binary_operation(a[l], a[l + 1], ..., a[r])) = false

        If check_function is monotone, this is the maximum r that satisfies check_function(binary_operation(a[l], a[l+1], ..,a[r-1]))=true

        if check_function is called with the same argument, it returns the same value, i.e., check_function has no side effect.
        check_function(identity_element()) = true
        0≤l≤n

        O(logn)

    (1) int seg.min_left<check_function>(int r)
    (2) int seg.min_left<F>(int r, F check_function)
        (1): It applies binary search on the segment tree. The function bool check_function(S x) should be defined.
        (2): The function object that takes S as the argument and returns bool should be defined.

        It returns an index l that satisfies both of the following :-
            l = r or check_function(binary_operation(a[l], a[l + 1], ..., a[r - 1])) = true
            l = 0 or check_function(binary_operation(a[l - 1], a[l], ..., a[r - 1])) = false

        If check_function is monotone, this is the minimum l that satisfies check_function(binary_operation(a[l], a[l+1], ..,a[r-1]))=true

        if check_function is called with the same argument, it returns the same value, i.e., check_function has no side effect.
        check_function(identity_element()) = true
        0≤r≤n

        O(logn)

    https://atcoder.github.io/ac-library/production/document_en/segtree.html

*/

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n((int)(v.size())) {
        log = segtree::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }

    // @param n `0 <= n`
    // @return minimum non-negative `x` s.t. `n <= 2**x`
    int ceil_pow2(int n) {
        int x = 0;
        while ((1U << x) < (unsigned int)(n)) x++;
        return x;
    }

};

int gcd(int a, int b) /*__gcd doesn't work for big no.s*/
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int binary_operation(int a,int b)
{
    return gcd(a,b);
}

int identity_element()
{
    return 0;
}

void solve_LOL()
{
    int n;
    cin>>n;

    vector <int> v(n);
    for(int &x : v)cin>>x;
    segtree<int,binary_operation,identity_element> tree(v);

    int l=0;
    int r=n-1;
    int ans=n;

    while (l<=r)
    {
        int m=(l+r)/2;

        int num=tree.prod(0,m+1);

        bool ok = true;
        // if(m==1)
        // {
        //     dbg(l,r,num);
        // }
        F(i,1,n-1)
        {
            int right=i+m+1;
            int extra=right-n;
            right=min(right,n);
            int nn1=tree.prod(i,right);
            int nn2=0;
            if(extra>0)
            {
                nn2=tree.prod(0,extra);
            }

            // if(m==1)
            // {
            //     // dbg(i,nn1,nn2,gcd(nn1,nn2),right,extra);
            // }

            if(gcd(nn1,nn2)!=num)
            {
                ok=false;
                break;
            }
        }

        if(ok)
        {
            ans=min(ans,m);
            r=m-1;
        }
        else
        {
            l=m+1;
        }
    }

    cout<<ans;
    cout<<"\n";
    
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOL();
    }
    return 0;
}
//	parsed : 10-July-2021 20:07:54 IST
### Prompt

Please formulate a CPP solution to the following problem:

You are given an array of positive integers a = [a_0, a_1, ..., a_{n - 1}] (n ≥ 2).

In one step, the array a is replaced with another array of length n, in which each element is the [greatest common divisor (GCD)](http://tiny.cc/tuy9uz) of two neighboring elements (the element itself and its right neighbor; consider that the right neighbor of the (n - 1)-th element is the 0-th element).

Formally speaking, a new array b = [b_0, b_1, ..., b_{n - 1}] is being built from array a = [a_0, a_1, ..., a_{n - 1}] such that b_i = \gcd(a_i, a_{(i + 1) mod n}), where \gcd(x, y) is the greatest common divisor of x and y, and x mod y is the remainder of x dividing by y. In one step the array b is built and then the array a is replaced with b (that is, the assignment a := b is taking place).

For example, if a = [16, 24, 10, 5] then b = [\gcd(16, 24), \gcd(24, 10), \gcd(10, 5), \gcd(5, 16)] = [8, 2, 5, 1]. Thus, after one step the array a = [16, 24, 10, 5] will be equal to [8, 2, 5, 1].

For a given array a, find the minimum number of steps after which all values a_i become equal (that is, a_0 = a_1 = ... = a_{n - 1}). If the original array a consists of identical elements then consider the number of steps is equal to 0.

Input

The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.

Each test case contains two lines. The first line contains an integer n (2 ≤ n ≤ 2 ⋅ 10^5) — length of the sequence a. The second line contains n integers a_0, a_1, ..., a_{n - 1} (1 ≤ a_i ≤ 10^6).

It is guaranteed that the sum of n over all test cases doesn't exceed 2 ⋅ 10^5.

Output

Print t numbers — answers for each test case.

Example

Input


5
4
16 24 10 5
4
42 42 42 42
3
4 6 4
5
1 2 3 4 5
6
9 9 27 9 9 63


Output


3
0
2
1
1

### Response

```cpp
/*
    author : aryan57
    created : 10-July-2021 21:00:01 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

/*
    It is the data structure for monoids i.e., the algebraic structure that satisfies the following properties :
        associativity: (a⋅b)⋅c = a⋅(b⋅c) for all a,b,c ∈ S
        existence of the identity element: a⋅e = e⋅a = a for all a ∈ S

    (1) segtree<S, binary_operation, identity_element> seg(int n)
    (2) segtree<S, binary_operation, identity_element> seg(vector<S> v)
        (1): It creates an array a of length n. All the elements are initialized to identity_element().
        (2): It creates an array a of length n = v.size(), initialized to v.
        0≤n≤10**8
        O(n)

    void seg.set(int p, S x)
        It assigns x to a[p]
        0≤p<n
        O(logn)

    S seg.get(int p)
        It returns a[p]
        0≤p<n
        O(1)

    S seg.prod(int l, int r)
        It returns binary_operation(a[l], ..., a[r - 1]), assuming the properties of the monoid. It returns identity_element() if l=r.
        0≤l≤r≤n
        O(logn)

    S seg.all_prod()
        It returns op(a[0], ..., a[n - 1]), assuming the properties of the monoid. It returns identity_element() if n=0.
        O(1)

    (1) int seg.max_right<check_function>(int l)
    (2) int seg.max_right<F>(int l, F check_function)
        (1): It applies binary search on the segment tree. The function bool check_function(S x) should be defined.
        (2): The function object that takes S as the argument and returns bool should be defined.

        It returns an index r that satisfies both of the following :-
            r = l or check_function(binary_operation(a[l], a[l + 1], ..., a[r - 1])) = true
            r = n or check_function(binary_operation(a[l], a[l + 1], ..., a[r])) = false

        If check_function is monotone, this is the maximum r that satisfies check_function(binary_operation(a[l], a[l+1], ..,a[r-1]))=true

        if check_function is called with the same argument, it returns the same value, i.e., check_function has no side effect.
        check_function(identity_element()) = true
        0≤l≤n

        O(logn)

    (1) int seg.min_left<check_function>(int r)
    (2) int seg.min_left<F>(int r, F check_function)
        (1): It applies binary search on the segment tree. The function bool check_function(S x) should be defined.
        (2): The function object that takes S as the argument and returns bool should be defined.

        It returns an index l that satisfies both of the following :-
            l = r or check_function(binary_operation(a[l], a[l + 1], ..., a[r - 1])) = true
            l = 0 or check_function(binary_operation(a[l - 1], a[l], ..., a[r - 1])) = false

        If check_function is monotone, this is the minimum l that satisfies check_function(binary_operation(a[l], a[l+1], ..,a[r-1]))=true

        if check_function is called with the same argument, it returns the same value, i.e., check_function has no side effect.
        check_function(identity_element()) = true
        0≤r≤n

        O(logn)

    https://atcoder.github.io/ac-library/production/document_en/segtree.html

*/

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n((int)(v.size())) {
        log = segtree::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }

    // @param n `0 <= n`
    // @return minimum non-negative `x` s.t. `n <= 2**x`
    int ceil_pow2(int n) {
        int x = 0;
        while ((1U << x) < (unsigned int)(n)) x++;
        return x;
    }

};

int gcd(int a, int b) /*__gcd doesn't work for big no.s*/
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int binary_operation(int a,int b)
{
    return gcd(a,b);
}

int identity_element()
{
    return 0;
}

void solve_LOL()
{
    int n;
    cin>>n;

    vector <int> v(n);
    for(int &x : v)cin>>x;
    segtree<int,binary_operation,identity_element> tree(v);

    int l=0;
    int r=n-1;
    int ans=n;

    while (l<=r)
    {
        int m=(l+r)/2;

        int num=tree.prod(0,m+1);

        bool ok = true;
        // if(m==1)
        // {
        //     dbg(l,r,num);
        // }
        F(i,1,n-1)
        {
            int right=i+m+1;
            int extra=right-n;
            right=min(right,n);
            int nn1=tree.prod(i,right);
            int nn2=0;
            if(extra>0)
            {
                nn2=tree.prod(0,extra);
            }

            // if(m==1)
            // {
            //     // dbg(i,nn1,nn2,gcd(nn1,nn2),right,extra);
            // }

            if(gcd(nn1,nn2)!=num)
            {
                ok=false;
                break;
            }
        }

        if(ok)
        {
            ans=min(ans,m);
            r=m-1;
        }
        else
        {
            l=m+1;
        }
    }

    cout<<ans;
    cout<<"\n";
    
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOL();
    }
    return 0;
}
//	parsed : 10-July-2021 20:07:54 IST
```