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

const int N = 400010;

int n,m,t,d,w[N];
struct node{
	int l, r;
	int sum, d;
}tr[N << 2];

int gcd(int a, int b){ return b ? gcd(b, a % b) : a;}
 
void pushup(node& tr, node& ls, node& rs){
	tr.sum = ls.sum + rs.sum;
	tr.d = gcd(ls.d, rs.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, r, 0, 0};
	if(l == r){
		ll tmp = w[l] - w[l - 1];
		tr[u].d = tr[u].sum = tmp;
	}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 left = query(u << 1, l, r);
		node right = query(u << 1 | 1, l, r);
		node tmp;
		pushup(tmp, left, right);
		return tmp;
	}
}

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

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

