#include<bits/stdc++.h>

#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define fst first
#define scn second
#define INF 0x3f3f3f3f
#define all(v) (v).begin(), (v).end()
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

void solve(){
	int n;
	si(n);
	vp vec(n);
	for(int i = 0; i < n; i++){
		si(vec[i].fst);
		vec[i].scn = i+1;
	}
	sort(all(vec));
	int ans = INT_MAX;
	int cnt;
	if(vec[0].scn > 1)
		cnt = 1;
	else
		cnt = 0;
	for(int i = 1; i < n; i++){
		if(vec[i-1].fst == vec[i].fst){
			if(vec[i].scn - vec[i-1].scn > 1)
				cnt++;
		}
		else{
			if(vec[i-1].scn < n)
				cnt++;
			ans = min(ans, cnt);
			cnt = 0;
			if(vec[i].scn > 1)
				cnt++;
		}
	}
	if(vec[n-1].scn < n)
		cnt++;
	ans = min(ans, cnt);
	printf("%d\n", ans);
}

int main(){
	int t;
	si(t);
	while(t--){
		solve();
	}
    return 0;
}
