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

#define ll long long
#define ull unsigned ll
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vs vector<string>
#define vvi vector<vi>
#define ff first
#define ss second
#define pb push_back
#define vpi vector<pi>
#define vpll vector<pll>
#define umap unordered_map
#define uset unordered_set
#define all(x) x.begin(),x.end()
#define fr(i,j,n) for(int i=j;i<n;++i)
#define rfr(i,j,n) for(int i=j; i>=n;--i)
#define MOD 1000000007
#define INF INT_MAX
#define LINF LONG_LONG_MAX  
#define mp make_pair
#define endl "\n"
#define sz  size()
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){
    int n;
    cin>>n;
    vi arr;
    int x;
    cin>>x;
    arr.pb(x);
    fr(i,0,n-1){
        cin>>x;
        if(x != arr.back()){
            arr.pb(x);
        }
    }
    if(arr.sz == 1){
        cout<<0<<endl;
        return;
    }
    map<int,int> cnt;
    fr(i,0,arr.sz){

        cnt[arr[i]]++;
    }
    cnt[arr[0]]--;
    cnt[arr[arr.sz-1]]--;
    int min = INF;
    for(auto it : cnt){
        if(it.ss < min){
            min = it.ss;
        }
    }
    
    cout<<min+1<<endl;
    return;
}

void pre() {
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        // cout<<solve()<<endl;
    }
}

int main() {
	fastIO; 
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	pre();
	return 0; 
	
}
