#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 400010;

int n,m,t,w[N],l,r,d;

struct node{
	int l, r;
	ll sum, d;
}tr[N << 2];

int gcd(int a, int b){ return b ? gcd(b, a % b) : a;}
 
void pushup(node& root, node& left, node& right){
	root.sum = left.sum + right.sum;
	root.d = gcd(left.d, right.d);
}

void pushup(int u){ pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);} 

void build(int u, int l, int r){
	tr[u].l = l, tr[u].r = r;
	if(l == r){
		ll b = w[l] - w[l - 1];
		tr[u].d = tr[u].sum = b;
	}else{
		int mid = l + r >> 1;
		build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
		pushup(u);
	}
}

node query(int u, int l, int r){
	if(tr[u].l >= l && tr[u].r <= r)	return tr[u];
	int mid = tr[u].l + tr[u].r >> 1;
	if(r <= mid)	return query(u << 1, l, r);
	else if(l > mid)	return query(u << 1 | 1, l, r);
	else{
		node res,left,right;
		left = query(u << 1, l, r);
		right = query(u << 1 | 1, l, r);
		pushup(res, left, right);
		return res;
	}
}

bool check(int mid){
	for(int i = 1; i <= n; ++ i){
		l = i, r = i + mid;
		node left1 = query(1, 1, l);
		node right1 = {0,0,0,0};
		if(l + 1 <= r)	right1 = query(1, l + 1, r);
		if(abs(gcd(left1.sum, right1.d)) != d)	return false;
	}
	return true;
}

int main(){
	cin >> t;
	while(t --){
		cin >> n;
		d = 0;
		for(int i = 1; i <= n; ++ i)	scanf("%d",&w[i]), d = gcd(d, w[i]), w[i + n] = w[i];
		build(1,1,2 * n);
		int l = 0, r = n;
		while(l < r){
			int mid = l + r >> 1;
			//printf("mid = %d\n", mid);
			if(check(mid))	r = mid;
			else	l = mid + 1;
		}
		cout << r << endl;
	}
	return 0;
} 