//
//  mod.cpp
//  
//
//  Created by Sagar Singh on 17/12/20.
//

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

#define WHILE_ONCE  while(false)
#define bug1( x )                   do{ cerr << (#x) << "=" << x << endl; }WHILE_ONCE;
#define bug2( x , y )               do{ cerr << (#x) << "=" << x << "    " << (#y) << "=" << y << endl; }WHILE_ONCE;
#define bug3( x , y , z )           do{ cerr << (#x) << "=" << x << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl; }WHILE_ONCE;
#define bug4( x , y , z , w)        do{ cerr << (#x) << "=" << x << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl; }WHILE_ONCE;
#define bug5( x , y , z , w ,p)     do{ cerr << (#x) <<    "=" << x << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl; }WHILE_ONCE;
#define bug6( x , y , z , w ,p , q) do{ cerr << (#x) << "=" << x << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl; }WHILE_ONCE;
#define bugn( x , n )               do{ cerr << (#x) << endl; for(int i=0;i<n;i++){ cout  << x[i] << "    "; } cout << endl; }WHILE_ONCE;
#define bugnm( x , n , m )          do{ cerr << (#x) << endl; for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout << x[i][j] << "    "; } cout << endl; }WHILE_ONCE;

typedef unsigned long long ul;
typedef long double ld;
typedef long long ll;
using namespace std;

template<typename T, typename K>
inline bool smax(T &x,K y){ return x < y ? x = y, true : false; }
template<typename T, typename K>
inline bool smin(T &x,K y){ return x > y ? x = y, true : false; }

const int mod = 1e9+7;
int add(int x,int y){
	int z = x + y;
	if( z >= mod ){
		z -= mod;
	}
	return z;
}
int sub(int x,int y){
	int z = x - y;
	if( z < 0 ){
		z += mod;
	}
	return z;
}
int mul(int x,int y){
	ll z = 1ll * x * y;
	if( z >= mod ){
		z %= mod;
	}
	return z;
}
int binpow(int a,ll p){
	int r = 1;
	while( p ){
		if( p & 1 )
			r = mul(r,a);
		a = mul(a,a), p >>= 1;
	}
	return r;
}
int gcd(int a,int b){
		return b ? gcd(b,a%b) : a;
}

const int nax = 1e6+1;
int lg[nax], dp[nax][20];
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	lg[1] = 0;
	for(int i=2;i<nax;++i)
		lg[i] = 1 + lg[i>>1];
	int t; cin >> t;
	while( t-- ){
		int n; cin >> n;
		int a[n];
		for(int i=0;i<n;++i){
			cin >> a[i];
		}
		int g = a[0];
		for(int i=0;i<n;++i){
			g = gcd(g,a[i]);
		}
		for(int i=0;i<n;++i){
			a[i] = a[i] / g;
			dp[i][0] = dp[i+n][0] = a[i];
		}
		for(int i=n+n-1;i>=0;--i){
			for(int j=1;i+(1<<j)-1<n+n;++j){
				dp[i][j] = gcd(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
			}
		}
		auto query = [&](int l,int r){
			int k = lg[r-l+1];
			return gcd(dp[l][k],dp[r-(1<<k)+1][k]);
		};
		int mx = 0;
		for(int i=0;i<n;++i){
			int l = i-1, r = n+n-1;
			while( l + 1 < r ){
				int m = (l+r)>>1;
				( query(i,m) != 1 ? l : r ) = m;
			}
			mx = max(mx,r - i);
			//bug2(i,r-i);
		}
		cout << mx << endl;
	}

}


