#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define P pair<ll,ll>
#define F first
#define S second
#define vll vector<ll>
#define vpll vector<P>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define mll map<ll,ll>
#define M map
#define V vector
#define mod2 998244353
#define mod 1000000007
#define C cout<<fixed<<setprecision(5)
using namespace std;
bool com(P a,P b){
    if(a.F==b.F) return a.S<b.S;
    return a.F<b.F;
}
int main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll t;
	cin >> t;
	while (t--){
	   ll n,m=INT_MAX,c=0;
	   cin>>n;
	   P a[n];
	   for(ll i=0;i<n;i++) {cin>>a[i].F; a[i].S=i;}
	   sort(a,a+n,com);
	   if(a[0].S!=0) c++;
	   for(ll i=1;i<n;i++){
	       if(a[i].F==a[i-1].F) {
	           if(a[i].S-a[i-1].S>1) c++;
	       }
	       else{
	           if(a[i-1].S!=n-1) c++;
	           if(m>c) m=c; c=0;
	           if(a[i].S!=0) c++;
	       }
	   }
	   if(a[n-1].S!=n-1) c++;
	   if(m>c) m=c;
	   cout<<m<<"\n";
	}
	return 0;
}	