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

signed  main() {
	int t; cin>>t;
	while(t--){
	    int n; cin>>n;
	    int arr[n];
	    bool flag=true;
	    vector<int> vec;
	    for(int i=0;i<n;i++) {
	        cin>>arr[i];
	        if(i==0) vec.push_back(arr[i]);
	        else{
	            if(arr[i]==arr[i-1]) continue;
	            else vec.push_back(arr[i]);
	        }
	    }
	    
	    if(vec.size()==1) {cout<<0<<endl; continue;}
	    
	   
	    unordered_map<int,int> dp;
	    n=vec.size();
	    dp[vec[0]]=1;
	    for(int i=1;i<n-1;i++){
	        if(dp[vec[i]]==0) dp[vec[i]]=2;
	        else dp[vec[i]]++;
	    }
	    
	    if(dp[vec[n-1]]==0) dp[vec[n-1]]=1;
	    
	    unordered_map<int,int> ::iterator it;
	    int ans=INT_MAX;
	    for(it=dp.begin();it!=dp.end();it++){
	        ans=min(ans,it->second);
	    }
	    cout<<ans<<endl;
	    
	    
	}
	return 0;
}