//Code written by @pulkit0795

#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while (t--)
    {
        int n, first;
        cin >> n;
        int a[n];
        vector<int> v1;
        map<int, int> mp_freq, mp2;
        map<int, int>::iterator itr;
        cin >> first;
        v1.push_back(first);
        a[0] = first;
        for (int i = 1; i < n; i++)
        {
            cin >> a[i];
            if (a[i - 1] == a[i])
            {
                continue;
            }
            else
            {
                v1.push_back(a[i]);
            }
        }
        for (int i = 0; i < v1.size(); i++)
        {
            mp_freq[v1[i]]++;
        }
        set<int> s1;
        for (itr = mp_freq.begin(); itr != mp_freq.end(); itr++)
        {
            int ans = itr->second - 1;
            if (itr->first != v1[0])
            {
                ans++;
            }
            if (itr->first != v1[v1.size() - 1])
            {
                ans++;
            }
            s1.insert(ans);
        }
        cout << *s1.begin() << endl;
    }
    return 0;
}