#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> pll;
#define ff first
#define ss second
#define pb push_back
ll const MOD=1000000007;
const int Mx= 2e5 + 10;
#define eb emplace_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
const int N=1e7;

int main()
{

    ll t;

    cin>>t;

    while(t--)
    {

        ll n;
        cin>>n;

        map<ll,ll>mp,l,r;
        vector<ll>v;

        ll val=-1;




        ll  mx=1e9,mn=1e12;

        for(ll i=1; i<=n; i++)
        {

            ll a;


            cin>>a;

            if(mp[a]==0)
            {
                l[a]=v.size();
                l[a]++;

            }


            if(val!=a)
            {
                v.pb(a);
                val=a;
                mp[a]++;
                r[a]=v.size();
            }

        }



        for(auto x : mp)
        {
            ll cnt=x.ss-1;



            if(l[x.ff]!=1)cnt++;



            if(r[x.ff]!=v.size())cnt++;



            mn=min(mn,cnt);


        }

        cout<<mn<<endl;

    }
}
