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

int main(){
    int t;
    cin >> t;
    
    while(t--){
        int n;
        cin >> n;
        int arr[n];
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        
        vector <int> v;
        vector <int> :: iterator itV;
        for(int i=0; i<n; i++){
            if(arr[i]!=arr[i-1] && i>0){
                v.push_back(arr[i]);
            }
            if(i==0){
                v.push_back(arr[i]);
            }
        }
        map <int , int> mp;
        map <int,int> :: iterator itM;
        for(int i=0; i<v.size(); i++){
            mp[v[i]]++;
        }
        int occurence=0,ans=-1;
        for(itM = mp.begin(); itM!=mp.end(); itM++){
            occurence = itM->second + 1;
            if(itM->first == v[0] || itM->first == v[v.size()-1]){
                occurence--;
                if(itM->first == v[0] && itM->first == v[v.size()-1]){
                    occurence--;
                }
            }
            if(ans==-1){
                ans = occurence;
            }
            else{
                ans = min(ans,occurence);
            }
        }
        
        cout << ans << endl;
        
    }
}