#include <bits/stdc++.h>
#include <string>
#include <vector>

#define pb push_back
#define rb pop_back
#define pf push_front
#define rf pop_front

#define mp make_pair

#define fi first
#define se second
#define endl "\n"

#define pii pair<int, int>

#define int long long
#define float long double
#define multiTest cin >> t; for(test = 0; test < t; test++)
#define toFile freopen("a.inp", "r", stdin); freopen("a.out", "w", stdout);
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int inf = 9e18;
const int mod = 1e9 + 7;

using namespace std;

int t;
int test;

bool cmp(pii a, pii b) {
	if(a.fi == b.fi) return a.se < b.se;
	else return a.fi < b.fi;
}

void solve() {
	int n;
	cin >> n;
	
	pii a[n + 5];
	for(int i = 0; i < n; i++) {
		cin >> a[i].fi;
		a[i].se = i + 1;
	}
	sort(a, a + n, cmp);
	
	if(n == 1) {
		cout << 0 << endl;
		return;
	}
	
	int res = inf;
	if(a[0].fi != a[1].fi) {
		res = 0;
		if(a[0].se != n) res++;
		if(a[0].se != 1) res++;
	}
	
	int cnt = 0;
	if(a[0].se != 1) cnt++;
	
	for(int i = 1; i < n; i++) {
 		if(a[i].fi == a[i - 1].fi) {
			if(a[i - 1].se + 1 != a[i].se) cnt++;
		} else {
			if(a[i - 1].se != n) {
				cnt++;
			}
			res = min(cnt, res);
			cnt = 0;
			
			if(a[i].se != 1) cnt++;
		}
	}
	if(a[n - 1].se != n) {
		cnt++;
	}
	res = min(cnt, res);
	
	cout << res << endl;
}

signed main() {
	speed;
	
	//toFile
	
	multiTest
	solve();
	
	return 0;
}