#include <bits/stdc++.h>
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define endl '\n'
using namespace std;
// const double PI = acos(-1.0);
// const double E = exp(1.0);
// const double EPS = 1e-9;
const int MOD = (int)1e9 + 7;
const int N = (int)2e5;

int main() {
#ifdef MY_LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    for (int tc = 1; tc <= T; tc++) {
        int n;
        cin >> n;
        vector<int> a(n);
        map<int, int> mp;
        cin >> a[0];
        mp[a[0]] = 0;
        for (int i = 1; i < n; i++) {
            cin >> a[i];
            if (a[i] != a[i - 1]) {
                mp[a[i]]++;
            }
        }
        
        int ans = INT32_MAX;
        for (auto x : mp) {
            if (x.first != a[n - 1]) {
                x.second++;
            }
            ans = min(ans, x.second);
        }
        if (ans == INT32_MAX) {
            ans = 0;
        }
        cout << ans << endl;
    }

    return 0;
}