#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isPrime(ll x)
{
    ll i,n;
    n=sqrt(x);
    if(x==1) return false;
    if(x==2 || x==3) return true;
    for(i=2;i<=n;i++)
    {
        if(!(x%i)) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
int solve()
{
    ll n,i,ans=0,ans2=1000000000;
    cin>>n;
    vll v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    map<ll,ll> m,o;
    for(i=0;i<n;i++)
    {
        if(m[v[i]])
        {
            if(m[v[i]]!=i)
            {
                o[v[i]]+=1;
            }
             m[v[i]]=i+1;
        }
        else
        {
            m[v[i]]=i+1;
            o[v[i]]=1;
        }
    }
    o[v[n-1]]--;
    o[v[0]]--;
    for(auto j:o)
    {
        //cout<<j.first<<" "<<j.second<<"\n";
        if(j.second+1<ans2)
        {
            ans2=j.second+1;
        }
    }
    if(ans2==1000000000)
    {
        ans2=0;
    }
    cout<<ans2<<"\n";
    return 0;
}
int main()
{
    fst;
    test();
    return 0;
}