#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector<int>Indx[333333];

void solveT()
{
	int t;
	cin>>t;
	while(t--)
	{

		int n,mx = INT_MIN;
		cin>>n;
		vector<int>v;
		for(int i=0;i<=n+10;i++)Indx[i].clear();
		map<int,int>mp;
		//set<int>st;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			//v.pb(x);
			Indx[x].pb(i+1);
			mp[x]++;
			mx = max(mx,mp[x]);
			v.pb(x);
		}
		if(n==1)
		{
			cout<<"0\n";
			continue;
		}
		if(mx==1)
		{
			cout<<"1\n";
			continue;
		}
		if(mx==n)
		{
			cout<<"0\n";
			continue;
		}
		//cout<<v.size()<<" --- >";
		int ans = INT_MAX;
		for(int j=0;j<n;j++)
		{
			int i = v[j];
			int cnt = 0;
			if(Indx[i].size()==1)
			{
				if(Indx[i][0]==1 || Indx[i][0]==n)
					cnt = 1;
				else
					cnt = 2;
				ans = min(ans,cnt);
				continue;
			}
			for(int k=0;k<Indx[i].size()-1;k++)
			{
				if(Indx[i][k+1]-Indx[i][k]>1)
					cnt++;
			}
			cnt+=2;
			if(Indx[i][0]==1)
				cnt--;
			if(Indx[i][Indx[i].size()-1]==n)
				cnt--;
			ans = min(ans,cnt);
		}
		cout<<ans<<endl;
	}
	return ;
}

int main()
{
	fast;
	solveT();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"

vector<int>v;

void solveT()
{
	int t;
	cin>>t;
	while(t--)
	{

		int n,mn = INT_MAX,mx = INT_MIN;
		cin>>n;
		v.clear();
		vector<int>Indx[333333];
		map<int,int>mp;
		set<int>st;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			v.pb(x);
			Indx[x].pb(i+1);
			mp[x]++;
			mx = max(mx,mp[x]);
			st.insert(x);
		}
		map<int,int> :: iterator it;
		vector<int>same,same2;
		for(it = mp.begin();it!=mp.end();it++)
		{
			mn = min(mn,it->second);
		}
		for(it=mp.begin();it!=mp.end();it++)
		{
			if(mn==it->second)
			{
				same.pb(it->first);
			}
			if(mx==it->second)
			{
				same2.pb(it->first);
			}
		}
		if(mn==1)
		{
			cout<<"1\n";
			continue;
		}
		if(mx==n)
		{
			cout<<"0\n";
			continue;
		}
		set<int>::iterator it2;
		int ans = INT_MAX;
		for(it2=st.begin();it2!=st.end();it2++)
		{
			int i = *it2;
			if(Indx[i].size()>=1){
			int cnt = Indx[i].size()-1;
			if(Indx[i][0]!=1)
				cnt++;
			if(Indx[i][Indx[i].size()-1]!=n)
				cnt++;
			ans = min(ans,cnt);
			}
		}
		cout<<ans<<endl;
	}
}

int main()
{
	//fast;
	solveT();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

vector<int>v;

void solveT()
{
	int t;
	cin>>t;
	while(t--)
	{

		int n,mn = INT_MAX,mx = INT_MIN;
		cin>>n;
		v.clear();
		vector<int>Indx[333333];
		map<int,int>mp;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			v.pb(x);
			Indx[x].pb(i+1);
			mp[x]++;
			mx = max(mx,mp[x]);
		}
		map<int,int> :: iterator it;
		vector<int>same,same2;
		for(it = mp.begin();it!=mp.end();it++)
		{
			mn = min(mn,it->second);
		}
		for(it=mp.begin();it!=mp.end();it++)
		{
			if(mn==it->second)
			{
				same.pb(it->first);
			}
			if(mx==it->second)
			{
				same2.pb(it->first);
			}
		}
		if(mn==1)
		{
			cout<<"1\n";
			continue;
		}
		if(mx==n)
		{
			cout<<"0\n";
			continue;
		}
		int ans = INT_MAX;
		for(int i=1;i<333333;i++)
		{
			if(Indx[i].size()>=1){
			int cnt = Indx[i].size()-1;
			if(Indx[i][0]!=1)
				cnt++;
			if(Indx[i][Indx[i].size()-1]!=n)
				cnt++;
			ans = min(ans,cnt);
			}
		}
		cout<<ans<<endl;
	}
}

int main()
{
	//fast;
	solveT();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector<int>Indx[333333];

void solveT()
{
	int t;
	cin>>t;
	while(t--)
	{

		int n,mx = INT_MIN;
		cin>>n;
		vector<int>v;
		for(int i=0;i<=n+10;i++)Indx[i].clear();
		map<int,int>mp;
		//set<int>st;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			//v.pb(x);
			Indx[x].pb(i+1);
			mp[x]++;
			mx = max(mx,mp[x]);
			v.pb(x);
		}
		if(mx==1)
		{
			cout<<"1\n";
			continue;
		}
		if(mx==n)
		{
			cout<<"0\n";
			continue;
		}
		//cout<<v.size()<<" --- >";
		int ans = INT_MAX;
		for(int j=0;j<n;j++)
		{
			int i = v[j];
			int cnt = 0;
			if(Indx[i].size()==1)
			{
				if(Indx[i][0]==1 || Indx[i][0]==n)
					cnt = 1;
				else
					cnt = 2;
				ans = min(ans,cnt);
				continue;
			}
			for(int k=0;k<Indx[i].size()-1;k++)
			{
				if(Indx[i][k+1]-Indx[i][k]>1)
					cnt++;
			}
			cnt+=2;
			if(Indx[i][0]==1)
				cnt--;
			if(Indx[i][Indx[i].size()-1]==n)
				cnt--;
			ans = min(ans,cnt);
		}
		cout<<ans<<endl;
	}
	return ;
}

int main()
{
	fast;
	solveT();
	return 0;
}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

void solve() {
  ll n; cin>>n;
  ll A[n];
  vector<ll> v;

  ll h[n+1];
  memset(h,0,sizeof(h));

  fo(i,n) cin>>A[i];

  for(int i=0;i<n-1;i++){
    if(A[i]!=A[i+1]){
      v.pb(A[i]);
    }
  }
  v.pb(A[n-1]);
  if(v.size() <= 1){
    cout<<0<<endl;
    return;
  }

  for(auto x : v){
    h[x]++;
  }

  if(h[v[0]] > 1){
    h[v[0]]--;
  }
  else{
    if(h[v[0]]==1){
      cout<<1<<endl;
      return;
    }
  }
  if(h[v[n-1]] > 1){
    h[v[n-1]]--;
  }
  else{
    if(h[v[n-1]]==1){
      cout<<1<<endl;
      return;
    }
  }

  ll mn = INT_MAX;
  for(int i = 1; i<=n; i++){
    if(h[i]>0)
      mn = min(mn, h[i]);
  }
  if(mn >= n) {
    cout<<0<<endl;
    return;
  }
  else{
    cout<<mn+1<<endl;
    return;
  }

}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

void solve()  {

  ll n; cin>>n;

  int A[n];

  fo(i,n) cin >> A[i];

  vector<int> un;

  fo(i,n-1){
  	if(A[i]!=A[i+1]) un.pb(A[i]);
  }
  un.pb(A[n-1]);

  int h[n+1];
  memset(h,1,sizeof(h));

  fo(i, un.size()) h[un[i]]++;

  h[un[0]]--; h[un[n-1]]--;
  int ans = INT_MAX;
  fo(i,n){
  	ans = min(ans, h[A[i]]);
  }
  cout<<ans<<endl;
}

int main() {

    fast_io;

    int t = 1;

    cin >> t;

    while(t--) {

      solve();

    }

    return 0;

}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

void solve()  {
	ll n; cin>>n;
	int A[n];
	fo(i,n) cin >> A[i];
	vector<int> u;
	fo(i,n-1) if(A[i+1]!=A[i]) u.pb(A[i]);
	u.pb(A[n-1]);
	// for(int x : u) cout << x << " ";
	int res[n+1];
	for(int i=0;i<=n;i++) res[i]=1;
	for(int x : u) res[x]++;

	int ans = INT_MAX;
	res[u[0]]--;
	res[u[u.size()-1]]--;
	fo(i,n){
		// cout<<res[A[i]]<<" ";
		ans = min(ans,res[A[i]]);
	}
	cout << ans << endl;
}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

void solve() {
  ll n; cin>>n;
  int A[n];
  vector<int> v;
  int h[n+1];
  memset(h,0,sizeof(h));
  for(int i=0;i<n;i++){
    cin >> A[i];
  }
  for(int i=0;i<n-1;i++){
    if(A[i]!=A[i+1]){
      v.pb(A[i]);
    }
  }
  v.pb(A[n-1]);
  if(v.size() <= 1){
    cout<<0<<endl;
    return;
  }

  for(auto x : v){
    h[x]++;
  }

  if(h[v[0]] > 1){
    h[v[0]]--;
  }
  else{
    if(h[v[0]]==1){
      cout<<1<<endl;
      return;
    }
  }
  if(h[v[n-1]] > 1){
    h[v[n-1]]--;
  }
  else{
    if(h[v[n-1]]==1){
      cout<<1<<endl;
      return;
    }
  }

  int mn = INT_MAX;
  for(int i = 0; i<=n; i++){
    if(h[i])
      mn = min(mn, h[i]);
  }
  if(mn == INT_MAX) {
    cout<<0<<endl;
    return;
  }
  else{
    cout<<mn+1<<endl;
    return;
  }
  // determine how many times an element divides the array.

}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

// 1 =>  0
// 2 => 1 [2]
// 3 => 1 [3]
// 4 => 2 [2,2]
// 5 => prime(1)
// 6 => 1 [6]
// 7 => 1
// 8 => [2 2 2]
// 9 => [3,3]
// 10 => [10]
// 1 2 3 1 2 3 1
void solve() {
  ll n; cin>>n;
  int A[n];
  vector<int> v;
  int h[n+1];
  memset(h,0,sizeof(h));
  for(int i=0;i<n;i++){
    cin >> A[i];
  }
  for(int i=0;i<n-1;i++){
    if(A[i]!=A[i+1]){
      v.pb(A[i]);
    }
  }
  v.pb(A[n-1]);
  if(v.size()==1){
    cout<<0<<endl;
    return;
  }
  for(auto x : v){
    h[x]++;
  }

  if(h[v[0]] > 1){
    h[v[0]]--;
  }
  else{
    if(h[v[0]]==1){
      cout<<1<<endl;
      return;
    }
  }
  if(h[v[n-1]] > 1){
    h[v[n-1]]--;
  }
  else{
    if(h[v[n-1]]==1){
      cout<<1<<endl;
      return;
    }
  }

  int mn = INT_MAX;
  for(int i = 0; i<= n+1; i++){
    if(h[i])
      mn = min(mn, h[i]);
  }
  if(mn == INT_MAX) {
    cout<<0<<endl;
    return;
  }
  else{
    cout<<mn+1<<endl;
    return;
  }
  // determine how many times an element divides the array.

}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

int SimpleCount(vector<int> B[], int x, int n){

  if(B[x].size()==0) return INT_MAX;

  int ctr = 0;

  for(int i = 0 ;i < B[x].size()-1 ;i++){

    if(B[x][i]+1!=B[x][i+1]) ctr++;

  }

  if(B[x][0]!=0) ctr++;

  if( B[x][B[x].size()-1] != n-1 ) ctr++;

  return ctr;

}

void solve() {

  ll n; cin>>n;

  int A[n];

  fo(i,n) { cin >> A[i]; A[i]--; }

  vector<int> B[n];

  fo(i,n) B[A[i]].pb(i);

  int mx = INT_MAX;

  fo(i,n) mx = min(mx, SimpleCount(B, A[i], n));

  cout<<mx<<endl;

}

int main() {

    fast_io;

    int t = 1;

    cin >> t;

    while(t--) {

      solve();

    }

    return 0;

}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

int lcm(int a, int b)
{
    return (a / gcd(a, b) * b);
}

ll ans = 0;

void dfs(ll x, ll reps){
  ll ans_t = INT_MAX;
  ll i_t = INT_MAX;
  for(ll i = 1; i <= sqrt(x); i++){
    if(x%i==0 && lcm(i, x / i) == x){
      if(ans_t > i+x/i){
        ans_t = min(ans_t, i + x/i);
        i_t = i;
      }
    }
  }
  debug2(i_t, x/i_t);
  debug(reps);
  if(reps == 1){
    ans+= ans_t;

    return;
  }
  else{
    dfs(i_t, reps-1);
    dfs(x/i_t,reps-1);
    return;
  }
}

void solve() {
  ll n; cin>>n;
  int A[n];
  int B[n+1];
  memset(B,0,sizeof(B));

  fo(i,n){
    cin >> A[i];
    if(i!=0 && i!=n-1){
      B[A[i]]++;
    }
  }
  // find min occu + 1;
  int mn = INT_MAX;
  fo(i,n+1){
    if(B[i]) mn = min(mn, B[i]);
  }
  if(B[A[0]]==0 || B[A[n-1]] == 0){
    cout<<1<<endl;
    return;
  }
  if(mn == n-2){
    cout<<0<<endl;
    return;
  }
  cout<<mn+1<<endl;
}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <set>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

void solve() {
  ll n; cin>>n;
  ll A[n];
  fo(i,n) cin>>A[i];

  vector<ll> v;

  ll h[n+1];
  memset(h,0,sizeof(h));

  for(int i=0;i<n-1;i++){
    if(A[i]!=A[i+1]){
      v.pb(A[i]);
    }
  }
  v.pb(A[n-1]);

  if(v.size() <= 1){
    cout<<0<<endl;
    return;
  }

  for(int x : v){
    h[x]++;
  }

  if(h[v[0]] > 1){
    h[v[0]]--;
  }
  else{
    if(h[v[0]]==1){
      cout<<1<<endl;
      return;
    }
  }
  if(h[v[n-1]] > 1){
    h[v[n-1]]--;
  }
  else{
    if(h[v[n-1]]==1){
      cout<<1<<endl;
      return;
    }
  }

  ll mn = INT_MAX;
  for(int i = 1; i<=n; i++){
    if(h[i]>0)
      mn = min(mn, h[i]);
  }
  if(mn >= n) {
    cout<<0<<endl;
    return;
  }
  else{
    cout<<mn+1<<endl;
    return;
  }

}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define fo(i,n) for (int i = 0; i < n; ++i)
#define traverse(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define initialise(x,k) memset(x, k, sizeof(x))
#define sortall(x) sort(all(x))
#define reversesortall(x) sort(all(x), greater<int>())
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define PI 3.1415926535897932384626
#define mod = 1000000007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<vi>		matrix_i;
typedef vector<vl>		matrix_l;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

int lcm(int a, int b)
{
    return (a / gcd(a, b) * b);
}

ll ans = 0;

void dfs(ll x, ll reps){
  ll ans_t = INT_MAX;
  ll i_t = INT_MAX;
  for(ll i = 1; i <= sqrt(x); i++){
    if(x%i==0 && lcm(i, x / i) == x){
      if(ans_t > i+x/i){
        ans_t = min(ans_t, i + x/i);
        i_t = i;
      }
    }
  }
  debug2(i_t, x/i_t);
  debug(reps);
  if(reps == 1){
    ans+= ans_t;

    return;
  }
  else{
    dfs(i_t, reps-1);
    dfs(x/i_t,reps-1);
    return;
  }
}

void solve() {
  ll n; cin>>n;
  int A[n];
  int B[n+1];
  memset(B,0,sizeof(B));

  fo(i,n){
    cin >> A[i];
    if(i!=0 && i!=n-1 && A[i]!=A[i-1]){
      B[A[i]]++;
    }
  }

  // find min occu + 1;
  int mn = INT_MAX;
  fo(i,n+1){
    if(B[i]) mn = min(mn, B[i]);
  }
  if(mn == INT_MAX){
    cout<<0<<endl;
    return;
  }
  if(B[A[0]]==0 || B[A[n-1]] == 0){
    cout<<1<<endl;
    return;
  }
  if(mn == n-2){
    cout<<0<<endl;
    return;
  }
  cout<<mn+1<<endl;
}

int main() {
    fast_io;
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> mm;
int main()
{
    int t;
    cin>>t;
    while(t--){
        mm.clear();
        int n;
        int an[200005];
        cin>>n;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            mm[an[i]]++;
            if(an[i]==an[0]){
                x=an[0];
                mm[an[i]]--;
                an[0]=-1;
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=20000005;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(an[i]==an[n-1]){
                mm[an[i]]--;
                an[n-1]=-1;
            }
            if(mm[an[i]]<mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        map<int,int> mm;
        int n;
        int an[200005];
        cin>>n;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            if(i>0&&an[i]==an[i-1]||i==1&&an[i]==x) continue;
            else{
                //cout<<"Yes"<<" "<<i<<endl;
                mm[an[i]]++;
                if(an[i]==an[0]){
                    x=an[0];
                    mm[an[i]]--;
                    an[0]=-1;
                }
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=200010;

        bool f=false;
        bool f2=false;
        for(int i=0;i<n;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(f2!=true&&an[i]==an[n-1]){
                f2=true;
                mm[an[i]]--;
            }
            if(mm[an[i]]<mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        int an[200005];
        cin>>n;
        map<int,int> mm;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            mm[an[i]]++;
            if(an[i]==an[0]){
                x=an[0];
                mm[an[i]]--;
                an[0]=-1;
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=200005;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(an[i]==an[n-1]){
                mm[an[i]]--;
                an[n-1]=-1;
            }
            if(mm[an[i]]<mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        map<int,int> mm;
        int n;
        int an[200005];
        cin>>n;
        int d=0;
        cin>>an[0];
        n--;
        d++;
        while(n--){
            cin>>an[d];
            if(an[d]!=an[d-1]) d++;
        }
        int mmin=200005;
        for(int i=0;i<d;i++){
            mm[an[i]]++;
        }
        if(d!=1){
            mm[an[0]]--;
            mm[an[d-1]]--;
            for(int i=0;i<d;i++){
                if(mm[an[i]]<mmin) mmin=mm[an[i]];
            }
            cout<<mmin+1<<endl;
        }
        else cout<<"0"<<endl;

    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        map<int,int> mm;
        int n;
        int an[200005];
        cin>>n;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            mm[an[i]]++;
            if(an[i]==an[0]){
                x=an[0];
                mm[an[i]]--;
                an[0]=-1;
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=2000005;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(an[i]==an[n-1]){
                mm[an[i]]--;
                an[n-1]=-1;
            }
            if(mm[an[i]]<mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> mm;
int main()
{
    int t;
    cin>>t;
    while(t--){
        mm.clear();
        int n;
        int an[200005];
        cin>>n;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            mm[an[i]]++;
            if(an[i]==an[0]){
                x=an[0];
                mm[an[i]]--;
                an[0]=-1;
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=200005;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(an[i]==an[n-1]){
                mm[an[i]]--;
                an[n-1]=-1;
            }
            if(mm[an[i]]<mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        map<int,int> mm;
        int n;
        int an[200005];
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>an[i];
            if(i>0&&an[i]==an[i-1]) continue;
            else mm[an[i]]++;
        }
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=200010;
        bool f=false;
        bool f2=false;
        bool f3=false;
        for(int i=0;i<n;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(f2!=true&&an[i]==an[n-1]){
                f2=true;
                mm[an[i]]--;
            }
            if(f3!=true&&an[i]==an[0]){
                f3=true;
                mm[an[i]]--;
            }
            if(mm[an[i]]<mmin){
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}
/*
int main()
{
    int Ttt;
    cin>>Ttt;
    map<int,int> b,mp;
    int a[200005];
    while(Ttt--)
    {
        b.clear();
        mp.clear();
        int n;
        cin>>n;
        cin>>a[1];
        mp[a[1]]=1;
        for(int i=2;i<=n;i++)
        {
            cin>>a[i];
            if(mp[a[i]]==0)
            b[a[i]]++;
            else if(mp[a[i]])
            {
                if(mp[a[i]]+1==i) ;
                else b[a[i]]++;
            }
            mp[a[i]]=i;
        }
        map<int,int> :: iterator it;
        for(it=mp.begin();it!=mp.end();it++)
        {
            if(mp[it->first]==0)
            b[it->first]++;
            else if(mp[it->first])
            {
                if(mp[it->first]==n) continue;
                else b[it->first]++;
            }
            mp[it->first]=n+1;
        }
        int ans=2e5+10;
        for(int i=1;i<=n;i++)
        {
            ans=min(ans,b[a[i]]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
*/


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int Ttt;
    cin>>Ttt;
    map<int,int> b,mp;
    int a[200005];
    while(Ttt--)
    {
        b.clear();
        mp.clear();
        int n;
        cin>>n;
        cin>>a[1];
        mp[a[1]]=1;
        for(int i=2;i<=n;i++)
        {
            cin>>a[i];
            if(mp[a[i]]==0)
            b[a[i]]++;
            else if(mp[a[i]])
            {
                if(mp[a[i]]+1==i) ;
                else b[a[i]]++;
            }
            mp[a[i]]=i;
        }
        map<int,int> :: iterator it;
        for(it=mp.begin();it!=mp.end();it++)
        {
            if(mp[it->first]==0)
            b[it->first]++;
            else if(mp[it->first])
            {
                if(mp[it->first]==n) continue;
                else b[it->first]++;
            }
            mp[it->first]=n+1;
        }
        int ans=2e5+10;
        for(int i=1;i<=n;i++)
        {
            ans=min(ans,b[a[i]]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        map<int,int> mm;
        int n;
        int an[200005];
        cin>>n;
        cin>>an[0];
        n--;
        int d=0;
        while(n--){
            cin>>an[d];
            if(an[d]!=an[d-1]) d++;
        }
        int mmin=200005;
        for(int i=0;i<d;i++){
            mm[an[i]]++;
        }
        if(d!=1){
            mm[an[0]]--;
            mm[an[d-1]]--;
            for(int i=0;i<d;i++){
                if(mm[an[i]]<mmin) mmin=mm[an[i]];
            }
            cout<<mmin+1<<endl;
        }
        else cout<<"0"<<endl;

    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int t;
    cin>>t;
    while(t--){
        int n;
        int an[200005];
        cin>>n;
        map<int,int> mm;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            mm[an[i]]++;
            if(an[i]==an[0]){
                x=an[0];
                mm[an[i]]--;
                an[0]=-1;
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        if(n!=1){
        int mmin=200005;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(an[i]==an[n-1]){
                mm[an[i]]--;
                an[n-1]=-1;
            }
            if(mm[an[i]]<mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
        }
        else cout<<"0"<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        map<int,int> mm;
        int n;
        int an[200005];
        cin>>n;
        int x=-1;
        for(int i=0;i<n;i++){
            cin>>an[i];
            mm[an[i]]++;
            if(an[i]==an[0]){
                x=an[0];
                mm[an[i]]--;
                an[0]=-1;
            }
        }
        if(x!=-1) an[0]=x;
        //for(int i=0;i<n;i++) cout<<an[i]<<" "<<mm[an[i]]<<" !";
        //cout<<endl;
        int mmin=2000005;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if(mm[an[i]]==n-1){
                f=true;
                break;
            }
            if(an[i]==an[n-1]){
                mm[an[i]]--;
                an[n-1]=-1;
            }
            if(mm[an[i]]<=mmin){
                //cout<<i<<" "<<mm[an[i]]<<endl;
                mmin=mm[an[i]];
            }
        }
        if(f==true) cout<<"0"<<endl;
        else cout<<mmin+1<<endl;
    }
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool f, f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f = f1 = F = F1 = false;
        cin >> n;
        ll a[N2],b[N2];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        k=1;
        fr(i,0,n-1){if(a[i]!=a[i+1])b[a[i]]++;if(a[i]==a[i+1])++ans;}
        if(ans==n-1&&a[n-1]==a[n-2]){cout<<0<<endl;cn;}
//        if(a[0]==a[1])ans++;
//        if(a[n-2]==a[n-1])ans++;
//        if(ans==n){cout<<0<<endl;cn;}
        if(a[n-2]!=a[n-1]) b[a[n-1]]++;
        f=1;

        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n){
          if(mn>b[a[i]]){
            mn=b[a[i]];
            mxa=a[i];
          }
        }
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn+1<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool f, f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f = f1 = F = F1 = false;
        cin >> n;
        ll a[n],b[N2];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        k=1;
        fr(i,0,n-1){if(a[i]!=a[i+1])b[a[i]]++;if(a[i]==a[i+1])++ans;}
//        if(a[0]==a[1])ans++;
//        if(a[n-2]==a[n-1])ans++;
//        if(ans==n){cout<<0<<endl;cn;}
        if(a[n-2]!=a[n-1]) b[a[n-1]]++;
        f=1;

        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n){
          if(mn>b[a[i]]+1){
            mn=b[a[i]]+1;
            mxa=a[i];
          }
        }
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool  f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f1 = F = F1 = false;
        bool f[10000];
        cin >> n;
        ll a[n+1],b[n+1];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        k=1;
        fr(i,0,n-1){
        if(a[i]==a[i+1])++ans;
        if(a[i]!=a[i+1])b[a[i]]++;
        }
        if(ans==n-1&&a[n-1]==a[n-2]){cout<<0<<endl;cn;}
        b[a[n-1]]++;

        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n)if(mn>=b[a[i]]) mn=b[a[i]];
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn+1<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool  f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f1 = F = F1 = false;
        bool f[10000];
        cin >> n;
        ll a[n+1],b[n+1];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        if(n==1){cout<<0<<endl;cn;}
        k=1;
        fr(i,0,n-1){
        if(a[i]==a[i+1])++ans;
        if(a[i]!=a[i+1])b[a[i]]++;
        }
        if(ans==n-1&&a[n-1]==a[n-2]){cout<<0<<endl;cn;}
        b[a[n-1]]++;

        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n)if(mn>=b[a[i]]) mn=b[a[i]];
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn+1<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool  f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f1 = F = F1 = false;
        bool f[10000];
        cin >> n;
        ll a[n+1],b[n+1];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        if(n==1){cout<<0<<endl;cn;}
        k=1;
        fr(i,0,n-1){
        if(a[i]==a[i+1])++ans;
        if(a[i]!=a[i+1])b[a[i]]++;
        }
        if(ans==n-1&&a[n-1]==a[n-2]){cout<<0<<endl;cn;}
        b[a[n-1]]++;|

        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n)if(mn>=b[a[i]]) mn=b[a[i]];
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn+1<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool f, f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f = f1 = F = F1 = false;
        cin >> n;
        ll a[n],b[N2];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        k=1;
        fr(i,0,n-1){if(a[i]!=a[i+1])b[a[i]]++;if(a[i]==a[i+1])++ans;}
        if(ans==n-1&&a[n-1]==a[n-2]){cout<<0<<endl;cn;}
//        if(a[0]==a[1])ans++;
//        if(a[n-2]==a[n-1])ans++;
//        if(ans==n){cout<<0<<endl;cn;}
        if(a[n-2]!=a[n-1]) b[a[n-1]]++;
        f=1;

        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n){
          if(mn>b[a[i]]+1){
            mn=b[a[i]]+1;
            mxa=a[i];
          }
        }
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool f, f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f = f1 = F = F1 = false;
        cin >> n;
        ll a[n],b[N2];
        fr(i,0,n)b[i]=0;
        fr(i,0,n)cin>>a[i];
        k=1;
        fr(i,1,n-1){if(a[i]!=a[i+1])b[a[i]]++;if(a[i]==a[i+1])++ans;}
        if(a[0]==a[1])ans++;
        if(a[n-2]==a[n-1])ans++;
        if(ans==n){cout<<0<<endl;cn;}
      //  b[a[n-1]]++;
       // fr(i,0,n)cout<<b[a[i]]<<" ";
        fr(i,0,n){
          if(mn>b[a[i]]+1){
            mn=b[a[i]]+1;
            mxa=a[i];
          }
        }
        if(mxa==a[0])b[a[0]]--;
        if(mxa==a[n-1])b[a[n-1]]--;
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn<<endl;
    }
    return 0;
}


/**
SVYATOI POINT
⡆⣐⢕⢕⢕⢕⢕⢕⢕⢕⠅⢗⢕⢕⢕⢕⢕⢕⢕⠕⠕⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢐⢕⢕⢕⢕⢕⣕⢕⢕⠕⠁⢕⢕⢕⢕⢕⢕⢕⢕⠅⡄⢕⢕⢕⢕⢕⢕⢕⢕⢕
⢕⢕⢕⢕⢕⠅⢗⢕⠕⣠⠄⣗⢕⢕⠕⢕⢕⢕⠕⢠⣿⠐⢕⢕⢕⠑⢕⢕⠵⢕
⢕⢕⢕⢕⠁⢜⠕⢁⣴⣿⡇⢓⢕⢵⢐⢕⢕⠕⢁⣾⢿⣧⠑⢕⢕⠄⢑⢕⠅⢕
⢕⢕⠵⢁⠔⢁⣤⣤⣶⣶⣶⡐⣕⢽⠐⢕⠕⣡⣾⣶⣶⣶⣤⡁⢓⢕⠄⢑⢅⢑
⠍⣧⠄⣶⣾⣿⣿⣿⣿⣿⣿⣷⣔⢕⢄⢡⣾⣿⣿⣿⣿⣿⣿⣿⣦⡑⢕⢤⠱⢐
⢠⢕⠅⣾⣿⠋⢿⣿⣿⣿⠉⣿⣿⣷⣦⣶⣽⣿⣿⠈⣿⣿⣿⣿⠏⢹⣷⣷⡅⢐
⣔⢕⢥⢻⣿⡀⠈⠛⠛⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⠛⠛⠁⠄⣼⣿⣿⡇⢔
⢕⢕⢽⢸⢟⢟⢖⢖⢤⣶⡟⢻⣿⡿⠻⣿⣿⡟⢀⣿⣦⢤⢤⢔⢞⢿⢿⣿⠁⢕
⢕⢕⠅⣐⢕⢕⢕⢕⢕⣿⣿⡄⠛⢀⣦⠈⠛⢁⣼⣿⢗⢕⢕⢕⢕⢕⢕⡏⣘⢕
⢕⢕⠅⢓⣕⣕⣕⣕⣵⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣷⣕⢕⢕⢕⢕⡵⢀⢕⢕
⢑⢕⠃⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⢕⢕⢕
⣆⢕⠄⢱⣄⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢁⢕⢕⠕⢁
⣿⣦⡀⣿⣿⣷⣶⣬⣍⣛⣛⣛⡛⠿⠿⠿⠛⠛⢛⣛⣉⣭⣤⣂⢜⠕⢑⣡⣴⣿

    author - _PerSik_
*/
#include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define br break
#define cn continue

#define fi first
#define se second

#define sz size()

#define pb push_back
#define CF int t; cin >> t; while(t--)
#define KYF freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)

typedef long long ll;
typedef long long ll;
typedef long double ld;

typedef string str;
typedef stringstream sstr;

typedef bool bl;

const ll N2=1e5*2,N1=1e6,N=1e5,M=1e2,P=1379,NM=1e9;
const ll MIN_LL = LONG_LONG_MIN;
const ll MAX_LL = LONG_LONG_MAX;

ll binpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    CF
    {
        map<ll, ll> mp;
        vector<ll> v;
        ll A;
        ll n, m;
        ll k, g, ans, kol, kol1, kol2, sum;
        g = k = ans = kol = kol1 = kol2 = sum = 0;
        ll x, y, xx, yy;
        ll mn = 1e9;
        ll mx = MIN_LL;
        bool f, f1, F, F1;
        ll mnI=-1;
        ll mxa;
        f = f1 = F = F1 = false;
        cin >> n;
        ll a[n+1],b[n+1];
        fr(i,0,n+1)b[i]=0;
        fr(i,0,n)cin>>a[i];
        k=1;
        fr(i,0,n-1){if(a[i]!=a[i+1])b[a[i]]++;if(a[i]==a[i+1])++ans;}
        if(ans==n-1&&a[n-1]==a[n-2]){cout<<0<<endl;cn;}
        if(a[n-2]!=a[n-1]) b[a[n-1]]++;
        f=1;
        mn=1e19;
        if(b[a[0]]>0)b[a[0]]--;
        if(b[a[n-1]]>0)b[a[n-1]]--;
       // fr(i,0,n){cout<<b[a[i]]<<" ";}cout<<endl;
        fr(i,0,n)if(mn>=b[a[i]]) mn=b[a[i]];
      //  fr(i,0,n)if(b[a[i]]<mn)mn=b[i];
        cout<<mn+1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	map<ll,vll> m;
	for(ll i=0;i<n;i++){
		m[v[i]].pb(i);
	}
	ll ans = 1e15;
	for(auto i: m){
		ll last =0;ll a = 0;
		for(auto j: i.ss){
			//cout<<j<<' ';
			if(j-last-1>0){
				a++;
			}
			last = j;
		}
		if(last!=n-1)
			a++;
		//cout<<endl;
		ans = min(ans,a);
	}
	//cout<<endl;
	if(ans==0 and m.size()>1){
		print(1);
		return;
	}
	print(ans);
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	map<ll,vll> m;
	for(ll i=0;i<n;i++){
		m[v[i]].pb(i);
	}
	ll ans = 1e15;
	for(auto i: m){
		ll last =0;ll a = 0;
		for(auto j: i.ss){
			//cout<<j<<' ';
			if(j!=0 and a==0){
				if(j-last-1>0)
					a++;
				else if(v[j]!=v[last])
					a++;
				last = j;
			}
			if(j-last-1>0){
				a++;
			}
			last = j;
		}
		if(last!=n-1)
			a++;
		//cout<<endl;
		ans = min(ans,a);
	}
	//cout<<endl;
	if(ans==0 and m.size()>1){
		print(1);
		return;
	}
	if(ans==1 and m.size()==1){
		print(0);
		return;
	}
	print(ans);
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	map<ll,vll> m;
	for(ll i=0;i<n;i++){
		m[v[i]].pb(i);
	}
	ll ans = 1e15;
	for(auto i: m){
		ll last =0;ll a = 0;
		for(auto j: i.ss){
			//cout<<j<<' ';
			if(j!=0 and a==0){
				a++;
				last = j;
			}
			if(j-last-1>0){
				a++;
			}
			last = j;
		}
		if(last!=n-1)
			a++;
		//cout<<endl;
		ans = min(ans,a);
	}
	//cout<<endl;
	if(ans==0 and m.size()>1){
		print(1);
		return;
	}
	if(ans==1 and m.size()==1){
		print(0);
		return;
	}
	print(ans);
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	set<int> s;
	for(auto i: v)
		s.insert(i);
	// for(auto i: s)
	// 	cout<<i<<' ';
	ll ans = 1e15;;
	for(auto i: s){
		mll m;
		ll last =0;
		ll s = i;ll a = 0;
		for(ll i=0;i<n;i++){
			if(v[i]==s){
				if(i-last-1>0){
					a++;
				}
				last = i;
			}
		}
		if(last!=n-1)
			a++;
		ans = min(ans,a);
	}
	if(ans==0 and s.size()>1){
		print(1);
		return;
	}
	else if(s.size()==1){
		print(0);
		return;
	}
	cout<<ans<<endl;
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	map<ll,vll> m;
	for(ll i=0;i<n;i++){
		m[v[i]].pb(i);
	}
	ll ans = 1e15;
	for(auto i: m){
		ll last =-1;ll a = 0;
		for(auto j: i.ss){
			if((last+1)!=j)
				a++;
			last= j;
		}
		if(last!=n-1)
			a++;
		ans = min(ans,a);
	}
	if(ans==0 and m.size()>1){
		print(1);
		return;
	}
	if(ans==1 and m.size()==1){
		print(0);
		return;
	}
	print(ans);
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	set<int> s;
	for(auto i: v)
		s.insert(i);
	// for(auto i: s)
	// 	cout<<i<<' ';
	ll ans = 1e15;;
	for(auto i: s){
		mll m;
		ll last =0;
		ll s = i;ll a = 0;
		for(ll i=0;i<n;i++){
			if(v[i]==s and i!=0){
				a++;
				last = i;
				continue;
			}
			if(v[i]==s){
				if(i-last-1>0){
					a++;
				}
				last = i;
			}
		}
		if(last!=n-1)
			a++;
		ans = min(ans,a);
	}
	if(ans==0 and s.size()>1){
		print(1);
		return;
	}
	else if(s.size()==1){
		print(0);
		return;
	}
	cout<<ans<<endl;
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	set<int> s;
	for(auto i: v)
		s.insert(i);
	// for(auto i: s)
	// 	cout<<i<<' ';
	ll ans = 1e15;;
	for(auto i: s){
		mll m;
		ll last =0;
		ll s = i;ll a = 0;
		for(ll i=0;i<n;i++){
			if(v[i]==s){
				if(i-last-1>0){
					a++;
				}
				last = i;
			}
		}
		if(last!=n-1)
			a++;
		ans = min(ans,a);
	}
	if(ans==0 and s.size()>1){
		print(1);
		return;
	}
	else if(ans==0 and s.size()==1){
		print(0);
		return;
	}
	cout<<ans<<endl;
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef map<ll,ll> mll;

typedef vector < pii > vpii;
typedef vector < pll > vpll;

typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef vector< vpii > vvpii;
typedef vector < vpll > vvpll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms;

#define mem(a, b) memset(a, (b), sizeof(a))
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define po pop_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define endl "\n"
#define SZ(x) ((int)x.size())

//debug template
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second);
cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""),
                          __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void FAST_IO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}
ll  binpow(ll a,  ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isprime(int n){
    if(n<=1){return false;}
    if(n<=3){return true;}
    if(n%2==0||n%3==0){return false;}
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0||n%(i+2)==0){return false;}
    }
    return true;
}
void seive(ll n){
	vector<int> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
	    if (is_prime[i]) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	// for(int i=2;i<=n;i++){
	// 	if(is_prime[i])
	// 		ans.pb(i);
	// }
}
map<ll,ll> primeFactors(ll n)
{
	map<ll,ll> m;
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        m[n]++;
    return m;
}

multiset<ll> get_factors(ll n){
	multiset<ll> m;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			if(n/i == i){
				m.insert(i);
			}
			else{
				m.insert(i);
				m.insert(n/i);
			}
		}
	}
	return m;
}

const ld pie = 3.14159265358979323846;
const ll mod = 1000000007;
 //const ll mod = 998244353;
// ll mod;
const ll inf = 1e15;

bool check_palin(ll n){
	ll h = n;
	ll rev =0;
	while(n){
		rev = (rev*10)+ n%10;
		n/=10;
	}
	return (h==rev);
}
// n<=10 -- O(N!) O(N^7) O(N^6)
// n<20 -- O(2^N) o(N^5)
// n<=80 -- O(N^4)
// n<=400 -- O(N^3)
// n<=7500 -- O(N^2)
// n<=10^4 -- O(Nsqrt(N))
// n<=10^5 -- O(NlogN)
// n<=10^6 -- O(N)
// n<=10^18 -- O(logN) O(1)
ll  C(int n,int m)
{
	ll z=1;
	for(int i=0;i<m;i++){
		z = z* (n-i)/(i+1);
		print(z);
	}
	return z;
}

void solve(){
	ll n;
	cin>>n;
	vll v(n);
	for(auto &i: v)
		cin>>i;
	set<int> s;
	for(auto i: v)
		s.insert(i);
	// for(auto i: s)
	// 	cout<<i<<' ';
	ll ans = 1e15;;
	for(auto i: s){
		ll j =0;
		ll flag = 0;ll ele = i;ll a = 0;
		for(ll i=0;i<n;i++){
			ll j = i;
			while(j<n and v[j]!=ele){
				j++;
				flag = 1;
			}
			if(flag){
				a++;
				i = j-1;
				flag = 0;
			}
		}
		ans = min(ans,a);
	}
	cout<<ans<<endl;
}

int32_t main()
{
    FAST_IO();
	ll t;
	cin>>t;
	while(t--) solve();
}