#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define f(i, v, n) for (ll i = v; i < n; ++i)
#define loop(t) while (t--)
#define pb push_back
#define ft first
#define sd second
#define ps pair<string, string>
#define pc pair<char, char>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define psi pair<string, int>
#define pis pair<int, string>
#define pci pair<char, int>
#define pic pair<int, char>
#define psll pair<string, ll>
#define plls pair<ll, string>
#define pill pair<int, ll>
#define plli pair<ll, int>

#define vll vector<ll>
#define vi vector<int>
#define vstr vector<string>
#define vpi vector<pi>
#define um(a, b) unordered_map<a, b>
#define ull unordered_map<ll, ll>
#define ui unordered_map<int, int>
#define uci um(char, int)
#define usi um(string, int)
#define si stack<int>
#define sll stack<ll>
#define qi queue<int>
#define qll queue<ll>
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test int t;cin >> t; while(t--)
#define pr(a) f (i, 0, a.size()) cout << a[i] << " "; cout << "\n";
// #define prAll(a) f (i, 0, a.size()) {try{if(a[i]){cout << a[i] << " ";}}catch(...){cout << a[i].ft << " " << a[i].sd << "\n";}} cout << "\n";
#define prpair(v) f (i, 0, v.size()) cout << v[i].ft << " " << v[i].sd << "\n";
#define sortA(v) sort(v.begin(), v.end());
#define sortD(v) sort(v.begin(), v.end(), comp);
#define mkp make_pair
// static int __=[](){std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);return 0;}();
template <typename T>
bool comp(T i, T j) {
	try {
		return i > j;
	}
	catch(...) {
		try {
			return i.ft > i.sd;
		}
		catch(...) {
			cout << "Something went bad in sorting's comparison!\n";
		}
	}
}

int n, k, p, q, r, mx = 10005;
string s;

int main(int argc, char const *argv[])
{
	fast
	vi v;
	ui u;
	int ans;
	test {
		cin >> n;
		v.clear();
		v.resize(n);
		u.clear();


		f (i, 0, n) {
			cin >> v[i];

			
		}

		int j = 0;
		f (i, 0, n) {

			while (i < n - 1) {
				if (v[i + 1] != v[i])
					break;
				i++;
			}
		
			if (u.find(v[i]) == u.end()) {
				if (i == n - 1 || j == 0)
					u[v[i]] = 1;
				else
					u[v[i]] = 2;
			}
			else {
				if (i != n - 1)
					u[v[i]]++;
			}
			j++;
		}

		if (n == 1) {
			cout << "0\n";
			continue;
		}

		if (u.size() == 1)
			cout << "0\n";
		else if (u.size() == n)
			cout << "1\n";
		else {
			ans = INT_MAX;
			// cout << "map\n";
			for (auto x : u) {
				// cout << x.ft << " " << x.sd << "\n";
				ans = min(ans, x.sd);
			}
			cout << ans << "\n";
		}
		// pr(v);
	}
	return 0;
}
