#include <iostream>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <cmath>

#define ll long long
#define ld long double
#define INF 10e+9

using namespace std;


int main()
{
    cin.tie(nullptr);
    std::istream::sync_with_stdio(false);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;

        vector<ll> arr;
        ll x;
        ll prev = -1;
        ll new_n = n;
        for (ll i = 0; i < n; ++i)
        {
            cin >> x;
            if (x == prev)
            {
                --new_n;
                continue;
            }

            prev = x;
            arr.emplace_back(x);
        }

        map<ll, ll> m;
        for (ll i = 0; i < new_n - 1; ++i)
        {
            if (arr[i] != arr[i + 1])
            {
                if (m.find(arr[i]) == m.end() && i != 0)
                {
                    m[arr[i]] = 1;
                }

                m[arr[i]] += 1;

                if (i == (new_n - 2) && m[arr[i + 1]] == 0)
                {
                    m[arr[i + 1]] = 1;
                }
            }
        }

        ll min_v = 1e10;
        for (auto pair : m)
        {
            if (pair.second < min_v)
            {
                min_v = pair.second;
            }
        }

        cout << (min_v == 1e10 ? 0 : min_v )<< endl;
    }


    return 0;
}
