#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef pair<int,int> P;
typedef long long ll;



void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    vector<int> b;
    int c = -1;
    rep(i,n) {
        if(c != a[i]) {
            b.push_back(a[i]);
            c = a[i];
        }
    }
    
    if(b.size() == 1) {
        cout << 0 << endl;
        return ;
    }
    
    map<int,int> m;
    rep(i,b.size()) {
        m[b[i]]++;
    }
    int ans = 1001001001;
    for(auto x : m) {
        int cnt = x.second+1;
        if(x.first == b.front())
            cnt--;
        if(x.first == b.back())
            cnt--;
        ans = min(ans,cnt);
    }
    
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    rep(i,t) {
        solve();
    }
    
    //solve();
    
    return 0;
}
