You are given a sequence $a$, initially consisting of $n$ integers.

You want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the same element).

To achieve this, you choose some integer $x$ that occurs at least once in $a$, and then perform the following operation any number of times (possibly zero): choose some segment $[l, r]$ of the sequence and remove it. But there is one exception: you are not allowed to choose a segment that contains $x$. More formally, you choose some contiguous subsequence $[a_l, a_{l + 1}, \dots, a_r]$ such that $a_i \ne x$ if $l \le i \le r$, and remove it. After removal, the numbering of elements to the right of the removed segment changes: the element that was the $(r+1)$-th is now $l$-th, the element that was $(r+2)$-th is now $(l+1)$-th, and so on (i. e. the remaining sequence just collapses).

Note that you can not change $x$ after you chose it.

For example, suppose $n = 6$, $a = [1, 3, 2, 4, 1, 2]$. Then one of the ways to transform it in two operations is to choose $x = 1$, then:

choose $l = 2$, $r = 4$, so the resulting sequence is $a = [1, 1, 2]$;

choose $l = 3$, $r = 3$, so the resulting sequence is $a = [1, 1]$.

Note that choosing $x$ is not an operation. Also, note that you can not remove any occurrence of $x$.

Your task is to find the minimum number of operations required to transform the sequence in a way described above.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer — the minimum number of operations required to transform the given sequence in a way described in the problem statement. It can be proven that it is always possible to perform a finite sequence of operations so the sequence is transformed in the required way.


-----Examples-----

Input
5
3
1 1 1
5
1 2 3 4 5
5
1 2 3 2 1
7
1 2 3 1 2 3 1
11
2 2 1 2 3 2 1 2 3 1 2
Output
0
1
1
2
3


-----Note-----

None

Difficulty: EASY

Solutions:
for i in range(int(input())):
	n = int(input())
	a = [10000000000.0] + list(map(int, input().split()))
	sp = [1000000000.0] * (n + 1)
	for j in range(1, n + 1):
		if a[j] != a[j - 1]:
			if sp[a[j]] == 1000000000.0:
				sp[a[j]] = 1
			else:
				sp[a[j]] += 1
	c = min(sp)
	if c == 1000000000.0:
		print(0)
	else:
		for j in range(n):
			if abs(sp[j + 1] - c) == 1 and a[1] == j + 1 and (a[-1] == j + 1) or (abs(sp[j + 1] - c) == 0 and (a[1] == j + 1 or a[-1] == j + 1)):
				if abs(sp[j + 1] - c) == 0 and (a[1] == j + 1 and a[-1] == j + 1):
					c -= 2
				else:
					c -= 1
		print(c + 1)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		arr = [[] for _ in range(n + 1)]
		for (ind, i) in enumerate(a):
			arr[i].append(ind)
		ans = 10 ** 10
		for i in range(n + 1):
			if len(arr[i]):
				z = int(arr[i][0] != 0)
				for j in range(1, len(arr[i])):
					if arr[i][j] - arr[i][j - 1] > 1:
						z += 1
				z += arr[i][-1] != n - 1
				ans = min(ans, z)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, exit, setrecursionlimit
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	n = int(input())
	a = lmi()
	if len(set(a)) == 1:
		print(0)
		continue
	freq = {a[0]: 0}
	for i in range(1, n):
		if a[i] not in freq:
			freq[a[i]] = 0
		if a[i] != a[i - 1]:
			freq[a[i]] += 1
	freq[a[n - 1]] -= 1
	mx = float('inf')
	for i in freq:
		mx = min(mx, freq[i])
	print(mx + 1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	flag = 0
	for i in range(1, n):
		if l[i] != l[i - 1]:
			flag = i
			break
	d[l[0]] = 1
	if flag != 0:
		for i in range(flag, n - 1):
			if l[i] != l[i + 1]:
				if l[i] not in d:
					d[l[i]] = 2
				else:
					d[l[i]] += 1
		if l[-1] not in d:
			d[l[-1]] = 1
		we = 9999999
		for i in d:
			we = min(we, d[i])
		print(we)
	else:
		print(0)


from itertools import groupby
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [x[0] for x in groupby(a)]
	c = Counter(a)
	d = {}
	for e in a:
		if e in d:
			continue
		num_seg = c[e]
		sub = 0
		if a[0] == e:
			sub += 1
		if a[-1] == e:
			sub += 1
		d[e] = num_seg + 1 - sub
	print(min(d.values()))


import sys
from collections import Counter

def solve(n, A):
	B = [A[0]]
	for a in A[1:]:
		if a == B[-1]:
			continue
		B.append(a)
	c = Counter(B)
	ans = n + 10
	for (k, v) in c.items():
		v += 1
		if k == A[0]:
			v -= 1
		if k == A[-1]:
			v -= 1
		if v < ans:
			ans = v
	return ans

def main():
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		print(solve(n, A))
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for j in range(n):
		if l[j] in d:
			d[l[j]].append(j)
		else:
			d[l[j]] = [j]
	min = -1
	for j in d:
		c = 0
		if d[j][0] != 0:
			c += 1
		if d[j][-1] != n - 1:
			c += 1
		for k in range(len(d[j]) - 1):
			if d[j][k] - d[j][k + 1] != -1:
				c += 1
		if c < min or min == -1:
			min = c
	print(min)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, lst):
	if len(set(lst)) == 1:
		return 0
	lst.append('a')
	lst1 = []
	for i in range(n):
		if lst[i] != lst[i + 1]:
			lst1.append(lst[i])
	lst = lst1.copy()
	n = len(lst)
	pos = {}
	for i in range(n):
		if i != 0 and i != n - 1:
			if pos.get(lst[i]) == None:
				pos[lst[i]] = [i]
			else:
				pos[lst[i]].append(i)
	ans = float('inf')
	for i in pos:
		cnt = 0
		if len(pos[i]) == 1:
			cnt = 2
		else:
			cnt += 2
			for j in range(len(pos[i]) - 1):
				if pos[i][j] + 1 != pos[i][j + 1]:
					cnt += 1
		ans = min(ans, cnt)
	pos = {}
	for i in range(n):
		if pos.get(lst[i]) == None:
			pos[lst[i]] = [i]
		else:
			pos[lst[i]].append(i)
	for i in pos:
		if len(pos[i]) == 1 and (pos[i][0] == 0 or pos[i][0] == n - 1):
			ans = min(ans, 1)
		elif len(pos[i]) == 2 and pos[i][0] == 0 and (pos[i][-1] == n - 1):
			ans = min(ans, 1)
	return ans
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = []
	for j in range(n):
		if j == 0 or A[j] != A[j - 1]:
			B.append(A[j])
	C = [-2] * n
	flag = n
	for j in range(len(B)):
		if C[B[j] - 1] == -2:
			C[B[j] - 1] = 0
		C[B[j] - 1] += 1
	C[B[0] - 1] -= 1
	C[B[-1] - 1] -= 1
	for j in range(n):
		if C[j] != -2 and C[j] < flag:
			flag = C[j]
	print(flag + 1)


from collections import Counter

def g(l):
	lf = [l[0]]
	for i in range(1, len(l)):
		if l[i] != l[i - 1]:
			lf.append(l[i])
	dicto = Counter(lf)
	dicto[lf[0]] -= 1
	dicto[lf[-1]] -= 1
	if len(lf) == 1:
		return '0'
	else:
		k = min(list(dicto.values()))
		return str(k + 1)
t = input()
no = int(t)
s = ''
for i in range(no):
	r1 = input()
	r2 = input().split(' ')
	km = list(map(int, r2))
	s += g(km) + '\n'
print(s)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = [-1] * (a + 1)
	for i in range(a):
		if c[b[i]] == -1:
			c[b[i]] = 0
		if i != 0:
			if b[i] != b[i - 1]:
				c[b[i]] += 1
	for i in range(a + 1):
		if c[i] != -1:
			if i != b[-1]:
				c[i] += 1
	minn = float('inf')
	for i in c:
		if i != -1:
			if i < minn:
				minn = i
	print(minn)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	bb = [aa[0]]
	for a in aa[1:]:
		if bb[-1] != a:
			bb.append(a)
	counts = {}
	for b in bb:
		counts[b] = counts.get(b, 0) + 1
	for b in counts.keys():
		if bb[0] != b:
			counts[b] += 1
		if bb[-1] != b:
			counts[b] += 1
	print(min(counts.values()) - 1)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	array = []
	for _ in range(n):
		size = int(input())
		arr = [*map(int, input().split())]
		counter = 9 ** 9
		optim = [[] for i in range(size)]
		for (i, val) in enumerate(arr):
			optim[val - 1].append(i)
		for val in optim:
			if len(val) == 0:
				continue
			count = 0
			if val[0] != 0:
				count = 1
			for (val1, val2) in zip(val[:-1], val[1:]):
				if val2 - val1 > 1:
					count += 1
			if val[-1] != size - 1:
				count += 1
			counter = min(counter, count)
		array.append(counter)
	for i in array:
		print(i)
main()


from collections import Counter

def main(xs):
	xs2 = [xs[0]]
	for i in range(1, len(xs)):
		if xs2[-1] != xs[i]:
			xs2.append(xs[i])
	counter = Counter(xs2)
	for (k, v) in counter.items():
		counter[k] += 1
	counter[xs2[0]] -= 1
	counter[xs2[-1]] -= 1
	first = True
	for (k, v) in counter.items():
		if first:
			m = v
			first = False
		elif v < m:
			m = v
	if m < 0:
		return 0
	else:
		return m
t = int(input())
for _ in range(t):
	input()
	as_ = [int(x) for x in input().split()]
	res = main(as_)
	print(res)

def test1():
	assert True == False

def test2():
	assert True == False

def test_min():
	assert True == False

def test_max():
	assert True == False


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = [arr[0]]
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			a.append(arr[i])
	n = len(a)
	if n == 1:
		print(0)
		continue
	c = Counter(a)
	for no in c:
		c[no] += 1
	c[a[0]] -= 1
	c[a[n - 1]] -= 1
	ops = min((c[no] for no in c))
	print(ops)


from collections import *
from itertools import *
for s in [*open(0)][2::2]:
	a = s.split()
	c = Counter((k for (k, g) in groupby(a)))
	print(min((c[x] - 1 + (x != a[0]) + (x != a[-1]) for x in c)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	last = -1
	lst = []
	for i in range(n):
		if a[i] != last:
			lst.append(a[i])
			last = a[i]
	ln = len(lst)
	hmmm = {}
	for i in range(ln):
		x = lst[i]
		if i == 0:
			hmmm[x] = 1
		elif i == ln - 1:
			if x not in hmmm:
				hmmm[x] = 1
		elif x in hmmm:
			hmmm[x] += 1
		else:
			hmmm[x] = 2
	ans = 10 ** 9
	for i in hmmm:
		ans = min(hmmm[i], ans)
	if ln == 1:
		print(0)
	else:
		print(ans)


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	d = dict()
	for (i, v) in enumerate(a):
		if v in d:
			if d[v][-1][1] == i:
				d[v][-1][1] = i + 1
			else:
				d[v].append([i, i + 1])
		else:
			d[v] = [[i, i + 1]]
	if len(d) == 1:
		print(0)
		continue
	m = float('inf')
	for v in d:
		c = 0
		if d[v][0][0] != 0:
			c += 1
		if d[v][-1][1] != len(a):
			c += 1
		c += len(d[v]) - 1
		m = min(m, c)
	print(m)


def smp(nums):
	return [a for (a, b) in zip(nums, nums[1:] + [not nums[-1]]) if a != b]
t = int(input())
ans = ''
for j in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	cnt = [1] * (n + 1)
	x = smp(x)
	n = len(x)
	for i in range(n):
		cnt[x[i]] += 1
	inicial = x[0]
	final = x[n - 1]
	cnt[inicial] -= 1
	cnt[final] -= 1
	res = 2 * 10 ** 5
	for i in range(n):
		res = min(res, cnt[x[i]])
	ans = ans + str(res) + '\n'
print(ans)


from collections import Counter

def solve(n, arr):
	count = Counter(arr)
	count[arr[-1]] -= 1
	count[arr[0]] -= 1
	if len(count) == 1:
		return 0
	mincost = 999999
	for i in range(1, n):
		if arr[i - 1] == arr[i]:
			count[arr[i]] -= 1
	for key in count.keys():
		mincost = min(mincost, count[key] + 1)
	return mincost
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	z = 1
	while z < len(a):
		if a[z] == a[z - 1]:
			del a[z - 1]
			z -= 1
		z += 1
	l = len(a)
	if l == 1:
		print(0)
	else:
		d = {}
		for z in range(l):
			if a[z] in d:
				d[a[z]] += 1
			else:
				d[a[z]] = 1
		if len(d) == l:
			print(1)
		else:
			ans = 10 ** 20
			if a[0] == a[l - 1]:
				d[a[0]] -= 2
			else:
				d[a[0]] -= 1
				d[a[l - 1]] -= 1
			for z in range(l):
				ans = min(ans, d[a[z]] + 1)
			print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ind = {}
	for i in range(n):
		try:
			ind[a[i]].append(i)
		except KeyError:
			ind[a[i]] = [i]
	mindiv = 10 ** 6
	for v in ind:
		divs = 0
		for i in range(len(ind[v])):
			if ind[v][i] != 0:
				if i == 0:
					divs += 1
				elif abs(ind[v][i - 1] - ind[v][i]) != 1:
					divs += 1
			if i == len(ind[v]) - 1:
				if ind[v][i] != n - 1:
					divs += 1
		if divs < mindiv:
			mindiv = divs
	print(mindiv)


t = int(input())
for _ in range(t):
	n = int(input())
	possibilities = {}
	once = False
	previous = None
	for number in input().split(' '):
		temp = int(number)
		if temp != previous:
			if temp in possibilities:
				possibilities[temp] += 1
			elif ~once:
				possibilities[temp] = 1
				once = ~once
			else:
				possibilities[temp] = 2
		previous = temp
	possibilities[temp] -= 1
	print(possibilities[min(possibilities, key=possibilities.get)])


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	o = {x[0]: [0]}
	for i in range(1, n):
		if x[i] in o:
			o[x[i]].append(i)
		else:
			o[x[i]] = [i]
	m = n
	if len(o) == 1:
		print(0)
	else:
		for (k, l) in o.items():
			ans = 0
			for i in range(1, len(l)):
				if l[i - 1] + 1 < l[i]:
					ans += 1
			if 0 not in l:
				ans += 1
			if n - 1 not in l:
				ans += 1
			m = min(m, ans)
		print(m)


from sys import stdin
input = stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	last = defaultdict(int)
	for i in range(n):
		if l[i] not in d:
			d[l[i]] += 1
		elif last[l[i]] != i - 1:
			d[l[i]] += 1
		last[l[i]] = i
	if len(d) == 1:
		print(0)
	else:
		d[l[0]] -= 1
		d[l[-1]] -= 1
		print(d[min(d, key=d.get)] + 1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	d[a[0]] = 1
	if n == 2:
		if len(set(a)) == 1:
			print(0)
		else:
			print(1)
	else:
		for i in range(1, n):
			if a[i] != a[i - 1]:
				if a[i] not in d.keys():
					d[a[i]] = 1
				else:
					d[a[i]] += 1
		ans = 10000000
		for (key, value) in d.items():
			if value == n:
				ans = 0
			elif a[0] == key and a[n - 1] == key:
				ans = min(ans, value - 1)
			elif a[0] == key or a[n - 1] == key:
				ans = min(ans, value)
			else:
				ans = min(ans, value + 1)
		print(ans)


a = int(input())
import math
from collections import *
for i in range(a):
	s = int(input())
	ans = list(map(int, input().split()))
	z = [ans[0]]
	for i in range(1, len(ans)):
		if ans[i] != z[-1]:
			z.append(ans[i])
	if z.count(z[0]) == len(z):
		print(0)
		continue
	elif z.count(z[0]) == 1 or z.count(z[-1]) == 1:
		print(1)
		continue
	else:
		al = defaultdict(int)
		for i in range(len(z)):
			al[z[i]] += 1
		mini = math.inf
		for i in al:
			if i != z[0] or i != z[-1]:
				mini = min(mini, al[i] + 1)
		if z[0] == z[-1]:
			print(min(mini, al[z[0]] - 1))
		else:
			print(min(mini, al[z[0]], al[z[-1]]))


from sys import stdin
loop = int(stdin.readline())
for lo in range(loop):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list()
	b.append(a[0])
	for i in range(1, len(a)):
		if a[i] != b[-1]:
			b.append(a[i])
	d = dict()
	for e in b:
		if e in d.keys():
			d[e] = d[e] + 1
		else:
			d.update({e: 1})
	d[b[0]] = d[b[0]] - 1
	d[b[-1]] = d[b[-1]] - 1
	print(min(d.values()) + 1)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 7
t = int(input())
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def z_array(s1):
	n = len(s1)
	z = [0] * n
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and s1[r - l] == s1[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and s1[r - l] == s1[r]:
					r += 1
				z[i] = r - l
				r -= 1
	return z

def solve():
	d = {}
	for i in l:
		d[i] = []
	for i in range(n):
		d[l[i]].append(i)
	mini = n + 1
	for i in d:
		cnt = 0
		if d[i][0] != 0:
			cnt += 1
		if d[i][-1] != n - 1:
			cnt += 1
		for j in range(len(d[i]) - 1):
			if d[i][j + 1] - d[i][j] > 1:
				cnt += 1
		mini = min(mini, cnt)
	return mini
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve())


t = int(input())
for test in range(0, t):
	n = int(input())
	lis = list(map(int, input().split()))
	fin_lis = []
	fin_lis.append(lis[0])
	for i in range(1, n):
		if lis[i] != lis[i - 1]:
			fin_lis.append(lis[i])
	dic = {}
	for i in range(0, len(fin_lis)):
		dic[fin_lis[i]] = 0
	dic[fin_lis[0]] -= 1
	dic[fin_lis[len(fin_lis) - 1]] -= 1
	for i in fin_lis:
		dic[i] += 1
	for (k, v) in dic.items():
		dic[k] += 1
	print(min(dic.values()))


from collections import Counter

def solve(n, seq):
	simplified = [seq[0]]
	for i in range(1, n):
		if seq[i - 1] != seq[i]:
			simplified.append(seq[i])
	if len(simplified) == 1:
		return 0
	score = {simplified[0]: 1, simplified[-1]: 1}
	for i in range(1, len(simplified) - 1):
		if simplified[i] not in score.keys():
			score[simplified[i]] = 1
		score[simplified[i]] += 1
	return min(score.values())
for t in range(int(input())):
	n = int(input())
	seq = list(map(int, input().split()))
	print(solve(n, seq))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(5 * 10 ** 5)
inf = 10 ** 20
mod = 10 ** 9 + 7
from math import gcd

def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def lcm(a, b):
	tmp = a * b // gcd(a, b)
	return tmp

def solve():
	n = II()
	a_list = LI()
	short_a = a_list[0:1]
	for i in range(1, n):
		a = a_list[i]
		if a != short_a[-1]:
			short_a.append(a)
	cnts_dict = collections.Counter(short_a)
	if len(cnts_dict) == 1:
		return 0
	ans = inf
	for (k, v) in cnts_dict.items():
		if short_a[0] == k:
			v -= 1
		if short_a[-1] == k:
			v -= 1
		ans = min(ans, max(1, v + 1))
	return ans

def main():
	t = II()
	res = list()
	for _ in range(t):
		res.append(solve())
	for ans in res:
		print(ans)
	return 0
main()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sa = []
	sa.append(a[0])
	for i in range(1, n):
		if a[i] != a[i - 1]:
			sa.append(a[i])
	count = dict(Counter(sa))
	sa_len = len(sa)
	for i in count:
		count[i] += 1
	count[sa[0]] -= 1
	count[sa[sa_len - 1]] -= 1
	ans = 2 * 10 ** 5
	for i in count:
		ans = min(ans, count[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	u = {a: 0 for a in arr}
	b = 0
	for i in arr:
		if i != b:
			b = i
			u[i] += 1
	u[arr[0]] -= 1
	u[arr[-1]] -= 1
	print(min(u.values()) + 1)


from itertools import groupby
t = int(input())
for i in range(t):
	n = int(input())
	w = [int(k) for k in input().split()]
	w = groupby(w)
	c = [k[0] for k in w]
	z = len(c)
	q = {j: 1 for j in c}
	for j in range(z):
		if j != 0 and j != z - 1:
			q[c[j]] += 1
	if z == 1:
		print(0)
	else:
		print(min(list(q.values())))


for i in range(int(input())):
	n = int(input())
	data = input().split()
	process = list(set(data))
	counter = {j: 1 for j in process}
	for j in range(n - 1):
		if data[j] != data[j + 1]:
			counter[data[j]] += 1
	counter[data[n - 1]] += 1
	counter[data[0]] -= 1
	counter[data[n - 1]] -= 1
	print(max(min(counter.values()), 0))


def myDupli(arr):
	i = 0
	j = 0
	n = len(arr)
	tot_length = n
	for j in range(n):
		if j + 1 < n and arr[j] == arr[j + 1]:
			tot_length -= 1
		else:
			arr[i] = arr[j]
			i += 1
	return arr[:tot_length]

def solve():
	n = int(sys.stdin.readline().strip())
	array = list(map(int, sys.stdin.readline().strip().split()))
	array = myDupli(array)
	map_my = {}
	n = len(array)
	if n == 1:
		return 0
	first_occurence = [False] * len(array)
	for i in range(len(array)):
		if array[i] not in map_my:
			map_my[array[i]] = 0
			first_occurence[i] = True
	map_my[array[0]] += 1
	for i in range(1, len(array)):
		add = 0
		if first_occurence[i] is True:
			if i != len(array) - 1:
				add = 2
			else:
				add = 1
		elif i != len(array) - 1:
			add = 1
		map_my[array[i]] += add
	min_val = float('inf')
	for i in map_my.keys():
		min_val = min(map_my[i], min_val)
	return min_val
import sys
t = int(sys.stdin.readline().strip())
for test in range(t):
	print(solve())


def nr():
	return nrs()[0]

def nrs():
	return [int(i) for i in input().split()]

def group(arr):
	lastitem = -1
	res = []
	for item in arr:
		if item != lastitem:
			res.append(item)
			lastitem = item
	return res

def f(arr):
	arr = group(arr)
	freq = {}
	for item in set(arr):
		freq[item] = []
	for (i, item) in enumerate(arr[1:-1]):
		freq[item].append(i)
	table = [[len(freq[key]), key] for key in freq]
	if len(table) == 1:
		return 0
	return min(table)[0] + 1
for _ in range(nr()):
	_ = nr()
	print(f(nrs()))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		arr = get_list()
		dic = dict()
		for i in range(n):
			if i == 0:
				dic[arr[i]] = 1
			elif arr[i] != arr[i - 1]:
				if arr[i] not in dic:
					dic[arr[i]] = 1
				else:
					dic[arr[i]] += 1
		ans = maxsize
		for (i, j) in dic.items():
			summ = j + 1
			if arr[0] == i:
				summ -= 1
			if arr[-1] == i:
				summ -= 1
			ans = min(ans, summ)
		get_print_int(ans)
solve()


for tt in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {arr[0]: 0, arr[-1]: -1}
	prev = arr[0]
	for i in arr:
		if i in d:
			if i != prev:
				d[i] += 1
				prev = i
		else:
			d[i] = 1
			prev = i
	print(min(d.values()) + 1)


for _ in range(int(input())):
	n = int(input())
	a = []
	c = {}
	for x in map(int, input().split()):
		if not a or a[-1] != x:
			a.append(x)
			c[x] = c.get(x, 0) + 1
	d = len(a)
	for x in c:
		d = min(d, c[x] - 1 + (a[0] != x) + (a[-1] != x))
	print(d)


from collections import Counter

def solve(a):
	mp = {}
	mp[a[0]] = 0
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			continue
		if a[i] not in mp:
			mp[a[i]] = 1
		else:
			mp[a[i]] += 1
	for i in mp:
		if i != a[-1]:
			mp[i] += 1
	Min = float('inf')
	for i in mp:
		Min = min(Min, mp[i])
	return Min
t = int(input())
ans = []
while t > 0:
	_ = int(input(''))
	a = list(map(int, input().split()))
	ans.append(solve(a))
	t -= 1
for i in ans:
	print(i)


import math, sys

def bin_search(arr, x):
	if len(arr) == 1:
		if arr[0] == x:
			return (True, 0)
	if x > arr[-1]:
		return (False, len(arr))
	elif x < arr[0]:
		return (False, -1)
	(beg, end) = (0, len(arr) - 1)
	while beg <= end:
		mid = (beg + end) // 2
		if arr[mid] == x:
			return (True, mid)
		elif x > arr[mid]:
			if x < arr[mid + 1]:
				return (False, mid + 1)
			else:
				beg = mid + 1
		elif x > arr[mid - 1]:
			return (False, mid - 1)
		else:
			end = mid - 1
t = int(input())
for i in range(t):
	N = int(input())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	n_arr = []
	for i in range(len(arr)):
		if len(n_arr) == 0 or n_arr[-1] != arr[i]:
			n_arr.append(arr[i])
	int_list = sorted(list(set(n_arr)))
	p_list = [[] for i in range(len(int_list))]
	for indx in range(len(n_arr)):
		pos = bin_search(int_list, n_arr[indx])[1]
		p_list[pos].append(indx)
	min_cost = N
	for lst in p_list:
		tmp_cost = 0
		if lst[0] != 0:
			tmp_cost += 1
		if lst[-1] != len(n_arr) - 1:
			tmp_cost += 1
		if len(lst) > 1:
			tmp_cost += len(lst) - 1
		min_cost = min(min_cost, tmp_cost)
	print(min_cost)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	dict1 = {}
	arr = inlt()
	for i in range(n):
		if arr[i] not in dict1:
			if i == 0:
				dict1[arr[i]] = [0, i]
			else:
				dict1[arr[i]] = [1, i]
			if i == n - 1:
				dict1[arr[i]][0] -= 1
		else:
			if i - dict1[arr[i]][1] != 1:
				dict1[arr[i]][0] += 1
			dict1[arr[i]][1] = i
			if i == n - 1:
				dict1[arr[i]][0] -= 1
	d = sorted(dict1, key=lambda x: dict1[x][0])
	print(dict1[d[0]][0] + 1)


from sys import stdin
from math import log2
input = lambda : stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	n = int(input())
	alb = list(map(int, input().split()))
	a = [alb[0]]
	for i in alb:
		if a[-1] != i:
			a.append(i)
	lol = [0]
	ans = {}
	n = len(a)
	if n == 1:
		print(0)
		continue
	for i in range(n):
		el = a[i]
		if i == 0:
			ans[el] = 1
		elif i == n - 1:
			ans[el] = ans.get(el, 1)
		elif el in ans:
			ans[el] += 1
		else:
			ans[el] = 2
	print(min(ans.values()))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0]
	for i in a:
		if b[-1] != i:
			b.append(i)
	b = b[1:]
	d = dict()
	if len(b) == 1:
		print(0)
	else:
		for i in range(len(b)):
			if b[i] in d:
				d[b[i]] += 1
			elif i == 0:
				d[b[i]] = 0
			else:
				d[b[i]] = 1
		x = n
		for i in d:
			if i != b[-1]:
				d[i] += 1
			x = min(x, d[i])
		print(x)


for _ in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().split()]
	a = A[0]
	d = {}
	d[a] = 1
	for i in A[1:]:
		if i != a:
			d[i] = d.get(i, 0) + 1
			a = i
	d[A[0]] -= 1
	d[A[-1]] -= 1
	if len(d) == 0:
		print('0')
	else:
		print(min(d.values()) + 1)


def counts(arr):
	stat = []
	n = len(arr)
	curr = 0
	for i in arr:
		if stat == [] or i != curr:
			stat.append(i)
		curr = i
	if len(stat) == 1:
		return 0
	uniq = {}
	for i in stat:
		uniq[i] = 1 if i not in uniq.keys() else uniq[i] + 1
	for i in uniq.keys():
		uniq[i] += 1
	uniq[stat[0]] -= 1
	uniq[stat[-1]] -= 1
	min_is = uniq[stat[0]]
	for i in uniq.keys():
		if uniq[i] < min_is:
			min_is = uniq[i]
	return min_is

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().strip().split()))
		ind = counts(arr)
		print(ind)
main()


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	D = {a: 0 for a in li}
	last = li[0]
	for i in li[1:]:
		if i != last:
			D[i] += 1
		last = i
	for k in D:
		if k != last:
			D[k] += 1
	print(min(D.values()))


def main_function():
	tests = range(int(input()))
	for test in tests:
		n = int(input())
		a = [int(i) for i in input().split(' ')]
		hash_table = {}
		current_value = a[0]
		for i in range(len(a)):
			if a[i] != current_value:
				prev_item = current_value
				current_value = a[i]
				if current_value in hash_table:
					pass
				else:
					hash_table[current_value] = 1
				if prev_item in hash_table:
					hash_table[prev_item] += 1
				else:
					hash_table[prev_item] = 1
		if len(hash_table) == 0:
			print(0)
		else:
			print(min([hash_table[i] for i in hash_table]))
main_function()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	last = None
	open = set()
	for i in range(n):
		if last is not None and last != a[i]:
			if d.get(a[i]):
				d[a[i]] += 1
			else:
				d[a[i]] = 1
		open.add(a[i])
		last = a[i]
	open.remove(last)
	for i in open:
		if d.get(i):
			d[i] += 1
		else:
			d[i] = 1
	if d:
		print(min(d.values()))
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = {}
	for x in a:
		if x in c:
			c[x] += 1
		else:
			c[x] = 1
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			c[a[i]] -= 1
	c[a[0]] -= 1
	c[a[-1]] -= 1
	print(min(c.values()) + 1)


def unique(arr):
	new = []
	c = arr[0]
	for i in arr[1:]:
		if i != c:
			new.append(c)
			c = i
	new.append(c)
	return new

def logic(arr):
	n = len(arr)
	if n == 1:
		return 0
	counts = {}
	f = arr[0]
	l = arr[-1]
	counts[f] = 1
	if f != l:
		counts[l] = 1
	for i in arr[1:-1]:
		if i in counts:
			counts[i] += 1
		else:
			counts[i] = 2
	m = n
	for key in counts:
		v = counts[key]
		if v < m:
			m = v
	return m
i = input()
for w in range(0, int(i)):
	input()
	arr = unique([int(x) for x in input().split()])
	print(logic(arr))


import os
from collections import Counter, defaultdict
from io import BytesIO, IOBase
import math
import sys

class SortedList:

	def __init__(self, iterable=None, _load=200):
		if iterable is None:
			iterable = []
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def primes(n, k):
	z = []
	x = 1
	while n % 2 == 0:
		x *= 2
		n = n // 2
	if x > 1:
		z.append(x)
	for i in range(3, math.ceil(math.sqrt(n)), 2):
		x = 1
		while n % i == 0:
			x *= i
			n = n // i
		if x > 1:
			z.append(x)
	if n > 2:
		z.append(n)
	n = len(z)
	x = SortedList(z)
	while n > k:
		if n - k > 1:
			a = x.pop(0)
			b = x.pop()
		else:
			a = x.pop(0)
			b = x.pop(0)
		n -= 1
		x.add(a * b)
	return list(x)

def main():
	for i in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		z = defaultdict(lambda : 0)
		for j in range(1, n - 1):
			z[a[j]] = 0
		z[a[0]] = 1
		z[a[-1]] = 0
		end = defaultdict(lambda : -1)
		for j in range(n):
			if j - end[a[j]] > 1:
				z[a[j]] += 1
			end[a[j]] = j
		m = 10000000000
		for j in z:
			if j != a[-1] and j != a[0]:
				z[j] += 1
			m = min(z[j], m)
		if len(set(a)) == 1:
			print(0)
		else:
			print(m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [0] * n
	dummy = arr[0]
	for i in range(1, n):
		if arr[i] == dummy:
			continue
		elif arr[i] != dummy:
			dp[dummy - 1] += 1
			if dp[arr[i] - 1] == 0:
				dp[arr[i] - 1] += 1
			dummy = arr[i]
	a = max(dp)
	b = min(dp)
	test = n
	if a == 0 and b == 0:
		print(0)
		continue
	else:
		for i in dp:
			if i < test and i != 0:
				test = i
		print(test)


for some in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	lis_new = []
	d = dict()
	lis_new.append(lis[0])
	d[lis_new[0]] = 2
	k = lis[0]
	for i in range(1, n):
		if lis[i] == k:
			continue
		lis_new.append(lis[i])
		k = lis[i]
		if lis_new[-1] in d:
			d[lis_new[-1]] += 1
		else:
			d[lis_new[-1]] = 2
	d[lis_new[0]] -= 1
	d[lis_new[-1]] -= 1
	print(min(d.values()))


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	D = {a: 0 for a in A}
	last = A[0]
	for a in A[1:]:
		if a != last:
			D[a] += 1
		last = a
	for k in D:
		if k != last:
			D[k] += 1
	print(min(D.values() or [0]))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for j in range(n - 1):
		if a[j] not in d:
			if j == 0:
				d[a[j]] = 0
			else:
				d[a[j]] = 1
			if a[j] != a[j + 1]:
				d[a[j]] += 1
		elif a[j] != a[j + 1]:
			d[a[j]] += 1
	if d == {}:
		print(0)
	elif a[-1] not in d:
		print(1)
	else:
		print(min(d.values()))


from sys import stdin, stdout
input = stdin.readline
t = int(input())
from collections import Counter
from math import sqrt, ceil

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qrr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(slr - dpr + 1, slr + 1):
		qlr = qlr * ip % mod
	for ij in range(1, dpr + 1):
		qs = qs * ip % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def ps(n):
	cp = 0
	while n % 2 == 0:
		n = n // 2
		cp += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		while n % ps == 0:
			n = n // ps
			cp += 1
	if n != 1:
		return False
	return True

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
for jj in range(t):
	n = int(input())
	arr = [int(x) for x in input().strip().split()]
	ll = set(arr)
	if len(ll) == 1:
		print(0)
		continue
	ll.clear()
	dict1 = {}
	dict1[arr[0]] = 0
	ll.add(arr[0])
	ans = {arr[0]: 1}
	for i in range(1, n):
		if arr[i] in ll:
			if dict1[arr[i]] != i - 1:
				ans[arr[i]] += 1
				dict1[arr[i]] = i
			else:
				dict1[arr[i]] = i
		else:
			ll.add(arr[i])
			ans[arr[i]] = 2
			dict1[arr[i]] = i
		if i == n - 1:
			ans[arr[i]] -= 1
	ipl = n
	for ij in ans:
		ipl = min(ipl, ans[ij])
	print(ipl)


t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	d = dict()
	for i in set(ls):
		d[i] = 0
	last = 0
	for i in range(n):
		if ls[i] != last:
			d[ls[i]] += 1
			last = ls[i]
	for i in d.keys():
		d[i] += 1
	d[ls[0]] -= 1
	d[ls[-1]] -= 1
	print(min(d.values()))


T = int(input())
for t in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	new_l = [l[0]]
	prev = l[0]
	counts = {l[0]: 1}
	for i in range(1, n):
		cur = l[i]
		if cur != prev:
			new_l.append(cur)
			r = counts.get(cur, 0)
			counts[cur] = r + 1
		prev = cur
	counts[new_l[0]] = counts.get(new_l[0]) - 1
	counts[new_l[-1]] = counts.get(new_l[-1]) - 1
	print(min(counts.values()) + 1)


import sys
infile = sys.stdin
next(infile)
for l in infile:
	n = int(l)
	a = list(map(int, infile.readline().split()))
	if n == 1:
		ans = 0
	else:
		c1n = a[0]
		c2n = a[-1]
		c1 = 0
		c2 = 0
		b = {}
		i = 0
		while i < n:
			if a[i] == c1n:
				c1 += 1
				i += 1
				while i < n and a[i] == c1n:
					i += 1
			elif a[i] == c2n:
				c2 += 1
				i += 1
				while i < n and a[i] == c2n:
					i += 1
			elif a[i] in b:
				check = a[i]
				b[check] += 1
				i += 1
				while i < n and a[i] == check:
					i += 1
			else:
				check = a[i]
				b[a[i]] = 1
				i += 1
				while i < n and a[i] == check:
					i += 1
		if b == {}:
			m = 0
		else:
			m = min(b.values())
		if a[0] == a[-1]:
			ans = min(c1 - 1, m + 1)
		elif m == 0:
			ans = min(c1, c2)
		else:
			ans = min(c1, c2, m + 1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.append(-1)
	cnt = [0] * (len(ls) + 1)
	res = float('inf')
	if ls.count(ls[0]) == len(ls):
		print(0)
	else:
		for i in range(1, len(ls)):
			if ls[i] != ls[i - 1]:
				cnt[ls[i - 1]] += 1
		for i in range(len(cnt)):
			if cnt[i] != 0:
				if i == ls[0]:
					cnt[i] -= 1
				if i == ls[-2]:
					cnt[i] -= 1
				res = min(cnt[i] + 1, res)
	print(res)


for _ in range(int(input())):
	i = int(input())
	l = list(map(int, input().split()))
	p = l[0]
	m = {}
	for x in set(l):
		m[x] = 0
		if x != p:
			m[x] += 1
	for x in l:
		if p != x:
			m[p] += 1
		p = x
	print(min(m.values()))


import sys
import math
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor
from sys import stdin, stdout, setrecursionlimit
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	freq = {}
	for i in range(n):
		if a[i] not in freq:
			freq[a[i]] = 1
		else:
			freq[a[i]] += 1
	if len(freq) == 1:
		print(0)
		continue
	if freq[a[0]] == 1 or freq[a[-1]] == 1:
		print(1)
		continue
	if a[0] == a[-1]:
		x = a[0]
		if freq[x] == 2:
			print(1)
			continue
	for i in range(n - 1):
		if a[i + 1] == a[i]:
			freq[a[i]] -= 1
	freq[a[0]] -= 1
	freq[a[-1]] -= 1
	mnVal = inf
	for i in freq:
		mnVal = min(mnVal, freq[i] + 1)
	print(mnVal)


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [[-1] for i in range(n + 1)]
	for i in range(n):
		b[a[i]].append(i)
	ans = float('inf')
	for i in range(1, n + 1):
		cnt = 0
		b[i].append(n)
		if len(b[i]) == 2:
			continue
		for j in range(len(b[i]) - 1):
			if b[i][j + 1] - b[i][j] > 1:
				cnt += 1
		ans = min(cnt, ans)
	print(ans)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, arr):
	d = {i: 0 for i in arr}
	prev = arr[0]
	for i in arr[1:]:
		if i != prev:
			d[i] += 1
		prev = i
	for j in d:
		if j != prev:
			d[j] += 1
	print(min(d.values()))
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	solve(n, arr)


from math import inf
import sys
import os
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	pos = defaultdict(list)
	for (i, v) in enumerate(arr):
		pos[v].append(i)
	ans = inf
	for (_, positions) in pos.items():
		positions += [n]
		(last, chunks) = (-1, 0)
		for i in range(len(positions)):
			chunks += positions[i] - last > 1
			last = positions[i]
		ans = min(ans, chunks)
	print(ans)


def f(n, l):
	if l.count(l[0]) == n:
		return 0
	else:
		m = [200001 for i in range(n + 1)]
		m[l[0]] = 0
		for i in range(1, n - 1):
			if l[i] != l[i - 1]:
				if m[l[i]] == 200001:
					m[l[i]] = 1
				else:
					m[l[i]] = m[l[i]] + 1
		if l[n - 1] != l[n - 2]:
			if m[l[n - 1]] == 200001:
				m[l[n - 1]] = 0
		else:
			m[l[n - 1]] = m[l[n - 1]] - 1
		return min(m) + 1
x = int(input())
p = []
for i in range(x):
	z = int(input())
	y = input()
	y1 = y.split(' ')
	y2 = [int(t) for t in y1]
	p.append((z, y2))
for j in range(x):
	print(f(p[j][0], p[j][1]))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mp = {}
	if len(set(arr)) == 1:
		print(0)
	else:
		for i in range(n):
			if arr[i] in mp:
				mp[arr[i]] = mp[arr[i]] + [i]
			else:
				mp[arr[i]] = [i]
		ans = 10 ** 9
		for i in mp:
			curr = 0
			if mp[i][0] != 0:
				curr += 1
			if mp[i][-1] != n - 1:
				curr += 1
			for j in range(1, len(mp[i])):
				if mp[i][j] != mp[i][j - 1] + 1:
					curr += 1
			ans = min(ans, curr)
		print(ans)


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
for _ in range(II()):
	n = II()
	a = []
	for v in MI():
		if not a or v != a[-1]:
			a.append(v)
	cnt = {i: 1 for i in set(a)}
	cnt[a[0]] -= 1
	cnt[a[-1]] -= 1
	for (i, v) in enumerate(a):
		cnt[v] += 1
	print(min(cnt.values()))


mod = 10 ** 9 + 7
INF = float('inf')

def readInts():
	return list(map(int, input().split()))

def readTuples():
	return tuple(map(int, input().split()))

def I():
	return int(input())
import collections
import bisect
q = I()
for _ in range(q):
	N = I()
	A = readInts()
	if N == 1:
		print(0)
		continue
	elif N == 2:
		if len(set(A)) == 1:
			print(0)
		else:
			print(1)
	elif len(set(A)) == 1:
		print(0)
	else:
		dic = collections.Counter(A)
		mos = dic.most_common()[-1]
		ans = INF
		if A[0] == mos[0]:
			pass
		else:
			v = A[0]
			sw = False
			a = 0
			for i in range(N):
				if A[i] == v:
					if sw:
						a += 1
						sw = False
				elif i == N - 1:
					if A[i] != v:
						a += 1
					elif sw:
						a += 1
				else:
					sw = True
			ans = min(a, ans)
		v = mos[0]
		a = 0
		sw = False
		for i in range(N):
			if i == 0:
				if A[i] == v:
					pass
				else:
					sw = True
			elif A[i] == v:
				if sw:
					a += 1
					sw = False
			elif i == N - 1:
				if A[i] != v:
					a += 1
				elif sw:
					a += 1
			else:
				sw = True
		ans = min(a, ans)
		if A[-1] == mos[0] or A[-1] == A[0]:
			pass
		else:
			sw = False
			a = 0
			v = A[-1]
			for i in range(N):
				if i == N - 1:
					if A[i] != v:
						a += 1
					elif sw:
						a += 1
					else:
						pass
				elif A[i] == v:
					if sw:
						sw = False
						a += 1
				else:
					sw = True
			ans = min(a, ans)
		print(ans)


import collections
N = int(input())

def ranker():
	d = collections.defaultdict(int)
	n = int(input())
	l = list(map(int, input().split()))
	last = -987654321
	for ch in l:
		if ch == last:
			pass
		else:
			d[ch] += 1
		last = ch
	d[l[0]] -= 1
	d[l[-1]] -= 1
	return min(d.items(), key=lambda x: x[1])[1] + 1
for _ in range(N):
	print(ranker())


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = []
	for i in range(n):
		if i == 0 or l[i] != l[i - 1]:
			l2.append(l[i])
	d = {}
	for i in l2:
		if i in d:
			d[i] += 1
		else:
			d[i] = 2
	d[l2[0]] -= 1
	d[l2[-1]] -= 1
	print(min(list(d.values())))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = [0] * (n + 1)
	prev = [0] * (n + 1)
	for i in range(n):
		if i + 1 - prev[a[i]] > 1:
			count[a[i]] += 1
			prev[a[i]] = i + 1
		else:
			prev[a[i]] = i + 1
	prev1 = [n + 1] * (n + 1)
	a1 = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		if prev1[a[i]] - (i + 1) > 1 and a1[a[i]] == 0:
			count[a[i]] += 1
			a1[a[i]] = 1
		else:
			a1[a[i]] = 1
			prev1[a[i]] = i + 1
	count.sort()
	if count[-1] == 0:
		print(0)
	else:
		for i in range(n + 1):
			if count[i] > 0:
				print(count[i])
				break


for _ in range(int(input())):
	n = int(input())
	array = [int(item) for item in input().split()]
	occur = [1] * (n + 1)
	counter = 0
	MIN = 10 ** 6
	occur[array[0]] -= 1
	occur[array[-1]] -= 1
	while counter < n:
		occur[array[counter]] += 1
		counter += 1
		if counter == n:
			break
		while array[counter] == array[counter - 1]:
			counter += 1
			if counter >= n:
				break
	for i in array:
		if occur[i] < MIN:
			MIN = occur[i]
	print(max(0, MIN))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	pos = {}
	for i in range(n):
		if a[i] not in pos:
			pos[a[i]] = [i]
		else:
			pos[a[i]].append(i)
	ans = inf
	for i in pos:
		temp = 0
		if pos[i][0] != 0:
			temp += 1
		if pos[i][len(pos[i]) - 1] != n - 1:
			temp += 1
		for j in range(1, len(pos[i])):
			if pos[i][j] != pos[i][j - 1] + 1:
				temp += 1
		ans = min(ans, temp)
	print(ans)
testcase(int(inp()))


import sys
read = sys.stdin.readline
for _ in range(int(read())):
	n = int(read())
	num = list(map(int, read().split()))
	check = {}
	before = -1
	num_new = []
	for i in range(n):
		if num[i] != before:
			num_new.append(num[i])
			before = num[i]
	n = len(num_new)
	for i in range(n):
		if num_new[i] not in check:
			check[num_new[i]] = []
		if i != 0 and i != n - 1:
			check[num_new[i]].append(i)
		before = num_new[i]
	if len(check) == 1:
		print(0)
	else:
		print(1 + min((len(arr) for arr in check.values())))


import sys
t = int(input())
for num in range(t):
	n = int(sys.stdin.readline())
	seq = list(map(int, sys.stdin.readline().split()))
	dic = {}
	for i in range(len(seq) - 1):
		if seq[i] != seq[i + 1]:
			if seq[i] not in dic:
				if len(dic) == 0:
					dic[seq[i]] = 1
				else:
					dic[seq[i]] = 2
			else:
				dic[seq[i]] += 1
	if seq[-1] not in dic:
		dic[seq[-1]] = 1
	if len(dic) == 1:
		print(0)
	else:
		print(min(dic.values()))


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
from itertools import groupby

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a / gcd(a, b) * b
t = I()
for _ in range(t):
	n = I()
	s = lint()
	mi = 1000000000.0
	s = [i[0] for i in groupby(s)]
	d = Counter(s)
	d[s[0]] -= 1
	d[s[-1]] -= 1
	for i in set(s):
		if mi > d[i]:
			mi = d[i]
	print(mi + 1)


for i in range(int(input())):
	n = int(input())
	lis = [int(x) for x in input().split()]
	s = list(set(lis))
	postion = [0] * (max(s) + 1)
	count = [0] * (max(s) + 1)
	for i in range(1, n):
		if lis[i] == lis[i - 1]:
			pass
		elif abs(i - postion[lis[i]]) > 0:
			count[lis[i]] += 1
		postion[lis[i]] = i
	for i in s:
		if abs(n - 1 - postion[i]) > 0:
			count[i] += 1
	ans = 100000000000
	for i in count:
		if i < ans and i != 0:
			ans = i
	if ans == 100000000000:
		print(0)
	else:
		print(ans)


t = int(input())
G = {}

def calc(a):
	G.clear()
	for i in range(0, len(a)):
		if a[i] in G:
			if a[i] != a[i - 1] and i != len(a):
				G[a[i]] += 1
		elif i != 0:
			G[a[i]] = 1
		else:
			G[a[i]] = 0
	for i in G:
		if a[len(a) - 1] != i:
			G[i] += 1
	mini = 10 ** 9
	for i in G:
		if G[i] < mini:
			mini = G[i]
	return mini
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(calc(a))


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import heapify, heappop, heappush
from statistics import median
from math import gcd, sqrt, floor, factorial, ceil, log2, log10
import copy
from copy import deepcopy
import sys
sys.setrecursionlimit(10 ** 7)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import random, randint, randrange

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

class MaxHeap:

	def __init__(self, maxsize):
		self.maxsize = maxsize
		self.size = 0
		self.Heap = [0] * (self.maxsize + 1)
		self.Heap[0] = sys.maxsize
		self.FRONT = 1

	def parent(self, pos):
		return pos // 2

	def leftChild(self, pos):
		return 2 * pos

	def rightChild(self, pos):
		return 2 * pos + 1

	def isLeaf(self, pos):
		if pos >= self.size // 2 and pos <= self.size:
			return True
		return False

	def swap(self, fpos, spos):
		(self.Heap[fpos], self.Heap[spos]) = (self.Heap[spos], self.Heap[fpos])

	def maxHeapify(self, pos):
		if not self.isLeaf(pos):
			if self.Heap[pos] < self.Heap[self.leftChild(pos)] or self.Heap[pos] < self.Heap[self.rightChild(pos)]:
				if self.Heap[self.leftChild(pos)] > self.Heap[self.rightChild(pos)]:
					self.swap(pos, self.leftChild(pos))
					self.maxHeapify(self.leftChild(pos))
				else:
					self.swap(pos, self.rightChild(pos))
					self.maxHeapify(self.rightChild(pos))

	def insert(self, element):
		if self.size >= self.maxsize:
			return
		self.size += 1
		self.Heap[self.size] = element
		current = self.size
		while self.Heap[current] > self.Heap[self.parent(current)]:
			self.swap(current, self.parent(current))
			current = self.parent(current)

	def Print(self):
		for i in range(1, self.size // 2 + 1):
			print(' PARENT : ' + str(self.Heap[i]) + ' LEFT CHILD : ' + str(self.Heap[2 * i]) + ' RIGHT CHILD : ' + str(self.Heap[2 * i + 1]))

	def extractMax(self):
		popped = self.Heap[self.FRONT]
		self.Heap[self.FRONT] = self.Heap[self.size]
		self.size -= 1
		self.maxHeapify(self.FRONT)
		return popped

def get_list():
	return list(map(int, input().split()))

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'
t = 1
t = input_int()
for i in range(t):
	n = input_int()
	l = get_list()
	if l == [l[0]] * n:
		print(0)
		continue
	dict = Counter(l)
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			dict[l[i]] -= 1
	if l[0] == l[-1]:
		dict[l[0]] -= 1
	m = set(l)
	for i in m:
		if i == l[0] or i == l[-1]:
			continue
		dict[i] += 1
	print(min(dict.values()))


from collections import defaultdict

def ans():
	n = int(input())
	a = list(map(int, input().split()))
	num_list = []
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			num_list.append(a[i])
	else:
		num_list.append(a[-1])
	if len(num_list) == 1:
		print(0)
	else:
		c = defaultdict(lambda : 0)
		for i in range(1, len(num_list) - 1):
			c[num_list[i]] += 1
		try:
			mn = min((i for i in c.values()))
		except ValueError:
			pass
		if num_list.count(num_list[0]) == 1 or (num_list.count(num_list[0]) == 2 and num_list[0] == num_list[-1]) or num_list.count(num_list[-1]) == 1:
			print(1)
		else:
			print(mn + 1)
for t in range(int(input())):
	ans()


t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		d = {}
		(same, ss) = (arr[0], True)
		last = -1
		for i in arr:
			if same != i:
				ss = False
			if last != i:
				last = i
				if i in d:
					d[i] += 1
				else:
					d[i] = 1
		if ss:
			print(0)
		else:
			d[arr[0]] -= 1
			d[arr[n - 1]] -= 1
			minf = min(d.values())
			print(minf + 1)


import sys
from collections import defaultdict
import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d1 = defaultdict(list)
	for i in range(n):
		d1[arr[i]].append(i)
	m = sys.maxsize
	moves = 0
	for i in d1:
		temp = d1[i]
		temp.insert(0, 0)
		temp.append(n - 1)
		if temp[1] - temp[0] > 0:
			moves += 1
		if temp[len(temp) - 1] - temp[len(temp) - 2] > 0:
			moves += 1
		for i in range(2, len(temp) - 1):
			if temp[i] - temp[i - 1] > 1:
				moves += 1
		m = min(moves, m)
		moves = 0
	print(m)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	dic2 = {}
	for i in range(n):
		if dic.get(arr[i], -1) == -1:
			dic[arr[i]] = i
			dic2[arr[i]] = 0
			if i > 0:
				dic2[arr[i]] = 1
		else:
			if i - dic[arr[i]] > 1:
				dic2[arr[i]] += 1
			dic[arr[i]] = i
	for i in dic:
		if n - dic[i] > 1:
			dic2[i] += 1
	minn = 10 ** 9
	for i in dic:
		minn = min(minn, dic2[i])
	print(minn)


from collections import Counter

def solve(L):
	filtered_list = []
	for l in L:
		if len(filtered_list) == 0 or filtered_list[-1] != l:
			filtered_list.append(l)
	if len(filtered_list) == 0:
		return 0
	counter = Counter()
	for l in filtered_list:
		counter[l] += 1
	result = -1
	for (key, value) in counter.items():
		num = value + 1
		if filtered_list[0] == key:
			num -= 1
		if filtered_list[-1] == key:
			num -= 1
		if result == -1 or num < result:
			result = num
	return result
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a))


rn = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rns = lambda : map(int, input().split())
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
for _ in range(rn()):
	n = rn()
	l = rl()
	a = (max(l) + 1) * [0]
	for i in range(len(a)):
		a[i] = []
	for i in range(n):
		a[l[i]] += [i]
	ans = float('inf')
	for i in range(len(a)):
		if len(a[i]) > 0:
			a[i] = [-1] + a[i]
			a[i].append(n)
			tans = 0
			for j in range(1, len(a[i])):
				if a[i][j] - a[i][j - 1] > 1:
					tans += 1
			ans = min(ans, tans)
	print(ans)


def sequenceTransformation(n, array):
	a = []
	prev = '#'
	for x in range(n):
		if array[x] != prev:
			a.append(array[x])
			prev = array[x]
	if len(a) == 1:
		return 0
	elif len(a) == 2:
		return 1
	d = {}
	for x in range(0, len(a)):
		if a[x] in d:
			d[a[x]] += 1
		else:
			d[a[x]] = 1
	min = float('inf')
	d[a[0]] -= 1
	d[a[-1]] -= 1
	for x in d:
		if d[x] < min:
			min = d[x]
	return min + 1
t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	print(sequenceTransformation(n, array))


from sys import stdout, stdin
input = stdin.readline
print = stdout.write

def main():
	mp = lambda : map(int, input().strip().split())
	it = int
	t = it(input())
	for _ in [0] * t:
		n = it(input())
		a = list(mp())
		b = [-1] * (n + 1)
		b[a[0]] = 0
		for i in range(1, n):
			if b[a[i]] < 0:
				b[a[i]] = 1
			elif a[i] != a[i - 1]:
				b[a[i]] += 1
		b[a[-1]] -= 1
		m = 10 ** 9
		for i in range(1, n + 1):
			if b[i] >= 0:
				m = min(m, b[i])
		if m == 10 ** 9:
			m = -1
		print(str(m + 1) + '\n')
main()


for _ in range(int(input())):
	input()
	pos = {}
	size = 0
	previous = 0
	for (i, v) in enumerate(map(int, input().split())):
		size += 1
		if i == 0:
			previous = v
			pos[v] = 0
			continue
		if v == previous:
			continue
		else:
			pos[previous] += 1
			if v in pos:
				pass
			else:
				pos[v] = 1
			previous = v
	print(min(pos.values()))


for s in [*open(0)][2::2]:
	l = [*map(int, s.split())]
	n = len(l)
	a = {x: 1 for x in l}
	a[l[0]] = 0
	for i in range(n - 1):
		if l[i + 1] != l[i]:
			a[l[i]] += 1
	print([min(a.items(), key=lambda x: x[1])[1], 0][len(set(l)) == 1])


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	l = [int(x) for x in sys.stdin.readline().split()]
	l2 = [l[0]]
	target = l[0]
	for i in range(1, n):
		if l[i] == target:
			continue
		else:
			target = l[i]
			l2.append(target)
	dic = {}
	for i in range(len(l2)):
		if l2[i] not in dic:
			dic[l2[i]] = 1
		else:
			dic[l2[i]] += 1
	dic[l[0]] -= 1
	dic[l[-1]] -= 1
	l_new = sorted(dic.items(), key=lambda d: d[1])
	if len(l_new) != 1:
		print(l_new[0][1] + 1)
	else:
		print(0)


from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(0)
		continue
	d = {}
	for (i, j) in enumerate(a):
		d[j] = d.get(j, []) + [i]
	mini = float('inf')
	for j in d.values():
		c = 0
		j = [-1] + j + [n]
		for i in range(1, len(j)):
			f = j[i] - j[i - 1] - 1
			if f > 0:
				c += 1
		mini = min(mini, c)
	print(mini)


from collections import Counter

def unique(lis):
	prev = -1
	res = []
	for i in lis:
		if i != prev:
			res.append(i)
			prev = i
	return res
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	lis = unique(lis)
	dic = Counter(lis)
	mi = float('inf')
	for i in dic:
		ans = dic[i] + 1
		if lis[0] == i:
			ans -= 1
		if lis[-1] == i:
			ans -= 1
		mi = min(mi, ans)
	print(mi)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	l = [-1] * n
	cnt = [0] * n
	for (i, x) in enumerate(a):
		if i - l[x - 1] > 1:
			cnt[x - 1] += 1
		l[x - 1] = i
	for x in range(1, n + 1):
		i = n
		if i - l[x - 1] > 1:
			cnt[x - 1] += 1
		l[x - 1] = i
	mn = int(1000000000.0)
	for x in a:
		mn = min(mn, cnt[x - 1])
	print(mn)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
from itertools import groupby
t = int(input())
for _ in range(0, t):
	n = int(input())
	inp = [int(x) for x in input().split()]
	x = [x[0] for x in groupby(inp)]
	if len(x) == 1:
		print(0)
		continue
	count = {}
	for i in range(0, len(x)):
		elem = x[i]
		if elem in count:
			if i != len(x) - 1:
				count[elem] += 1
		elif i == 0 or i == len(x) - 1:
			count[elem] = 1
		else:
			count[elem] = 2
	print(min(count.values()))


import sys
from math import *
from collections import deque

def linp():
	return list(map(int, sys.stdin.readline().split()))

def minp():
	return map(int, sys.stdin.readline().split())

def sinp():
	return sys.stdin.readline().rstrip('\n')

def inp():
	return int(sys.stdin.readline())
for t in range(inp()):
	n = inp()
	lst = linp()
	cnt = [0] * (n + 1)
	for i in range(1, n):
		if lst[i] == lst[i - 1]:
			continue
		else:
			cnt[lst[i]] += 1
	for i in set(lst):
		if i != lst[-1]:
			cnt[i] += 1
	ans = 10 ** 9
	for i in cnt:
		if i != 0:
			ans = min(i, ans)
	print(ans if ans != 10 ** 9 else 0)


import collections
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = [a[0]] + [a[i] for i in range(1, n) if a[i] != a[i - 1]]
	cnt = collections.Counter(a)
	cnt[a[0]] -= 1
	cnt[a[-1]] -= 1
	print(min([cnt[i] + 1 for i in cnt]))


from math import *
import threading
import sys
from collections import defaultdict
sys.setrecursionlimit(300000)
mod = 10 ** 9
inf = 10 ** 15
yes = 'YES'
no = 'NO'
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def dist(a, b):
	d = abs(a[1] - b[1]) + abs(a[2] - b[2])
	return d

def power_of_n(x, n):
	cnt = 0
	while x % n == 0:
		cnt += 1
		x //= n
	return cnt

def check(u, r, d, l):
	f = 1
	if u == 0 or d == 0:
		if l == n or r == n:
			f = 0
	if l == 0 or r == 0:
		if d == n or u == n:
			f = 0
	if u == 0 and d == 0:
		if l >= n - 1 or r >= n - 1:
			f = 0
	if l == 0 and r == 0:
		if d >= n - 1 or u >= n - 1:
			f = 0
	return f
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict()
	for i in range(n):
		if a[i] in d:
			d[a[i]].append(i)
		else:
			d[a[i]] = [i]
	mini = inf
	for (k, v) in d.items():
		ans = 0
		if v[0] - 0 > 0:
			ans += 1
		if n - 1 - v[-1] > 0:
			ans += 1
		for i in range(1, len(v)):
			if v[i] - v[i - 1] > 1:
				ans += 1
		mini = min(mini, ans)
	print(mini)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	A = defaultdict(lambda : 0)
	prev = -1
	for (i, v) in enumerate(map(int, input().split()), 1):
		if v != prev:
			A[v] += 1
			prev = v
			if i == 1 or i == n:
				A[v] -= 1
		elif i == n:
			A[v] -= 1
	if len(A) == 1:
		print(0)
	else:
		print(min(A.values()) + 1)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().strip().split(' ')))
	if len(set(li)) == 1:
		print(0)
		continue
	ma = {}
	for i in range(n):
		if i == 0:
			ma[li[i]] = [0, i + 1 - 1]
		elif li[i] in ma:
			ma[li[i]][0] += 1 if ma[li[i]][1] < i - 1 else 0
			ma[li[i]][1] = i + 1 - 1
		else:
			ma[li[i]] = [1, i + 1 - 1]
	for i in list(ma.keys()):
		ma[i][0] += 1 if i != li[-1] else 0
	print(min([x[0] for x in ma.values()]))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	prev = float('inf')
	t = []
	for i in range(n):
		if l[i] != l[i - 1]:
			t.append(l[i])
		prev = l[i]
	d = {}
	for i in t:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	d = {k: v for (k, v) in sorted(d.items(), key=lambda item: item[1])}
	if len(d) == 0:
		print(0)
	else:
		r = list(d.keys())[0]
		if d[l[0]] == d[r] or d[l[n - 1]] == d[r]:
			print(d[r])
		else:
			print(d[r] + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	dic = {}
	inp = input()
	for i in inp.split(' '):
		ele = int(i)
		if ele != (arr or [None])[-1]:
			arr.append(ele)
			dic[ele] = dic.get(ele, 1) + 1
	dic[arr[0]] = dic[arr[0]] - 1
	dic[arr[-1]] = dic[arr[-1]] - 1
	print(dic[min(dic, key=dic.get)])


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import *
sys.setrecursionlimit(99999)

def II():
	return int(sys.stdin.buffer.readline().strip())

def IIs():
	return list(map(int, sys.stdin.buffer.readline().strip().split()))
for _ in range(II()):
	n = II()
	arr = IIs()
	d = collections.defaultdict(int)
	d[arr[0]] = 1
	for (i, c) in enumerate(arr[1:], start=1):
		if c != arr[i - 1]:
			d[c] += 1
	ans = float('inf')
	for (k, v) in d.items():
		v -= 1
		if arr[0] != k:
			v += 1
		if arr[-1] != k:
			v += 1
		ans = min(ans, v)
	print(0 if ans == float('inf') else ans)


def do():
	d = {}
	last = ''
	for e in data:
		if e == last:
			continue
		d[e] = d.get(e, 1) + 1
		last = e
	if len(d) == 1:
		return 0
	d[data[0]] -= 1
	d[data[-1]] -= 1
	return min(d.values())
for _ in range(int(input())):
	n = int(input())
	data = input().split()
	print(do())


import sys

def read_int():
	return int(sys.stdin.readline())

def read_ints():
	return map(int, sys.stdin.readline().split(' '))
t = read_int()
ans = []
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	seg = [0] * (n + 1)
	curr = 0
	cnt = 0
	for ai in a:
		if ai == curr:
			cnt += 1
		else:
			if cnt > 0:
				seg[curr] += 1
			curr = ai
			cnt = 1
	if cnt > 0:
		seg[curr] += 1
	res = n
	for i in range(1, n + 1):
		if seg[i] == 0:
			continue
		op = seg[i] + 1
		if i == a[0]:
			op -= 1
		if i == a[-1]:
			op -= 1
		res = min(res, op)
	ans.append(str(res))
print('\n'.join(ans))


from sys import stdin, stdout
input = stdin.readline
from collections import Counter
import bisect

def func(l, n):
	l.insert(0, -1)
	l.append(n)
	ans = 0
	for i in range(1, len(l)):
		if l[i] - l[i - 1] > 1:
			ans += 1
	return ans

def check(a, n):
	for i in range(n):
		if a[i] != a[0]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	d = {}
	if check(a, n):
		print(0)
		continue
	for i in range(n):
		if a[i] in d:
			d[a[i]].append(i)
		else:
			d[a[i]] = [i]
	mn = len(a)
	for (i, j) in d.items():
		mn = min(mn, func(j, n))
	print(mn)


T = 0
T = int(input())
for i in range(T):
	n = 0
	n = int(input())
	ar = list(map(int, input().strip().split(' ')))
	x = [0] * (n + 1)
	y = [1] * (n + 1)
	y[ar[n - 1]] -= 1
	min = 2000000
	b = 0
	a = 0
	u = 0
	for j in range(1, n + 1):
		a = ar[j - 1]
		b = j - x[a] - 1
		x[a] = j
		if b >= 1:
			u = 1
			y[a] += 1
	for j in range(1, n + 1):
		if x[j] != 0 and y[j] < min:
			min = y[j]
	if u == 0:
		print(0)
	else:
		print(min)


I = lambda : map(int, input().split())
for _ in [0] * int(input()):
	n = int(input())
	a = list(I())
	d = {}
	d[a[0]] = 1
	for i in range(1, n):
		ai = a[i]
		if ai != a[i - 1]:
			if ai not in d:
				d[ai] = 2
			else:
				d[ai] = d[ai] + 1
	d[a[n - 1]] = d[a[n - 1]] - 1
	print(min(d.values()))


from sys import stdin
input = stdin.readline
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt
from itertools import permutations as p

def it():
	return int(input())

def mp():
	return map(int, input().split())
for _ in range(it()):
	n = it()
	a = list(mp())
	k = set(a)
	d = dd(lambda : [])
	for i in range(n):
		d[a[i]].append(i + 1)
	out = float('inf')
	for j in d:
		ind = None
		ans = 0
		for k in d[j]:
			if ind == None:
				if k > 1:
					ans += 1
				ind = k
			elif k - ind > 1:
				ans += 1
			ind = k
		if n - ind:
			ans += 1
		out = min(out, ans)
	print(out)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	c = 0
	for i in l:
		if i == c:
			continue
		d[i] = d.get(i, 1) + 1
		c = i
	d[l[0]] -= 1
	d[l[-1]] -= 1
	print(min(d.values()))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0 for i in range(n + 1)]
	for i in range(n):
		if a[i] == a[i - 1] or i == 0:
			continue
		ans[a[i]] += 1
	res = float('inf')
	for i in range(n):
		if a[n - 1] != a[i]:
			res = min(res, ans[a[i]] + 1)
		else:
			res = min(res, ans[a[i]])
	print(res)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if arr[i] in d:
			d[arr[i]].append(i)
		else:
			d[arr[i]] = [i]
	res = None
	ind = None
	for i in d:
		k = -1
		c = 0
		for j in d[i]:
			if k + 1 != j:
				c += 1
				k = j
			else:
				k = j
		if k != n - 1:
			c += 1
		if res is None or c < res:
			res = c
	if res:
		return res
	else:
		return 0

def main():
	for _ in range(int(input())):
		print(solve())
main()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = defaultdict(list)
	prev = None
	for i in range(n):
		if arr[i] != prev:
			dic[arr[i]].append(i)
			prev = arr[i]
	ans = float('inf')
	for x in dic.keys():
		temp = len(dic[x]) + 1
		if x == arr[0]:
			temp -= 1
		if x == arr[-1]:
			temp -= 1
		ans = min(ans, temp)
	print(ans)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = [0] * (n + 1)
	b = [0] * (n + 1)
	h = [False] * (n + 1)
	i = 1
	for v in mints():
		if a[v] != i - 1:
			b[v] += 1
		a[v] = i
		h[v] = True
		i += 1
	ans = int(1000000000.0)
	for v in range(n + 1):
		if h[v]:
			if a[v] != n:
				b[v] += 1
			ans = min(ans, b[v])
	print(ans)
for i in range(mint()):
	solve()


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	ind = [-1] * (n + 1)
	ints = [0] * (n + 1)
	for i in range(n):
		if i - ind[arr[i]] > 1:
			ints[arr[i]] += 1
		ind[arr[i]] = i
	for i in range(1, n + 1):
		if ind[i] != -1 and n - ind[i] > 1:
			ints[i] += 1
	ans = n + 1
	for i in range(1, n + 1):
		if ind[i] != -1:
			ans = min(ans, ints[i])
	print(ans)
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	(l, b) = (list(map(int, input().split())), [0] * (n + 1))
	temp = l[0]
	b[temp] = -1
	for i in range(n - 1):
		if l[i] != l[i + 1]:
			tmp = l[i]
			b[tmp] += 1
	ans = 1000000000.0
	for i in range(n):
		tmp = l[i]
		ans = min(b[tmp] + 1, ans)
	print(ans)


import sys
import math
import collections
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	d = {}
	for i in range(n):
		if l[i] in d:
			d[l[i]] += [i]
		else:
			d[l[i]] = [-1, i]
	for i in d:
		d[i].append(n)
	m = 20000000
	for i in d:
		c = 0
		for j in range(1, len(d[i])):
			if d[i][j] - d[i][j - 1] > 1:
				c += 1
		m = min(m, c)
	print(m)


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
sys.setrecursionlimit(2 * 10 ** 5 + 10)
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
aa = 'abcdefghijklmnopqrstuvwxyz'

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def primeFactors(n):
	sa = []
	while n % 2 == 0:
		sa.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.append(i)
			n = n // i
	if n > 2:
		sa.append(n)
	return sa

def seive(n):
	pri = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if pri[p] == True:
			for i in range(p * p, n + 1, p):
				pri[i] = False
		p += 1
	return pri

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def sol(n):
	seti = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			seti.add(n // i)
			seti.add(i)
	return seti

def lcm(a, b):
	return a * b // gcd(a, b)

def moore_voting(l):
	count1 = 0
	count2 = 0
	first = 10 ** 18
	second = 10 ** 18
	n = len(l)
	for i in range(n):
		if l[i] == first:
			count1 += 1
		elif l[i] == second:
			count2 += 1
		elif count1 == 0:
			count1 += 1
			first = l[i]
		elif count2 == 0:
			count2 += 1
			second = l[i]
		else:
			count1 -= 1
			count2 -= 1
	for i in range(n):
		if l[i] == first:
			count1 += 1
		elif l[i] == second:
			count2 += 1
	if count1 > n // 3:
		return first
	if count2 > n // 3:
		return second
	return -1

def find_parent(u, parent):
	if u != parent[u]:
		parent[u] = find_parent(parent[u], parent)
	return parent[u]

def dis_union(n):
	par = [i for i in range(n + 1)]
	rank = [1] * (n + 1)
	k = int(input())
	for i in range(k):
		(a, b) = map(int, input().split())
		(z1, z2) = (find_parent(a, par), find_parent(b, par))
		if z1 != z2:
			par[z1] = z2
			rank[z2] += rank[z1]

def dijkstra(n, tot, hash):
	hea = [[0, n]]
	dis = [10 ** 18] * (tot + 1)
	dis[n] = 0
	boo = defaultdict(bool)
	check = defaultdict(int)
	while hea:
		(a, b) = heapq.heappop(hea)
		if boo[b]:
			continue
		boo[b] = True
		for (i, w) in hash[b]:
			if b == 1:
				c = 0
				if (1, i, w) in nodes:
					c = nodes[1, i, w]
					del nodes[1, i, w]
				if dis[b] + w < dis[i]:
					dis[i] = dis[b] + w
					check[i] = c
				elif dis[b] + w == dis[i] and c == 0:
					dis[i] = dis[b] + w
					check[i] = c
			elif dis[b] + w <= dis[i]:
				dis[i] = dis[b] + w
				check[i] = check[b]
			heapq.heappush(hea, [dis[i], i])
	return check

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res *= x
		x = x * x
		y = y >> 1
	return res
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	la = []
	hash = defaultdict(list)
	i = 0
	if len(set(l)) == 1:
		print(0)
		continue
	while i < len(l):
		z = l[i]
		hash[z].append(i)
		while i < len(l) and l[i] == z:
			i += 1
	ans = 10 ** 18
	hash[l[-1]][-1] = n - 1
	for i in hash:
		count = 0
		for j in hash[i]:
			if j != 0:
				count += 1
		if hash[i][-1] != n - 1:
			count += 1
		ans = min(count, ans)
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	d = {}
	last_element = -1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			if last_element != -1:
				if last_element in d:
					d[last_element] += 1
				else:
					d[last_element] = 1
			last_element = a[i]
	if last_element == -1:
		print(0)
	elif a[0] not in d or last_element not in d:
		print(1)
	else:
		print(min(d.values()) + 1)


from sys import stdin
criba = []
T = int(stdin.readline().strip())
for casos in range(T):
	n = int(stdin.readline().strip())
	s = list(map(int, stdin.readline().strip().split()))
	cnt = [n + n for i in range(n + 2)]
	for i in set(s):
		cnt[i] = 1
	for i in range(1, n):
		if s[i - 1] != s[i]:
			cnt[s[i]] += 1
	cnt[s[-1]] -= 1
	cnt.sort()
	print(cnt[0])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	le = l[0]
	d = {}
	d[le] = 1
	for i in l[1:]:
		if le != i:
			d[i] = d.get(i, 0) + 1
			le = i
	d[l[0]] -= 1
	d[l[-1]] -= 1
	if len(d) == 1:
		print(0)
	else:
		print(min(d.values()) + 1)


t = int(input())
for i in range(t):
	n = int(input())
	dic = {}
	x = list(map(int, input().split()))
	for j in range(1, n + 1):
		dic.setdefault(x[j - 1], [0, 2, 0])
		dic[x[j - 1]][0] += 1
		dic[x[j - 1]][2] += 1
	for j in range(1, n):
		if x[j] == x[j - 1]:
			dic[x[j]][2] -= 1
	z = 0
	for (key, val) in dic.items():
		dic[key][2] += 1
		if n == val[0]:
			print(0)
			z = 1
			break
		if x[0] == key and val[2] > 1:
			dic[key][2] -= 1
		if x[-1] == key and val[2] > 1:
			dic[key][2] -= 1
	min = n
	if z == 0:
		for (key, val) in dic.items():
			if val[2] < min:
				min = val[2]
		print(min)


from sys import exit, stderr
from collections import defaultdict

def debug(*args):
	for i in args:
		stderr.write(str(i) + ' ')
	stderr.write('\n')
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	st = set(a)
	if len(st) == 1:
		print(0)
		continue
	d = defaultdict(list)
	narr = []
	for i in range(n):
		try:
			prev = d[a[i]][-1]
			if i - prev == 1:
				d[a[i]][-1] = i
			else:
				d[a[i]].append(i)
			continue
		except:
			d[a[i]].append(i)
			continue
	mn = 10 ** 18
	fg = True
	for ke in d:
		ln = len(d[ke])
		if ln == 1:
			if d[ke][0] == 0 or d[ke][0] == n - 1 or a[0] == ke:
				fg = False
				print(1)
				break
			else:
				mn = min(mn, 2)
		else:
			if d[ke][-1] == n - 1:
				ln -= 1
			if a[0] == ke:
				ln -= 1
			mn = min(mn, ln + 1)
	if fg:
		print(mn)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(0)
	elif len(set(a)) == n:
		print(1)
	else:
		b = [a[0]]
		for i in range(1, n):
			if a[i] != a[i - 1]:
				b.append(a[i])
		dic = {}
		for x in b:
			if x in dic:
				dic[x] += 1
			else:
				dic[x] = 1
		dic[b[len(b) - 1]] -= 1
		dic[b[0]] -= 1
		print(min(dic.values()) + 1)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		MAX_A = max(A)
		section = [[] for _ in range(MAX_A)]
		for i in range(n):
			section[A[i] - 1].append(i)
		res = f_inf
		for sec in section:
			if len(sec) == 0:
				continue
			cnt = 0
			now = sec[0]
			if now != 0:
				cnt += 1
			for idx in sec:
				if idx - now > 1:
					cnt += 1
				now = idx
			if now != n - 1:
				cnt += 1
			res = min(res, cnt)
		print(res)
resolve()


from collections import Counter
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if len(set(a)) == 1:
		print(0)
	elif a[0] == a[-1] and a.count(a[0]) == 2:
		print(1)
	else:
		c = []
		for i in range(len(a)):
			if i == len(a) - 1:
				break
			if a[i] != a[i + 1]:
				c.append(a[i])
		if a[-1] != c[-1]:
			c.append(a[-1])
		o = list(Counter(c).values())
		if len(c) == len(set(a)):
			print(1)
		elif c[0] == c[-1] and c.count(c[0]) == 2:
			print(1)
		elif c[0] == c[-1]:
			if c.count(c[0]) - 1 < min(o) + 1:
				print(c.count(c[0]) - 1)
			else:
				print(min(o) + 1)
		else:
			print(min(min(o) + 1, c.count(c[-1]), c.count(c[0])))


t = int(input())

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		el = arr[i]
		if not el in d.keys():
			d[el] = []
		d[el].append(i)
	ans = 2 ** 31
	for i in d.keys():
		regions = 0
		a = d[i]
		for i in range(len(a)):
			if i == 0:
				if a[i] > 0:
					regions += 1
			if i == len(a) - 1:
				if a[i] < n - 1:
					regions += 1
			if i != len(a) - 1:
				if a[i + 1] - a[i] > 1:
					regions += 1
		ans = min(ans, regions)
	print(ans)
for i in range(t):
	solve()


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for i in range(t):
	n = int(input())
	a = lnii()
	if len(set(a)) == 1:
		print(0)
		continue
	backet = [[] for i in range(n + 1)]
	for i in range(n):
		backet[a[i]].append(i)
	ans = 10 ** 9
	for i in backet:
		if not i:
			continue
		li = i
		if li[0] != 0:
			li = [-1] + li
		if i[-1] != n - 1:
			li = li + [n]
		t_ans = 0
		for j in range(1, len(li)):
			if li[j] != li[j - 1] + 1:
				t_ans += 1
		ans = min(ans, t_ans)
	print(ans)


import sys
from collections import Counter

def rl():
	return sys.stdin.readline().strip()

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array0):
	array = []
	last = -1
	for v in array0:
		if not last == v:
			array.append(v)
		last = v
	c = Counter(array)
	sc = sorted([(c[k], k) for k in c])
	ops = float('inf')
	if len(sc) == 1:
		ops = 0
	else:
		for (freq, v) in sc:
			freq -= 1
			if not array0[0] == v:
				freq += 1
			if not array0[-1] == v:
				freq += 1
			ops = min(ops, freq)
	return ops
NT = int(rl())
for ti in range(NT):
	_ = rl()
	array = [int(x) for x in rl().split(' ')]
	res = solve(array)
	pr(res)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cond = []
	for x in arr:
		if not cond or cond[-1] != x:
			cond.append(x)
	ct = {}
	for x in set(cond):
		ct[x] = 1
	for x in cond[1:]:
		ct[x] += 1
	ct[cond[-1]] -= 1
	print(min(ct.values()))


for test in range(int(input())):
	input()
	a = list(map(int, input().split()))
	a_a = {a[0]: 1}
	for (a_i, a_p_i) in zip(a[1:], a[:-1]):
		if a_i == a_p_i:
			continue
		a_a[a_i] = a_a.get(a_i, 1) + 1
	a_a[a[-1]] -= 1
	print(min(a_a.values()))


import os
import sys
from io import BytesIO, IOBase
from collections import deque, defaultdict, OrderedDict, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, insort, bisect_left

def main():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		b = [l[0]]
		for i in range(1, n):
			if l[i] != l[i - 1]:
				b.append(l[i])
		a = Counter(b)
		a[b[0]] -= 1
		a[b[-1]] -= 1
		print(min(a.values()) + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve(n, a):
	if len(set(a)) == 1:
		return 0
	d = dict()
	for i in range(n):
		if a[i] not in d.keys():
			d[a[i]] = [i + 1]
		else:
			d[a[i]].append(i + 1)
	lev = float('inf')
	mini = float('inf')
	for (k, v) in d.items():
		if len(v) == 1:
			if v[0] == 1 or v[0] == n:
				lev = 1
			else:
				lev = 2
		else:
			if v[0] == 1:
				cop = 0
			else:
				cop = 1
			for i in range(1, len(v)):
				if v[i] - v[i - 1] > 1:
					cop += 1
			if v[-1] != n:
				cop += 1
			lev = cop
		if mini > lev:
			mini = lev
	return mini
noOfTestCases = int(input())
for i in range(noOfTestCases):
	n = int(input())
	a = list(map(int, input().split()))
	ans = solve(n, a)
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline())
for q in range(t):
	stdin.readline()
	L = [int(x) for x in stdin.readline().split(' ')]
	freq = {}
	for i in L:
		freq[i] = 1
	for (idx, i) in enumerate(L):
		if L[idx - 1] != L[idx]:
			freq[i] += 1
	m = 100000000
	if L[0] == L[-1]:
		freq[L[0]] -= 1
	else:
		freq[L[0]] -= 1
		freq[L[-1]] -= 1
	for (key, val) in freq.items():
		m = min(val, m)
	print(m)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = defaultdict(list)
		for (i, v) in enumerate(a):
			b[v].append(i)
		mi = inf
		for i in b:
			z = (b[i][0] != 0) + (b[i][-1] != n - 1)
			for j in range(len(b[i]) - 1):
				if b[i][j + 1] - b[i][j] > 1:
					z += 1
			mi = min(mi, z)
		print(mi)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
input = stdin.readline
print2 = stdout.write

def get_ints():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		input()
		print(0)
		continue
	a = get_list()
	se = set(a)
	if len(se) == 1:
		print(0)
		continue
	elif len(se) == n:
		print(1)
		continue
	counts = {s: 1 for s in se}
	i = 1
	prev = a[0]
	while i < n:
		cur = a[i]
		if cur != prev:
			counts[a[i]] += 1
		prev = cur
		i += 1
	counts[a[-1]] -= 1
	print(min(counts.values()))


list_ans = []
for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	dict1 = {}
	ans = 10 ** 5
	for i in range(n):
		if list1[i] not in dict1:
			dict1[list1[i]] = [i]
		else:
			dict1[list1[i]].append(i)
	for x in dict1.values():
		s = 2
		m = len(x)
		for y in range(m - 1):
			if x[y + 1] - x[y] > 1:
				s += 1
		if 0 in x:
			s -= 1
		if n - 1 in x:
			s -= 1
		ans = min(ans, s)
	list_ans.append(ans)
for item in list_ans:
	print(item)


def solve(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = list(a)
	b.sort()
	if b[0] == b[len(b) - 1]:
		print(0)
		return
	c = []
	cnt = {}
	for i in a:
		cnt[i] = 0
		c.append(i)
		if len(c) != 1 and c[-1] == c[-2]:
			c.pop()
	for i in range(1, len(c) - 1):
		cnt[c[i]] += 1
	print(min(cnt.values()) + 1)
t = int(input())
for i in range(t):
	solve(i)


inputs = []
test_cases = int(input())
while test_cases > 0:
	l = int(input())
	inputs.append(list(map(int, input().strip().split())))
	test_cases -= 1
indexlist = {}
for test in inputs:
	i = 0
	for n in test:
		if n not in indexlist:
			indexlist[n] = [i]
		else:
			indexlist[n].append(i)
		i += 1
	ans = len(test)
	for key in indexlist:
		if len(test) == 1 or len(indexlist) == 1:
			ans = 0
			break
		if len(indexlist) == len(test):
			ans = 1
			break
		flag1 = 0
		flag2 = 0
		op = 0
		l = len(indexlist[key])
		if indexlist[key][0] != 0:
			flag1 = 1
		if indexlist[key][l - 1] != i - 1:
			flag2 = 1
		for j in range(len(indexlist[key]) - 1):
			if indexlist[key][j + 1] - indexlist[key][j] > 1:
				op += 1
		if flag1 == 1:
			op += 1
		if flag2 == 1:
			op += 1
		if flag1 == 0 and flag2 == 0 and (len(indexlist[key]) == 2):
			op = 1
		if op < ans:
			ans = op
	print(ans)
	indexlist.clear()


n = int(input())
for i in range(n):
	m = int(input())
	p = list(map(int, input().split()))
	p1 = [p[0]]
	for j in p[1:]:
		if p1[-1] != j:
			p1.append(j)
	p = p1
	m = len(p)
	cou = {}
	for j in range(m):
		if p[j] not in cou.keys():
			cou[p[j]] = [0]
		cou[p[j]].append(j)
	ans1 = []
	alpha = []
	mi = m
	q = list(cou.keys())
	for j in q:
		ans = []
		for k in range(1, len(cou[j])):
			tem = cou[j][k] - cou[j][k - 1]
			if tem != 0:
				ans.append(tem)
		temp = m - cou[j][-1] - 1
		if temp != 0:
			ans.append(temp)
		ans1.append(len(ans))
		alpha.append(ans)
	print(min(ans1))


import sys

def answer(n, a):
	a_new = [a[0]]
	for i in range(1, n):
		if a[i] != a_new[-1]:
			a_new.append(a[i])
	if len(a_new) == 1:
		return 0
	cnt = [0] * (n + 1)
	legit = [False] * (n + 1)
	for e in a_new:
		cnt[e] += 1
		legit[e] = True
	cnt[a_new[0]] -= 1
	cnt[a_new[-1]] -= 1
	mn = 10 ** 10
	for i in range(len(cnt)):
		if legit[i]:
			mn = min(mn, cnt[i])
	return mn + 1

def main():
	t = int(input())
	while t:
		n = int(sys.stdin.readline())
		a = [int(i) for i in sys.stdin.readline().split()]
		print(answer(n, a))
		t -= 1
	return
main()


class problem:

	def __init__(self):
		self.t = int(input())

	def solve(self):
		while self.t != 0:
			n = int(input())
			nums = input().strip().split()
			arr = list(map(lambda x: int(x), nums))
			d = {}
			for (i, val) in enumerate(arr):
				if val in d:
					ele = i - d[val][0]
					if ele > 1:
						d[val][0] = i
						d[val][1] = d[val][1] + 1
					else:
						d[val][0] = i
				elif i > 0:
					d[val] = [i, 1]
				else:
					d[val] = [i, 0]
			ans = n + 1
			for (val, data) in d.items():
				if arr[n - 1] == val:
					ans = min(data[1], ans)
				else:
					ans = min(data[1] + 1, ans)
			print(ans)
			self.t -= 1
q1 = problem()
q1.solve()


for t in range(int(input())):
	n = int(input())
	M = [int(i) for i in input().split()]
	M1 = set(M)
	if len(M1) == 1:
		print(0)
	elif len(M1) == n:
		print(1)
	else:
		A = [[] for i in range(n + 1)]
		for i in range(n):
			A[M[i]].append(i + 1)
		A = list(filter(None, A))
		B = [2] * len(A)
		for i in range(len(A)):
			if A[i][0] == 1:
				B[i] -= 1
			if A[i][len(A[i]) - 1] == n:
				B[i] -= 1
			for j in range(len(A[i]) - 1):
				res = A[i][j + 1] - A[i][j]
				if res > 1:
					B[i] += 1
		small = B[0]
		for i in range(1, len(B)):
			if B[i] < small:
				small = B[i]
		print(small)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split())) + [-1]
		num_segs = [0] * (n + 1)
		first = None
		last = None
		for i in range(n):
			if a[i] != a[i + 1]:
				num_segs[a[i]] += 1
				if first is None:
					first = a[i]
				if i == n - 1:
					last = a[i]
		mn = 2 * n
		a.pop()
		for i in a:
			mn = min(mn, num_segs[i] - (first == i) - (last == i) + 1)
		print(mn)
prog()


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	d = dict()
	if len(set(a)) == 1:
		print(0)
		continue
	elif len(set(a)) == n:
		print(1)
		continue
	t = []
	for i in range(n):
		if i == 0:
			t.append(a[i])
		else:
			if t[-1] == a[i]:
				continue
			t.append(a[i])
	d = dict()
	for i in t:
		try:
			d[i] += 1
		except KeyError:
			d[i] = 1
	vis = dict()
	cnt = 0
	mn = int(1000000000.0)
	for i in t:
		try:
			if vis[i]:
				continue
		except KeyError:
			ans = 0
			vis[i] = 1
			if cnt == 0:
				if t[-1] == i:
					ans = max(0, d[i] - 1)
				else:
					ans = d[i]
			elif t[-1] == i:
				ans = max(0, d[i])
			else:
				ans = d[i] + 1
			cnt += 1
			mn = min(mn, ans)
	print(mn)


from sys import *
from collections import Counter
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	dic = {}
	for i in range(n):
		if arr[i] not in dic:
			if i == 0:
				dic[arr[i]] = 0
			else:
				dic[arr[i]] = 1
		elif arr[i - 1] != arr[i]:
			dic[arr[i]] += 1
	last = arr[-1]
	for i in set(arr):
		if i != last:
			dic[i] += 1
	print(min(dic.values()))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [a[0]]
	h = [0] * n
	h[a[0] - 1] = 1
	for i in range(1, n):
		h[a[i] - 1] = 1
		if a[i] == a[i - 1]:
			continue
		b.append(a[i])
	if len(b) == 1:
		print('0')
		continue
	c = [1] * n
	for i in range(len(b)):
		c[b[i] - 1] += 1
	c[b[0] - 1] -= 1
	if len(b) > 1:
		c[b[-1] - 1] -= 1
	ans = 10 ** 18
	for i in range(n):
		if h[i] == 1 and ans > c[i]:
			ans = c[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ls = []
	f = a[0]
	ls.append(f)
	for i in range(n):
		if a[i] == f:
			pass
		else:
			f = a[i]
			ls.append(f)
	n = len(ls)
	a = ls
	am = a.count(a[0])
	if a[0] == a[n - 1]:
		am -= 1
	else:
		am_l = a.count(a[n - 1])
		am = min(am, am_l)
	ls = sorted(a)
	ans = []
	i = -1
	test = ls[0]
	cnt = 0
	i = 0
	while i < n:
		if ls[i] == a[0] or ls[i] == a[n - 1]:
			pass
		else:
			test = ls[i]
			cnt = 0
			while ls[i] == test:
				cnt += 1
				i += 1
				if i == n:
					break
			ans.append(cnt)
			i -= 1
		i += 1
	ans.sort()
	print(max(0, min(ans[0] + 1 if ans else 100000, am)))


T = int(input())
for case in range(T):
	N = int(input())
	a = [int(x) for x in input().split(' ')]
	b = []
	for i in range(N - 1):
		if a[i] != a[i + 1]:
			b.append(a[i])
	b.append(a[N - 1])
	linker_rand = b[0]
	rechter_rand = b[len(b) - 1]
	b.sort()
	b.append(1000000)
	kleinste_anzahl = 1000000
	anzahl = 0
	element = -1
	for i in range(len(b)):
		if b[i] == element:
			anzahl += 1
		else:
			if element != -1:
				if element == linker_rand:
					anzahl -= 1
				if element == rechter_rand:
					anzahl -= 1
				if anzahl < kleinste_anzahl:
					kleinste_anzahl = anzahl
			element = b[i]
			anzahl = 1
	print(kleinste_anzahl + 1)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	numbers = dict()
	memory = l[0]
	for (i, a) in enumerate(l):
		if a != memory:
			if memory not in numbers.keys():
				numbers[memory] = set()
			numbers[memory].add(i - 1)
			memory = a
	temp = l[-1]
	if temp not in numbers.keys():
		numbers[temp] = {n - 1}
	else:
		numbers[temp].add(n - 1)
	if len(numbers.keys()) == 1:
		print(0)
		return
	min_operations = float('inf')
	for (k, v) in numbers.items():
		temp = len(v) + 1
		if k == l[0]:
			temp -= 1
		if k == l[-1]:
			temp -= 1
		temp = max(0, temp)
		min_operations = min(min_operations, temp)
	print(min_operations)
for _ in range(int(input())):
	solve()


from itertools import groupby
for _ in range(int(input())):
	input()
	arr = [x for (x, y) in groupby([int(x) for x in input().split()])]
	cnt = {x: 1 for x in arr}
	cnt[arr[0]] -= 1
	cnt[arr[len(arr) - 1]] -= 1
	for x in arr:
		cnt[x] += 1
	print(max(0, min(cnt.values())))


import math
import collections

def prob():
	n = int(input())
	l = [int(x) for x in input().split()]
	di = {}
	prev = 0
	for i in l:
		if i == prev:
			continue
		di[i] = di.get(i, 1) + 1
		prev = i
	di[l[0]] -= 1
	di[l[-1]] -= 1
	print(min(di.values()))
t = 1
t = int(input())
for _ in range(0, t):
	prob()


for i in range(int(input())):
	n = int(input())
	a = [int(X) for X in input().split()]
	b = []
	b.append(a[0])
	for j in range(1, n):
		if a[j] != a[j - 1]:
			b.append(a[j])
	d = {}
	for j in range(len(b)):
		d[b[j]] = 0
	for j in range(len(b)):
		d[b[j]] += 1
	d[b[len(b) - 1]] -= 1
	d[b[0]] -= 1
	print(min(d.values()) + 1)


from collections import Counter

def solution(items):
	cnt = Counter(items)
	cmns = cnt.most_common()
	if cmns[-1][1] == len(items):
		return 0
	min_res = float('inf')
	for i in range(len(cnt) - 1, -1, -1):
		if i == len(cnt) - 1:
			min_i = cmns[i][1]
		t = cmns[i][1] + 1
		if t - 2 > min_i:
			break
		if items[0] == cmns[i][0]:
			t -= 1
		if items[-1] == cmns[i][0]:
			t -= 1
		min_res = min(min_res, t)
	return min_res
t = int(input())
for _ in range(t):
	_ = input()
	items = tuple(map(int, input().split()))
	res = []
	for (idx, item) in enumerate(items):
		if idx == 0:
			res.append(item)
		elif item != res[-1]:
			res.append(item)
	print(solution(res))


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = [a[0]]
	d = {}
	for i in range(1, n):
		if b[-1] != a[i]:
			b.append(a[i])
	m = len(b)
	if m == 1:
		return 0
	for i in range(m):
		d[b[i]] = d.get(b[i], 0) + (1 if i < m - 1 and i > 0 else 0)
	return min(d.values()) + 1
t = int(input())
while t > 0:
	t -= 1
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	prev = a[0]
	count = {a[0]: 0, a[-1]: -1}
	for i in a:
		if i in count:
			if prev is not i:
				count[i] += 1
		else:
			count[i] = 1
		prev = i
	if len(count) == 1:
		print(0)
		continue
	print(min(count.values()) + 1)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[a[i]] = d.get(a[i], [])
		d[a[i]].append(i)
	if len(d) == 1:
		print(0)
	elif len(d) == n:
		print(1)
	else:
		sol = n + 1
		for k in d:
			t = k
			ma = len(d[k])
			ans = ma + 1
			if d[t][0] == 0:
				ans -= 1
			if d[t][-1] == n - 1:
				ans -= 1
			for i in range(1, ma):
				if d[t][i] == d[t][i - 1] + 1:
					ans -= 1
			sol = min(sol, ans)
		print(sol)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	n = ini()
	a = inl()
	count = dict()
	prev = -1
	for i in a:
		if i not in count:
			count[i] = 1
		if prev != i:
			count[i] += 1
		prev = i
	ans = n
	for i in a:
		ans = min(ans, count[i] - (1 if a[0] == i else 0) - (1 if a[-1] == i else 0))
	print(ans)