#include <iostream>
using namespace std;
int main()
{
	int n,a,b,mishka,chris,good;
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		cin>>a>>b;
		if (a>b)
		mishka++;
		else if(a==b)
		good++;
		else
		chris++;
	}
	if (mishka>chris)
	cout<<"Mishka";
	else if(chris>mishka)
	cout<<"Chris";
	else
	cout<<"Friendship is magic!^^";
}


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

int main(int argc, char const *argv[])
{
    ll i,j,k,t,m,n,value,r,q,c,z,a,b,d;
         cin>>n;
          pair< ll, ll> p;
             p.first=0;
             p.second=0;
         while(n--){
           cin>>a>>b;
           if(a>b){
             p.first++;
           }
           if(b<a){
           	  p.second++;
           }

         }

         if(p.first>p.second){
         	cout<<"Chris";
         }
         if( p.second>p.first){
         	cout<< "Mishka";
         }
         else{
         	cout<<"Friendship is magic!^^";
         }

    return 0;
}


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

int main(int argc, char const *argv[])
{
    ll i,j,k,t,m,n,value,r,q,c,z,a,b,d;
         cin>>n;
          pair< ll, ll> p;
             p.first=0;
             p.second=0;
         while(n--){
           cin>>a>>b;
           if(a>b){
             p.first++;
           }
           if(b<a){
           	  p.second++;
           }

         }

         if(p.first>p.second){
         	cout<<"Mishka";
         }
         else if( p.second>p.first){
         	cout<< "Chris";
         }
         else{
         	cout<<"Friendship is magic!^^";
         }

    return 0;
}


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

int main(int argc, char const *argv[])
{
    ll i,j,k,t,m,n,value,r,q,c,z,a,b,d;
         cin>>n;
          pair< ll, ll> p;
             p.first=0;
             p.second=0;
         while(n--){
           cin>>m>>c;
           if(m>c){
             p.first++;
           }
           if(c>m){
           	  p.second++;
           }

         }

         if(p.first>p.second){
         	cout<<"Mishka";
         }
         if( p.second>p.first){
         	cout<<"Chris";
         }
         if(p.first==p.second){
         	cout<<"Friendship is magic!^^";
         }

    return 0;
}


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

int main(int argc, char const *argv[])
{
    ll i,j,k,t,m,n,value,r,q,c,z,a,b,d;
         cin>>n;
          pair< ll, ll> p;
             p.first=0;
             p.second=0;
         while(n--){
           cin>>a>>b;
           if(a>b){
             p.first++;
           }
           if(b>a){
           	  p.second++;
           }

         }

         if(p.first>p.second){
         	cout<<"Mishka";
         }
         if( p.second>p.first){
         	cout<<"Chris";
         }
         else{
         	cout<<"Friendship is magic!^^";
         }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,a,b,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>a>>b;
       if(a>b)
        x++;
       else
        y++;
   }
   if(x>y)
    cout<<"Misha"<<endl;
   else if(x<y)
    cout<<"Chris"<<endl;
   else
    cout<<"Friendship is magic!^^"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,a,b,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>a>>b;
       if(a>b)
        x++;
       else
        y++;
   }
   if(x>y)
    cout<<"Mishka"<<endl;
   else if(x<y)
    cout<<"Chris"<<endl;
   else
    cout<<"Friendship is magic!^^"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,a,b,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>a>>b;
       if(a>b)
        x++;
       else
        y++;
   }
   if(x>y)
    cout<<"Mishka"<<endl;
    if(x<y)
    cout<<"Chris"<<endl;
   if(x==y)
    cout<<"Friendship is magic!^^"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,a,b,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>a>>b;
       if(a>b)
        x++;
       if(a<b)
        y++;
   }
   if(x>y)
    cout<<"Mishka"<<endl;
    if(x<y)
    cout<<"Chris"<<endl;
   if(x==y)
    cout<<"Friendship is magic!^^"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a,b,x=0,y=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        x+=a;
        y+=b;

    }
    if(x>y)
        cout<<"Mishka"<<endl;
    else if(x<y)
        cout<<"Chris"<<endl;
    else
        cout<<"Friendship is magic!^^"<<endl;
    return 0;
}


#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int i,n;
int sum1,sum2;
int main() {
	cin>>n;
	int m,c;
	for(i=1; i<=n; i++) {
		cin>>m>>c;
		if(m>c)
			sum1++;
		else if(m<c)
			sum2++;
	}
	if(sum1>sum2)
		cout<<"Mishka";
	else if(sum1==sum2)
		cout<<"Friendship is magic!^^";
	else
		cout<<"Chris";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,cnt1,cnt2;
int main(){
	ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1,a,b;i<=n;i++){
		cin>>a>>b;
		if(a>b)cnt1++;
		else if(a<b)cnt2++;
    }
    if(cnt1==cnt2)cout<<"Friendship is magic!^^";
    else if(cnt1>cnt2)cout<<"Mishka";
    else cout<<"Chris";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,a=0,b=0;
	cin>>n;
	while(n--)
	{
		int x,y;
		cin>>x>>y;
		if(x>y)a++;
		if(x<y)b++;
	}
	if(a>b)cout<<"Mishka";
	else if(a<b)cout<<"Chris";
	else cout<<"Friendship is magic!^^";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	cin>>k;
	int a[102],b[102];
	int cnta=0,cntb=0;
	for(int i=0;i<k;i++){
		cin>>a[i]>>b[i];
		if(a[i]<b[i])
			cntb++;
		else if(a[i]>b[i])
			cnta++;
	}
	if(cnta>cntb)
		cout<<"Mishka"<<endl;
	else if(cnta==cntb)
		cout<<"Friendship is magic!^^"<<endl;
	else
		cout<<"Chris"<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,b,c,d;
int main(){
	cin>>n;
	while(n--){
		cin>>c>>d;
		if(c>d)a++;
		if(d>c)b++;
	}
	if(a>b)puts("Mishka");
	else if(a==b)puts("Friendship is magic!^^");
	else puts("Chris");
	return 0;
}


#include<cstdio>
int n,a,b,s1,s2;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a,&b);
        if(a>b)s1++;
        if(a<b)s2++;
    }
    if(s1>s2)printf("Mishka");
    else if(s1<s2) printf("Chris");
    else printf("Friendship is magic!^^");
}


#include<iostream>
using namespace std;
int n,a,b,suma,sumb;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>b)  suma++;
		if(a<b)  sumb++;
	}
	if(suma>sumb)  cout<<"Mishka";
	if(suma<sumb)  cout<<"Chris";
	if(suma==sumb) cout<<"Friendship is magic!^^";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a, b, c, per1, pre2;
int main()
{
    cin >> a;
    for(int x = 1; x <= a; ++ x){
        cin >> b >> c;
        if(b > c)
            per1 ++;
        if(c > b)
            per2 ++ ;
    }
    if(per1 > per2){
        cout << "Mishka";
    }
    if(per1 == per2){
        cout << "Friendship is magic!^^";
    }
    if(per1 < per2){
        cout << "Chris";
    }
}


#include<bits/stdc++.h>
int ans1,ans2,a,b,i,j,k;//定义变量，ans1表示统计Mishka赢的次数，ans2表示统计Chris赢的次数
using namespace std;
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);noip时用的文件
    int n,m;
    cin>>n;//输入总次数
    for(i=1;i<=n;i++) {//边输入边做
    cin>>a>>b;
    if(a>b)ans1++;  //开始统计
    else if(a<b)ans2++;
    }
    if(ans1==ans2)cout<<"Friendship is magic!^^";
    if(ans1>ans2)cout<<"Mishka";
    if(ans1<ans2)cout<<"Chris";//输出
    return 0;//完美结束
}


from collections import defaultdict
for _ in range(int(input())):

    n=int(input())
    a=list(map(int,input().split()))
    d=dict()
    d1=defaultdict(int)
    for i in range(n):
        if a[i] not in d:
            if i!=0:
                d1[a[i]]+=1
        else:
            if i-d[a[i]]>1:
                d1[a[i]]+=1
        d[a[i]]=i
        ##print(d)
   ## print(d)
    ##print(d1)
    x1=list(d.keys())

    for i in range(len(x1)):
        if d[x1[i]]!=n-1:
            d1[x1[i]]+=1

    x=list(d1.values())
    print(min(x))


from collections import defaultdict
for _ in range(int(input())):

    n=int(input())
    a=list(map(int,input().split()))
    d=dict()
    d1=defaultdict(int)
    for i in range(n):
        if a[i] not in d:
            if i!=0:
                d1[a[i]]+=1
        else:
            if i-d[a[i]]>1:
                d1[a[i]]+=1
        d[a[i]]=i
        ##print(d)
   ## print(d)
    ##print(d1)
    x1=list(d.keys())

    for i in range(len(x1)):
        if d[x1[i]]!=n-1:
            d1[x1[i]]+=1

    x=list(d1.values())
    if len(x)==0:
        print(0)
    else:
        print(min(x))


def counts(arr):
    stat = []
    n = len(arr)
    for i in arr:
        if i not in stat:
            stat.append(i)

    minislands = n
    if len(stat) == 1:
        return 0
    elif len(stat) == n:
        return 1
    for x in stat:
        islands = 0
        changed = False
        for i in range(n):
            if arr[i] == x:
                if changed:
                    changed = False
            elif not changed:
                islands += 1
                if islands == minislands:
                    break
                changed = True
        minislands = min(minislands, islands)
        if not minislands:
            return 0

    return minislands

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

if __name__ == "__main__":
    main()


def counts(arr):
    stat = []
    n = len(arr)
    for i in arr:
        if i not in stat:
            stat.append(i)

    minislands = n
    if len(stat) == 1:
        return 0
    elif len(stat) == n:
        return 1
    for x in stat:
        islands = 0
        changed = False
        for i in range(n):
            if arr[i] == x:
                if changed:
                    changed = False
            elif not changed:
                islands += 1
                changed = True

        minislands = min(minislands, islands)
        if not minislands or minislands == 2:
            return minislands

    return minislands

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

if __name__ == "__main__":
    main()


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)

if __name__ == "__main__":
    main()


def counts(arr):
    stat = []
    n = len(arr)
    for i in arr:
        if i not in stat:
            stat.append(i)

    minislands = n
    for x in stat:
        islands = 0
        changed = False
        for i in range(n):
            if arr[i] == x:
                if changed:
                    changed = False
            elif not changed:
                islands += 1
                changed = True

        minislands = min(minislands, islands)
        if not minislands:
            return 0

    return minislands

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

if __name__ == "__main__":
    main()


def counts(arr):
    stat = []
    n = len(arr)
    for i in arr:
        if i not in stat:
            stat.append(i)

    minislands = n
    if len(stat) == 1:
        return 0
    elif len(stat) == n:
        return 1
    for x in stat:
        islands = 0
        changed = False
        for i in range(n):
            if arr[i] == x:
                if changed:
                    changed = False
            elif not changed:
                islands += 1
                changed = True

        minislands = min(minislands, islands)
        if not minislands:
            return 0

    return minislands

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

if __name__ == "__main__":
    main()


t = int(input())
for _ in range(t):
    n = int(input())
    nums = list(input().split())
    numSet = set(nums)
    numDict = {}
    cntDict = {}
    for num in numSet:
        numDict[num] = 0
        cntDict[num] = 0
    for num in nums:
        for key in numDict.keys():
            if num != key:
                cntDict[key] += 1
            else:
                if cntDict[key]:
                    numDict[key] += 1
                    cntDict[key] = 0
    for key in numDict.keys():
        if cntDict[key]:
            numDict[key] += 1
    print(min(numDict.values()))


t = int(input())
for _ in range(t):
  n = int(input())
  numList = list(map(int, input().split()))
  cntDict = {numList[0]: 0}
  resultDict = {numList[0]: 0}
  for i in range(1, len(numList)):
    for key in cntDict.keys():
      cntDict[key] += 1
    if i == len(numList) - 1:
      for key in cntDict.keys():
        if key != numList[i]:
          resultDict[key] += 1
    if numList[i] not in resultDict:
      resultDict[numList[i]] = 1
      cntDict[numList[i]] = 0
    else:
      if cntDict[numList[i]] > 1:
        resultDict[numList[i]] += 1
        cntDict[numList[i]] = 0
      else:
        cntDict[numList[i]] = 0
  print(min(resultDict.values()))


t = int(input())
for _ in range(t):
  n = int(input())
  numList = list(map(int, input().split()))
  resultDict = {numList[0]: 0}
  before = numList[0]
  for i in range(1, len(numList)):
    if i == len(numList) - 1:
      for key in resultDict.keys():
        if key != numList[i]:
          resultDict[key] += 1
    if numList[i] not in resultDict:
      resultDict[numList[i]] = 1
    else:
      if before != numList[i]:
        resultDict[numList[i]] += 1
    before = numList[i]
  print(min(resultDict.values()))


t = int(input())
for _ in range(t):
    n = int(input())
    nums = list(map(int, input().split()))
    numSet = set(nums)
    result_list = []
    for num in numSet:
        result = 0
        cnt = 0
        for i in nums:
            if i == num:
                if cnt:
                    result += 1
                    cnt = 0
            else:
                cnt += 1
        if cnt:
            result += 1
        result_list.append(result)
    print(min(result_list))


import sys
import math

from sys import stdin, stdout, setrecursionlimit
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)


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)


n = int(input())
from collections import Counter
for i in range(n):
    a = int(input())
    data = list(map(int, input().split()))
    d = Counter()
    f = data[0]
    d[data[0]] += 1
    for el in data[1:]:
        if el != f:
            d[el] += 1
            f = el
    d[data[0]] -= 1
    d[data[-1]] -= 1
    # if len(data) > 2:
    #     if data[-1] == data[-2]:
    #        d[data[-1]] -= 1
    if len(d) == 1:
        print(0)
    else:
        # print(d)
        print(min(d.values()) + 1)


n = int(input())
from collections import Counter
for i in range(n):
    a = int(input())
    data = list(map(int, input().split()))
    d = Counter()
    f = data[0]
    d[data[0]] += 1
    for el in data[1:-1]:
        if el != f:
            d[el] += 1
            f = el
    d[data[0]] -= 1
    if len(data) > 2:
        if data[-1] == data[-2]:
            d[data[-1]] -= 1
    if len(d) == 1:
        print(0)
    else:
        # print(d)
        print(min(d.values()) + 1)


n = int(input())
from collections import Counter
for i in range(n):
    a = int(input())
    data = list(map(int, input().split()))
    d = Counter()
    f = data[0]
    d[data[0]] += 1
    for el in data[1:-1]:
        if el != f:
            d[el] += 1
            f = el
    d[data[0]] -= 1
    if len(d) == 1:
        print(0)
    else:
        # print(d)
        print(min(d.values()) + 1)


for _ in range(int(input())):
    di = {}
    n = int(input())
    a = list(map(int,input().split()))
    sep = 0
    maximus = 1000000
    for i in range(n):
        if i+1<=n-1 and a[i]!=a[i+1]:
            if di.get(a[i],None)==None:
                di[a[i]]=2
            else:
                di[a[i]]=di[a[i]]+1
        elif i==n-1:
            if di.get(a[i],None)==None:
                di[a[i]]=2
            else:
                di[a[i]]=di[a[i]]+1
    di[a[0]]=di[a[0]]-1
    di[a[-1]]=di[a[-1]]-1
    for i in di.keys():
        if di[i]<maximus:
            maximus = di[i]

    print(maximus)


for _ in range(int(input())):
    di = {}
    n = int(input())
    a = list(map(int,input().split()))
    sep = 0
    maximus = 1000000
    for i in range(n):
        if i+1<n-1 and a[i]!=a[i+1]:
            if di.get(a[i],None)==None:
                di[a[i]]=2
            else:
                di[a[i]]=di[a[i]]+1
        elif i==n-1:
            if di.get(a[i],None)==None:
                di[a[i]]=2
            else:
                di[a[i]]=di[a[i]]+1

    di[a[0]]=di[a[0]]-1
    di[a[-1]]=di[a[-1]]-1
    for i in di.keys():
        if di[i]<maximus:
            maximus = di[i]

    print(maximus)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    count = {}
    same = 0
    for i in a:
        if i == a[0]:
            same += 1
        if i in count:
            count[i] += 1
        else:
            count[i] = 1
    ans = 9999999999999999
    if a[0] == a[-1]:
        ans = count[a[0]] - 1
    if same == n:
        print(0)
        continue
    ans = min(ans, min(count.values()) + 1, max(count.values()))
    print(ans)


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)


def lip(): return list(map(int,input().split()))
def splip(): return map(int,input().split())
def intip(): return int(input())

for _ in range(intip()):
    n = intip()
    a = lip()
    l = len(set(a))
    if l==1:
        print(0)
    elif l==n:
        print(1)
    elif a[0]==a[n-1] and a[0] not in set(a[1:n-1]):
        print(1)
    else:
        d={}
        min_so_far = int(1e5)
        for i in set(a):
            d[i]=[]
        for i in range(n):
            d[a[i]].append(i+1)
        for value in d.values():
            if len(value)==1:
                if value[0]==1 or value[0]==n:
                    min_so_far = 1
                    break
                else:
                    min_so_far = 2
                    break
            else:
                if value[0]==1 and value[len(value)-1]==n:
                    min_now = 0
                elif value[0]!=1 and value[len(value)-1]!=n:
                    min_now = 2
                elif value[0]==1 and value[len(value)-1]!=n:
                    min_now = 1
                elif value[0]!=1 and value[len(value)-1]==n:
                    min_now = 1
                for i in range(1,len(value)):
                    if value[i]-value[i-1] > 1:
                        min_now+=1
            if min_so_far > min_now:
                min_so_far = min_now
            if min_so_far==1:
                break
        print(min_so_far)


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:
                print(0)
                break
            else:
                if (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)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    d = {}
    for i in range(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:
            print(0)
            break
        else:
            if (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)


def lip(): return list(map(int,input().split()))
def splip(): return map(int,input().split())
def intip(): return int(input())

for _ in range(intip()):
    n = intip()
    a = lip()
    l = len(set(a))
    if l==1:
        print(0)
    elif l==n:
        print(1)
    elif a[0]==a[n-1] and a[0] not in set(a[1:n]):
        print(1)
    else:
        d={}
        min_so_far = int(1e5)
        for i in set(a):
            d[i]=[]
        for i in range(n):
            d[a[i]].append(i+1)
        for value in d.values():
            if len(value)==1:
                if value[0]==1 or value[0]==n:
                    min_so_far = 1
                    break
            else:
                if value[0]==1 and value[len(value)-1]==n:
                    min_now = 0
                elif value[0]!=1 and value[len(value)-1]!=n:
                    min_now = 2
                elif value[0]==1 and value[len(value)-1]!=n:
                    min_now = 1
                elif value[0]!=1 and value[len(value)-1]==n:
                    min_now = 1
                for i in range(1,len(value)):
                    if value[i]-value[i-1] > 1 and min_now<min_so_far:
                        min_now+=1
            if min_so_far > min_now:
                min_so_far = min_now
            if min_so_far==1:
                break
        print(min_so_far)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split())
    d = {}
    for i in range(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:
            print(0)
            break
        else:
            if (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)


def lip(): return list(map(int,input().split()))
def splip(): return map(int,input().split())
def intip(): return int(input())

for _ in range(intip()):
    n = intip()
    a = lip()
    l = len(set(a))
    if l==1:
        print(0)
    elif l==n:
        print(1)
    elif a[0]==a[n-1] and a[0] not in set(a[1:n]):
        print(1)
    else:
        d={}
        min_so_far = int(1e5)
        for i in set(a):
            d[i]=[]
        for i in range(n):
            d[a[i]].append(i+1)
        for value in d.values():
            if len(value)==1:
                if value[0]==1 or value[0]==n:
                    min_so_far = 1
                    break
                else:
                    min_so_far = 2
                    break
            else:
                if value[0]==1 and value[len(value)-1]==n:
                    min_now = 0
                elif value[0]!=1 and value[len(value)-1]!=n:
                    min_now = 2
                elif value[0]==1 and value[len(value)-1]!=n:
                    min_now = 1
                elif value[0]!=1 and value[len(value)-1]==n:
                    min_now = 1
                for i in range(1,len(value)):
                    if value[i]-value[i-1] > 1 and min_now<min_so_far:
                        min_now+=1
            if min_so_far > min_now:
                min_so_far = min_now
            if min_so_far==1:
                break
        print(min_so_far)


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
            else:
                if (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)


def lip(): return list(map(int,input().split()))
def splip(): return map(int,input().split())
def intip(): return int(input())

for _ in range(intip()):
    n = intip()
    a = lip()
    l = len(set(a))
    if l==1:
        print(0)
    elif l==n:
        print(1)
    elif a[0]==a[n-1] and a[0] not in set(a[1:n]):
        print(1)
    else:
        d={}
        min_so_far = int(1e5)
        for i in set(a):
            d[i]=[]
        for i in range(n):
            d[a[i]].append(i+1)
        for value in d.values():
            if len(value)==1:
                if value[0]==1 or value[0]==n:
                    min_so_far = 1
                    break
            else:
                if value[0]==1 and value[len(value)-1]==n:
                    min_now = 0
                elif value[0]!=1 and value[len(value)-1]!=n:
                    min_now = 2
                elif value[0]==1 and value[len(value)-1]!=n:
                    min_now = 1
                elif value[0]!=1 and value[len(value)-1]==n:
                    min_now = 1
                if(len(value)!=2):
                    for i in range(1,len(value)):
                        if value[i]-value[i-1] > 1 and min_now<min_so_far:
                            min_now+=1
            if min_so_far > min_now:
                min_so_far = min_now
            if min_so_far==1:
                break


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    d = {}
    d[a[0]]= 1
    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:
            print(0)
            break
        else:
            if (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)


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)

if __name__ == '__main__':
    resolve()


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 + 1)]
        for i in range(n):
            section[A[i]].append(i)

        res = f_inf
        for sec in section:
            if len(sec) == 0:
                continue
            sec.append(n - 1)
            cnt = 0
            now = 0
            for idx in sec:
                if idx - now > 1:
                    cnt += 1
                now = idx
            res = min(res, cnt)
        print(res)

if __name__ == '__main__':
    resolve()


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 = 0
            for idx in sec:
                if idx - now > 1:
                    cnt += 1
                now = idx
            if now != n - 1:
                cnt += 1
            res = min(res, cnt)
        print(res)

if __name__ == '__main__':
    resolve()


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 a[j]==a[0]:
                d[a[j]]=0
            else:
                d[a[j]]=1
            if a[j]!=a[j+1]:
                d[a[j]]+=1
        else:
            if a[j]!=a[j+1]:
                d[a[j]]+=1

    print(min(d.values()))


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
        else:
            if a[j]!=a[j+1]:
                d[a[j]]+=1
    if d=={}:
        print(0)
    else:

        print(min(d.values()))


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 a[j]==a[0]:
                d[a[j]]=0
            else:
                d[a[j]]=1
            if a[j]!=a[j+1]:
                d[a[j]]+=1
        else:
            if a[j]!=a[j+1]:
                d[a[j]]+=1
    print(d)
    print(min(d.values()))


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
        else:
            if 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()))


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 a[j]==a[0]:
                d[a[j]]=0
            else:
                d[a[j]]=1
            if a[j]!=a[j+1]:
                d[a[j]]+=1
        else:
            if a[j]!=a[j+1]:
                d[a[j]]+=1
    if d=={}:
        print(0)
    else:

        print(min(d.values()))


for a0 in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    s=set(l)
    if(len(s)==1):
        print(0)
    else:
        ans=[]
        for i in s:
            r=0
            tp=[x for x in l]
            co = tp.count(i)
            for az in range(co):
                rs=tp.index(i)
                if rs!=0:
                    r+=1
                del tp[:rs+1]
            if len(tp)>0:
                r+=1
            ans.append(r)
        print(min(ans))


for a0 in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    s=set(l)
    if(len(s)==1):
        print(0)
    else:
        ans=[]
        for i in s:
            # print("**",i)
            r=0
            tp=[x for x in l]
            co=l.count(i)
            for tt in range(co):
                x=tp.index(i)
                if tt == co-1:
                    rr=tp.index(i)
                    if rr>0 and rr<len(tp)-1:
                        r+=2
                    elif len(tp)>1:
                        r+=1
                else:
                    if x==0:
                        del tp[0]
                        rr=tp.index(i)
                        del tp[:rr]
                        r+=1
                    else:
                        del tp[:x+1]
                        r+=1
            ans.append(r)
        print(min(ans))


for a0 in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    s=dict()
    ans=[]
    for i in range(len(l)):
        if l[i] not in s.keys():
            if i>0:
                s[l[i]]=[1,i]
            else:
                s[l[i]]=[0,0]
            if l[-1]!=l[i]:
                s[l[i]][0]+=1
        else:
            if i-s[l[i]][1]>1:
                s[l[i]][0]+=1
            s[l[i]][1]=i
    for i in s.values():
        ans.append(i[0])
    print(min(ans))


for a0 in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    s=set(l)
    if(len(s)==1):
        print(0)
    else:
        ans=[]
        for i in s:
            # print("**",i)
            r=0
            tp=[x for x in l]
            co=l.count(i)
            for tt in range(co):
                x=tp.index(i)
                if tt == co-1:
                    if x>0 and x<len(tp)-1:
                        r+=2
                    elif len(tp)>1:
                        r+=1
                else:
                    if x==0:
                        del tp[0]
                        rr=tp.index(i)
                        if rr!=0:
                            del tp[:rr]
                            r+=1
                    else:
                        del tp[:x+1]
                        rr=tp.index(i)
                        del tp[:rr]
                        r+=2
                # print("***",tp,r)
            ans.append(r)
        # print("&&",ans)
        print(min(ans))


from collections import Counter
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    an=Counter(a)
    x=an.most_common(1)[0][0]
    y=an.most_common()[-1][0]
    ansx=0
    ansy=0
    cx=0
    cy=0
    for z in a:
        if z!=x and cx==0:
            ansx+=1
            cx=1
        elif z!=x and cx==1:
            pass
        elif z==x:
            cx=0
        if z!=y and cy==0:
            ansy+=1
            cy=1
        elif z!=y and cy==1:
            pass
        elif z==y:
            cy=0
    print(min(ansx,ansy))


for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    si=0
    for z in range(1,n):
        if a[z]==a[z-1]:
            si=z
    a=a[si:]
    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()))
    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)


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()
    ans = dict()
    count = dict()
    index = 0
    for i in a:
        if i not in count:
            count[i] = index
        else:
            if i not in ans:
                ans[i] = 1
            if ans[i] != index - 1:
                ans[i] += 1
        index += 1
    if len(ans) == 0:
        print(1)
    elif len(ans) == 1:
        print(0)
    else:
        if a[0] == a[-1]:
            ans[a[0]] -= 2
        ans = sorted(ans.items(), key=lambda x: x[1])[0]
        print(ans[1] + 1)


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()
    ans = dict()
    count = dict()
    index = 0
    for i in a:
        if i not in count:
            count[i] = index
        else:
            if i not in ans:
                ans[i] = 1
            if ans[i] != index - 1:
                ans[i] += 1
        index += 1
    if len(ans) == 1 or n == 1:
        print(0)
    elif len(ans) == 0:
        print(1)
    else:
        if a[0] == a[-1]:
            ans[a[0]] -= 2
        ans = sorted(ans.items(), key=lambda x: x[1])[0]
        print(ans[1] + 1)


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)


for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    m=max(l)
    d={}
    last=0
    c=0
    s=set(l)
    for i in s:
        d[i]=0
    for i in l:
        if(i!=last):
            d[i] += 1
            last=i
    a=n+1
    if(l[0]==l[-1]):
        d[l[0]] -= 2
    # d[l[0]] -= 1
    # d[l[-1]] -= 1
    for i in d.keys():
        a=min(a,d[i])
    if(len(s)==len(l)):
        print(1)
    elif(len(d.keys())==1):
        print(0)
    else:
        print(a+1)


for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    f={}
    for i in set(l):
        f[i]=0
    last=0
    for i in range(n):
        if(l[i]!=last):
            f[l[i]] += 1
            last=l[i]
    for i in f.keys():
        f[i] += 1
    f[l[0]] -= 1
    f[l[-1]] -= 1
    print(min(f.values()))


t = int(input())
for j in range(0,t):
    s = int(input())
    l1 = [int(x) for x in input().split()]
    val_f = l1[0]
    s_ind = 1
    for i in range(1,len(l1)):
        if l1[i]==val_f:
            s_ind+=1
        else:
            break
    if s_ind==s:
        print(0)
    else:
        e_ind = len(l1)-1
        val_e = l1[-1]
        for i in range(len(l1)-2,-1,-1):
            if l1[i]==val_e:
                e_ind-=1
            else:
                break
        c = []
        for i in range(0,s+1):
            c.append(0)
        for i in range(s_ind,e_ind):
            c[l1[i]]+=1
        if c[l1[0]]==0:
            print(1)
        else:
            ind =0
            mini = 0
            for i in range(0,len(c)):
                if mini==0 and c[i]!=0:
                    mini = c[i]
                    ind = i
                elif mini>c[i] and c[i]!=0:
                    mini = c[i]
                    ind = i
            print(mini+1)


t = int(input())
for j in range(0,t):
    s = int(input())
    l1 = [int(x) for x in input().split()]
    val_f = l1[0]
    s_ind = 1
    for i in range(1,len(l1)):
        if l1[i]==val_f:
            s_ind+=1
        else:
            break
    if s_ind==s:
        print(0)
    else:
        e_ind = len(l1)-1
        val_e = l1[-1]
        for i in range(len(l1)-2,-1,-1):
            if l1[i]==val_e:
                e_ind-=1
            else:
                break
        count = 0
        for i in range(e_ind-1,s_ind-1,-1):
            if l1[i]==val_e:
                count+=1
        if count==0:
            print(1)
        else:
            c = []
            for i in range(0,s+1):
                c.append(0)
            for i in range(s_ind,e_ind):
                c[l1[i]]+=1
            if c[l1[0]]==0:
                print(1)
            else:
                ind =0
                mini = 0
                for i in range(0,len(c)):
                    if mini==0 and c[i]!=0:
                        mini = c[i]
                        ind = i
                    elif mini>c[i] and c[i]!=0:
                        mini = c[i]
                        ind = i
                print(mini+1)


t = int(input())
for j in range(0,t):
    s = int(input())
    l1 = [int(x) for x in input().split()]
    val_f = l1[0]
    s_ind = 1
    for i in range(1,len(l1)):
        if l1[i]==val_f:
            s_ind+=1
        else:
            break
    if s_ind==s:
        print(0)
    else:
        e_ind = len(l1)-1
        val_e = l1[-1]
        for i in range(len(l1)-2,-1,-1):
            if l1[i]==val_e:
                e_ind-=1
            else:
                break
        count = 0
        for i in range(e_ind-1,s_ind-1,-1):
            if l1[i]==val_e:
                count+=1
        if count==0:
            print(1)
        else:
            c = []
            for i in range(0,s+1):
                c.append(0)
            for i in range(s_ind,e_ind):
                if l1[i]!=l1[i-1]:
                    c[l1[i]]+=1
                # print("hi")
            # print(c[l1[0]])
            if c[l1[0]]==0:
                print(1)
            else:
                ind =0
                mini = 0
                # print(c)
                for i in range(0,len(c)):
                    if mini==0 and c[i]!=0:
                        mini = c[i]
                        ind = i
                    elif mini>c[i] and c[i]!=0:
                        mini = c[i]
                        ind = i
                # print(mini)
                print(mini+1)


from collections import Counter
t = int(input())
for i in range(t):
    n = int(input())
    l = [int(j) for j in input().split()]
    c = Counter(l)
    mini = float('inf')
    minival = -1
    for j in c:
        if c[j]==1:
            mini = min(mini, j)
            minival = j

    if c[l[0]]==1 or c[l[-1]]==1 or (l[0]==l[-1] and c[l[0]]==2):
        print(1)
    elif len(set(l))==1:
        print(0)
    elif mini==1:
        print(2)
    else:

        tcount = float('inf')
        #3 3 3 5 4 56 5 4 6 3  3 2 3 6 7 3 3 3

        # 1 1 3 4 2 2 3 4 1 1 1
        for k in c:
            j=0
            count = 0
            countstarting=0
            minival=k
            while(j<n and l[j]==minival):
                j+=1
                countstarting+=1

            while(j<n):
                while(j<n and l[j]!=minival):
                    j+=1
                count+=1

                while(j<n and l[j]==minival):
                    j+=1

            tcount = min(count, tcount)
        print(tcount)


from collections import Counter
t = int(input())
for i in range(t):
    n = int(input())
    l = [int(j) for j in input().split()]
    c = Counter(l)
    mini = float('inf')
    minival = -1
    for j in c:
        if c[j]==1:
            mini = min(mini, j)
            minival = j

    if n==1:
        print(0)
    elif c[l[0]]==1 or c[l[-1]]==1 or (l[0]==l[-1] and c[l[0]]==2):
        print(1)
    elif len(set(l))==1:
        print(0)
    elif mini==1:
        print(2)
    else:

        tcount = float('inf')
        #3 3 3 5 4 56 5 4 6 3  3 2 3 6 7 3 3 3

        # 1 1 3 4 2 2 3 4 1 1 1
        for k in c:
            j=0
            count = 0
            countstarting=0
            minival=k
            while(j<n and l[j]==minival):
                j+=1
                countstarting+=1

            while(j<n):
                while(j<n and l[j]!=minival):
                    j+=1
                count+=1

                while(j<n and l[j]==minival):
                    j+=1

            tcount = min(count, tcount)
        print(tcount)


from collections import Counter
t = int(input())
for i in range(t):
    n = int(input())
    l = [int(j) for j in input().split()]
    c = Counter(l)
    mini = float('inf')
    minival = -1
    for j in c:
        if c[j]==1:
            mini = min(mini, j)
            minival = j

    if n==1:
        print(0)
    elif len(set(l))==1:
        print(0)
    elif c[l[0]]==1 or c[l[-1]]==1 or (l[0]==l[-1] and c[l[0]]==2):
        print(1)

    elif mini==1:
        print(2)
    else:

        tcount = float('inf')
        #3 3 3 5 4 56 5 4 6 3  3 2 3 6 7 3 3 3

        # 1 1 3 4 2 2 3 4 1 1 1
        for k in c:
            j=0
            count = 0
            countstarting=0
            minival=k
            while(j<n and l[j]==minival):
                j+=1
                countstarting+=1

            while(j<n):
                while(j<n and l[j]!=minival):
                    j+=1
                count+=1

                while(j<n and l[j]==minival):
                    j+=1

            tcount = min(count, tcount)
        print(tcount)


from collections import Counter
t = int(input())
for i in range(t):
    n = int(input())
    l = [int(j) for j in input().split()]
    c = Counter(l)
    mini = float('inf')
    minival = -1
    for j in c:
        if c[j]==1:
            mini = min(mini, j)
            minival = j

    if n==1:
        print(0)
    elif len(set(l))==1:
        print(0)
    elif c[l[0]]==1 or c[l[-1]]==1 or (l[0]==l[-1] and c[l[0]]==2):
        print(1)
    else:

        tcount = float('inf')
        #3 3 3 5 4 56 5 4 6 3  3 2 3 6 7 3 3 3

        # 1 1 3 4 2 2 3 4 1 1 1
        for k in c:
            j=0
            count = 0
            countstarting=0
            minival=k
            while(j<n and l[j]==minival):
                j+=1
                countstarting+=1

            while(j<n):
                while(j<n and l[j]!=minival):
                    j+=1
                count+=1

                while(j<n and l[j]==minival):
                    j+=1

            tcount = min(count, tcount)
        print(tcount)


from collections import Counter
t = int(input())
for i in range(t):
    n = int(input())
    l = [int(j) for j in input().split()]
    c = Counter(l)
    mini = float('inf')
    minival = -1
    for j in c:
        if c[j]==1:
            mini = min(mini, j)
            minival = j

    if n==1:
        print(0)
    elif len(set(l))==1:
        print(0)
    elif c[l[0]]==1 or c[l[-1]]==1 or (l[0]==l[-1] and c[l[0]]==2):
        print(1)
    else:

        tcount = float('inf')
        #3 3 3 5 4 56 5 4 6 3  3 2 3 6 7 3 3 3

        # 1 1 3 4 2 2 3 4 1 1 1
        '''

        1 1 2 3 3 4 3 3 3 3 2 1  =>  1 2 3 1 3 2 3
        '''
        newl = [l[0]]
        prev = l[0]
        for i in range(n):
            if l[i]!=prev:
                prev = l[i]
                newl.append(l[i])

        c = Counter(newl)
        minival = -1
        mini = 10000000000000
        for j in c:
            if c[j]<mini:
                minival = j
                mini = c[j]

        for k in [minival, newl[0], newl[-1]]:
            j=0
            count = 0
            countstarting=0
            minival=k
            while(j<n and l[j]==minival):
                j+=1
                countstarting+=1

            while(j<n):
                while(j<n and l[j]!=minival):
                    j+=1
                count+=1

                while(j<n and l[j]==minival):
                    j+=1

            tcount = min(count, tcount)
        print(tcount)


import sys
t=int(input().strip())
for a0 in range(t):
     n=int(input())
     l=[int(i) for i in input().split()]
     h1=[]
     h2=[]
     h3=[]
     for i in range(n+1):
         h1.append(-1)
         h3.append(-1)
         h2.append(0)
     for i in range(n):
            h3[l[i]]=1
            if(i==0):

                h1[l[i]]=i;
            else:

                if(h1[l[i]]==-1):

                    h2[l[i]]+=1
                    h1[l[i]]=i

                else:
                    if(i-h1[l[i]]!=1):
                        h2[l[i]]+=1
                        h1[l[i]]=i
     for i in range(n+1):
         if(i!=l[n-1] and h3[i]!=-1):
             h2[i]+=1
     z=0
     for i in range(n-1):
         if(l[i]!=l[i+1]):
             z=1
             break
     if(z==0):
         print(0)
     else:

         d=n+2
         for i in range(n+1):
             if(h2[i]!=0):
                 d=min(d,h2[i])
         print(d)


import sys
t=int(input().strip())
for a0 in range(t):
     n=int(input())
     l=[int(i) for i in input().split()]
     h1=[]
     h2=[]
     h3=[]
     for i in range(n+1):
         h1.append(-1)
         h3.append(-1)
         h2.append(0)
     for i in range(n):
            h3[l[i]]=1
            if(i==0):

                h1[l[i]]=i;
            else:

                if(h1[l[i]]==-1):

                    h2[l[i]]+=1
                    h1[l[i]]=i
                else:
                    if(i-h1[l[i]]!=1):
                        h2[l[i]]+=1
                        h1[l[i]]=i
                    else:
                        h1[l[i]]=i
     for i in range(n+1):
         if(i!=l[n-1] and h3[i]!=-1):
             h2[i]+=1
     z=0
     for i in range(n-1):
         if(l[i]!=l[i+1]):
             z=1
             break
     if(z==0):
         print(0)
     else:
         d=n+2
         for i in range(n+1):
             if(h2[i]!=0):
                 d=min(d,h2[i])
         print(d)


for _ in range(int(input())):
    d={}
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    while i<n:
        if l[i] not in d:
            d[l[i]]=1
        else:
            d[l[i]]+=1
        x=i+1
        a=l[i]
        while x<n and l[x]==a:
            x+=1
        i=x
    m=n+1
    for i in d:
        if d[i]<m:
            m=d[i]
    ans=m+1
    if len(set(l))==1:
        print(0)
    else:
        if m+1>=d[l[0]]:
            ans=d[l[0]]
            if l[0]==l[-1]:
                ans-=1
        elif m+1>=d[l[-1]]:
            ans=d[l[-1]]
        print(ans)


for _ in range(int(input())):
    d={}
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    while i<n:
        if l[i] not in d:
            d[l[i]]=1
        else:
            d[l[i]]+=1
        x=i+1
        a=l[i]
        while x<n and l[x]==a:
            x+=1
        i=x
    m=n+1
    for i in d:
        if d[i]<m:
            m=d[i]
    ans=m+1
    if len(set(l))==1:
        print(0)
    else:
        if m+1>=d[l[0]]:
            ans=d[l[0]]
            if l[0]==l[-1]:
                ans-=1
        if m+1>=d[l[-1]]:
            ans=min(ans,d[l[-1]])
        print(ans)


for _ in range(int(input())):
    d={}
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    while i<n:
        if l[i] not in d:
            d[l[i]]=1
        else:
            d[l[i]]+=1
        x=i+1
        a=l[i]
        while x<n and l[x]==a:
            x+=1
        i=x
    m=n+1
    for i in d:
        if d[i]<m:
            m=d[i]
    ans=m+1
    if len(set(l))==1:
        print(0)
    elif m+1>=d[l[0]]:
        ans=d[l[0]]
        if l[0]==l[-1]:
            ans-=1
    elif m+1>=d[l[-1]]:
        ans=d[l[-1]]
    print(ans)


def do():
    d = {}
    for e in data:
        d[e] = d.get(e, 1) + 1
    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())


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

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(1, 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()))


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()))


import sys

t = int(input())
for num in range(t):
    n = int(sys.stdin.readline())
    seq = list(map(int, sys.stdin.readline().split()))
    dic = {}
    dic[seq[0]] = 1
    for i in range(1, len(seq) - 1):
        if seq[i] != seq[i+1]:
            if seq[i] not in dic:
                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()))


t = int(input())
while t>0:
    n = int(input())
    seq = list(map(int,input().split()))
    freq = {}
    for i in seq:
        if i in freq:
            freq[i] +=1
        else:
            freq[i] = 1
    if len(freq) ==1:
        print("0")
        t-=1
        continue
    if max(freq.values()) == 1:
        print("1")
        t-=1
        continue
    j = []
    for k in freq.keys():
        jump = 0
        occ = 0
        r = 0
        for i in range(len(seq)):
            if k == seq[i] and occ==0:
                occ +=1
                continue
            if k == seq[i] and occ!=0 and seq[i-1]!=k:
                jump +=1
                #print("here1")
                r = 0
            if k != seq[i]:
                r +=1
        if seq[0] != k:
            jump += 1
        if r >=1:
            jump +=1
            #print("here2")
        j.append(jump)
    print(min(j))
    t-=1


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())
while t>0:
    n = int(input())
    seq = list(map(int,input().split()))
    freq = {}
    for i in seq:
        if i in freq:
            freq[i] +=1
        else:
            freq[i] = 1
    if len(freq) ==1:
        print("0")
        t-=1
        continue
    if max(freq.values()) == 1:
        print("1")
        t-=1
        continue
    for k in freq.keys():
        j = []
        jump = 0
        occ = 0
        r = 0
        for i in range(len(seq)):
            if k == seq[i] and occ==0:
                occ +=1
                continue
            if k == seq[i] and occ!=0:
                jump +=1
                #print("here1")
                r = 0
            if k != seq[i]:
                r +=1
        if r >=1:
            jump +=1
            #print("here2")
        j.append(jump)
    print(min(j))
    t-=1


from collections import Counter
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if len(l)==1 or len(set(l))==1:
        print(0)
    elif len(set(l))==n:
        print(1)
    else:
        z=Counter(l)
        lst=sorted(list(z.values()))
        out=[]
        for w in range(len(lst)):
            tmp=[]
            for i in z:
                if z[i]==lst[w]:
                    tmp.append(i)
            for i in tmp:
                if l[0]==i and l[-1]==i:
                    out.append(lst[w]-1)
                    break
                elif l[0]==i and l[-1]==i:
                    out.append(lst[w])
                else:
                    out.append(lst[w]+1)
        print(min(out))


for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if n==1 or len(set(l))==1:
        print(0)
    elif len(set(l))==n:
        print(1)
    else:
        pre=-1
        z={}
        for i in l:
            if pre!=i:
                if i in z:
                    z[i]+=1
                else:
                    z[i]=1
            pre=i
        lst=sorted(list(z.values()))
        out=[]
        for w in range(min(3,len(lst))):
            tmp=[]
            for i in z:
                if z[i]==lst[w]:
                    tmp.append(i)
            for i in tmp:
                if l[0]==i and l[-1]==i:
                    out.append(lst[w]-1)
                    break
                elif l[0]==i or l[-1]==i:
                    out.append(lst[w])
                else:
                    out.append(lst[w]+1)
        print(min(out))


from collections import Counter
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if len(l)==1 or len(set(l))==1:
        print(0)
    elif len(set(l))==n:
        print(1)
    else:
        z=Counter(l)
        lst=sorted(list(z.values()))
        out=[]
        for w in range(len(lst)):
            tmp=[]
            for i in z:
                if z[i]==lst[w]:
                    tmp.append(i)
            for i in tmp:
                if l[0]==i and l[-1]==i:
                    out.append(lst[w]-1)
                    break
                elif l[0]==i or l[-1]==i:
                    out.append(lst[w])
                else:
                    out.append(lst[w]+1)
        print(min(out))


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)


from collections import Counter
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if len(l)==1 or len(set(l))==1:
        print(0)
    elif len(set(l))==n:
        print(1)
    else:
        z=Counter(l)
        lst=sorted(list(z.values()))
        #print(lst)
        out=[]
        for w in range(min(len(lst),3)):
            tmp=[]
            for i in z:
                if z[i]==lst[w]:
                    tmp.append(i)
            #print(tmp)
            for i in tmp:
                if l[0]==i and l[-1]==i:
                    out.append(lst[w]-1)
                    break
                elif l[0]==i and l[-1]==i:
                    out.append(lst[w])
        if len(out)==0:
            print(lst[0]+1)
        else:
            print(min(lst[0]+1,min(out)))


for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if n==1 or len(set(l))==1:
        print(0)
    elif len(set(l))==n:
        print(1)
    else:
        pre=-1
        z={}
        for i in l:
            if pre!=i:
                if i in z:
                    z[i]+=1
                else:
                    z[i]=1
            pre=i
        lst=sorted(list(z.values()))
        out=[]
        for w in range(2):
            tmp=[]
            for i in z:
                if z[i]==lst[w]:
                    tmp.append(i)
            for i in tmp:
                if l[0]==i and l[-1]==i:
                    out.append(lst[w]-1)
                    break
                elif l[0]==i or l[-1]==i:
                    out.append(lst[w])
                else:
                    out.append(lst[w]+1)
        print(min(out))


for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if n==1 or len(set(l))==1:
        print(0)
    elif len(set(l))==n:
        print(1)
    else:
        pre=-1
        z={}
        for i in l:
            if pre!=i:
                if i in z:
                    z[i]+=1
                else:
                    z[i]=1
            pre=i
        lst=sorted(list(z.values()))
        out=[]
        for w in range(len(lst)):
            tmp=[]
            for i in z:
                if z[i]==lst[w]:
                    tmp.append(i)
            for i in tmp:
                if l[0]==i and l[-1]==i:
                    out.append(lst[w]-1)
                    break
                elif l[0]==i or l[-1]==i:
                    out.append(lst[w])
                else:
                    out.append(lst[w]+1)
        print(min(out))


import sys
for _ in range(int(input())):
	n=int(sys.stdin.readline())
	m = 1000000000000000000000
	arr = sys.stdin.readline().split()
	elements = set(arr[:])
	#combine consecutive identical
	i=0
	while 1:
		if i==len(arr)-1:
			break
		if arr[i+1]==arr[i]:
			del arr[i]
		else:
			i+=1

	for element in elements:
		if arr[-1] == element and arr[0] == element:
			m = min(m,arr.count(element)-1)
		elif arr[-1] != element and arr[0] != element:
			m = min(m,arr.count(element)+1)
		else:
			m = min(m,arr.count(element))
	print(m)


import sys
for _ in range(int(input())):
	n=int(sys.stdin.readline())
	m = 1000000000000000000000
	dic = {}
	arr = sys.stdin.readline().split()
	elements = set(arr[:])
	#combine consecutive identical
	i=0
	arr+=[-1]
	while 1:
		if i==len(arr)-1:
			break
		if arr[i+1]==arr[i]:
			del arr[i+1]
		else:
			if arr[i] in dic:
				dic[arr[i]] += 1
			else:
				dic[arr[i]] = 1
			i+=1
	del arr[-1]
	if len(arr)==1:
		print(0)
	else:
		for element in elements:
			if arr[-1] == element and arr[0] == element:
				m = min(m,dic[element]-1)
			elif arr[-1] != element and arr[0] != element:
				m = min(m,dic[element]+1)
			else:
				m = min(m,dic[element])
		print(m)


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si(): return input()

def ii(): return int(input())

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

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

def out(v): print(v)

def spout(): print(v, end=" ")

def d2b(n): return bin(n).replace("0b", "")

def twod(n, m, num): return [[num for x in range(m)] for y in range(n)]

def vow(): return ['a', 'e', 'i', 'o', 'u']

def let(): return [chr(i) for i in range(97, 123)]

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

def ispow2(x):
    return (x and (not (x & (x - 1))))

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1: factors.append(n)
    return (list(factors))

t = ii()
while t:
    t -= 1
    n=ii()
    a=li()
    d=dd(list)
    ls={}
    for i in range(n):
        try:
            if ls[a[i]]+1!=i:
                ls[a[i]] = i
                d[a[i]].append(i)
            else:
                ls[a[i]]=i
        except KeyError:
            ls[a[i]]=i
            d[a[i]].append(i)
    if len(d)==1: print(0)
    elif len(d)==n: print(1)
    else:
        ans=999999999
        for i in d.keys():
            if len(d[i])==1:
                if d[i][0]==0 or a[d[i][0]]==a[-1]:
                    ans=1
                    break
                else:
                    ans=min(2,ans)
            else:
                #print(i,d)
                if d[i][0] == 0 and a[d[i][-1]] == a[-1]:
                    ans=min(ans,len(d[i])-1)
                elif d[i][0]==0 or a[d[i][-1]]==a[-1]:
                    ans=min(ans,len(d[i]))
                else: ans=min(ans,len(d[i])+1)
        print(ans)


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si(): return input()

def ii(): return int(input())

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

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

def out(v): print(v)

def spout(): print(v, end=" ")

def d2b(n): return bin(n).replace("0b", "")

def twod(n, m, num): return [[num for x in range(m)] for y in range(n)]

def vow(): return ['a', 'e', 'i', 'o', 'u']

def let(): return [chr(i) for i in range(97, 123)]

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

def ispow2(x):
    return (x and (not (x & (x - 1))))

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1: factors.append(n)
    return (list(factors))

t = ii()
while t:
    t -= 1
    n=ii()
    a=li()
    d=dd(list)
    for i in range(n):
        d[a[i]].append(i)
    if len(d)==1: print(0)
    elif len(d)==n: print(1)
    else:
        ans=999999999
        for i in d.keys():
            if len(d[i])>1:
                if d[i][0]==0:
                    if d[i][-1]==n-1: ans=min(ans,len(d[i])-1)
                    else: ans=min(ans,len(d[i]))
                elif d[i][-1]==n-1:
                    ans=min(len(d),ans)
                else:
                    ans=min(ans,len(d[i])+1)
        print(ans)


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si(): return input()

def ii(): return int(input())

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

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

def out(v): print(v)

def spout(): print(v, end=" ")

def d2b(n): return bin(n).replace("0b", "")

def twod(n, m, num): return [[num for x in range(m)] for y in range(n)]

def vow(): return ['a', 'e', 'i', 'o', 'u']

def let(): return [chr(i) for i in range(97, 123)]

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

def ispow2(x):
    return (x and (not (x & (x - 1))))

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1: factors.append(n)
    return (list(factors))

t = ii()
while t:
    t -= 1
    n=ii()
    a=li()
    d=dd(list)
    ls={}
    for i in range(n):
        try:
            if ls[a[i]]+1!=i:
                d[a[i]].append(i)
            else:
                ls[a[i]]=i
        except KeyError:
            ls[a[i]]=i
            d[a[i]].append(i)
    if len(d)==1: print(0)
    elif len(d)==n: print(1)
    else:
        ans=999999999
        for i in d.keys():
            if len(d[i])==1:
                if d[i][0]==0 or a[d[i][0]]==a[-1]:
                    ans=1
                    break
                else:
                    ans=min(2,ans)
            else:
                #print(i,d)
                if d[i][0] == 0 and a[d[i][-1]] == a[-1]:
                    ans=min(ans,len(d[i])-1)
                elif d[i][0]==0 or a[d[i][-1]]==a[-1]:
                    ans=min(ans,len(d[i]))
                else: ans=min(ans,len(d[i])+1)
        print(ans)


for _ in range(int(input())):
	n=int(input())
	dic={}
	lis=list(map(int,input().split()))
	se=set(lis)
	for i in se:
		dic[i]=[-1,0]
	for i in range(len(lis)):
		if dic[lis[i]][0]+1==i:
			dic[lis[i]][0]=i
		else:
			dic[lis[i]][1]+=1
			dic[lis[i]][0]=i

	for i in dic:
		if i!=lis[-1]:
			dic[i][1]+=1
	ans=float('Inf')

	if len(dic)==1:
		print(0)
		continue
	for i in dic:
		ans=min(ans,dic[i][1])
	print(ans)


for _ in range(int(input())):
	n=int(input())
	dic={}
	lis=list(map(int,input().split()))
	se=set(lis)
	for i in se:
		dic[i]=[1,-1]
	for i in range(len(lis)):
		if dic[lis[i]][0]+1==i:
			dic[lis[i]][0]=i
		else:
			dic[lis[i]][1]+=1
			dic[lis[i]][0]=i
	for i in dic:
		if dic[i]!=lis[-1]:
			dic[i][1]+=1
	ans=float('Inf')
	if len(dic)==1:
		print(0)
		continue
	for i in dic:
		ans=min(ans,dic[i][1])
	print(ans+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:
        t = 0
        ma = n + 1
        dif = 0
        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]:
                    ans -= 1
            sol = min(sol, ans)
        print(sol)


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]:
                    ans -= 1
            sol = min(sol, ans)
        print(sol)


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)


# Design_by_JOKER

from math import *
from cmath import *
from itertools import *
from decimal import *  # su dung voi so thuc
from fractions import *  # su dung voi phan so
from sys import *
#from numpy import *

'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r')  a = input.readline()
out = open(".out", mode='w') a.index(val) '''

for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	for x in range(n+5):
		b.append([])
	dem = 0
	for x in input().split():
		a.append(int(x))
		b[int(x)].append(dem)
		dem += 1
	ok = 0
	if n == 1:
		print(0)
		continue
	ans = n+9
	for x in a:
		if len(b[x]) == 1:
			if b[x][0] == 0 or b[x][0] == n-1:
				print(1)
				ok = 1
				break
		elif len(b[x]) == n:
			print(0)
			ok = 1
			break
		else:
			res = 0
			if b[x][0] > 0:
				res += 1
			if b[x][-1] < n-1:
				res += 1
			res += len(b[x]) - 1
			ans = min(ans, res)
	if not ok:
		print(ans)


# Design_by_JOKER

from math import *
from cmath import *
from itertools import *
from decimal import *  # su dung voi so thuc
from fractions import *  # su dung voi phan so
from sys import *
#from numpy import *

'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r')  a = input.readline()
out = open(".out", mode='w') a.index(val) '''

for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = []
	c = [0] * (n+2)
	b.append(a[0])
	c[a[0]] += 1
	for x in range(1, n):
		if a[x] != a[x-1]:
			b.append(a[x])
			c[a[x]] += 1
	ans = n+5
	for x in b:
		res = c[x] + 1
		if b[0] == x:
			res -= 1
		if b[-1] == x:
			res -= 1
		ans = min(res, ans)
	print(ans)


# Design_by_JOKER

from math import *
from cmath import *
from itertools import *
from decimal import *  # su dung voi so thuc
from fractions import *  # su dung voi phan so
from sys import *
#from numpy import *

'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r')  a = input.readline()
out = open(".out", mode='w') a.index(val) '''

for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	for x in range(n+5):
		b.append([])
	dem = 0
	for x in input().split():
		a.append(int(x))
		b[int(x)].append(dem)
		dem += 1
	ok = 0
	ans = n+9
	for x in a:
		if len(b[x]) == 1:
			if b[x][0] == 0 or b[x][0] == n-1:
				print(1)
				ok = 1
				break
		elif len(b[x]) == n:
			print(0)
			ok = 1
			break
		else:
			res = 0
			if b[x][0] > 0:
				res += 1
			if b[x][-1] < n-1:
				res += 1
			res += len(b[x]) - 1
			ans = min(ans, res)
	if not ok:
		print(ans)


# Design_by_JOKER

from math import *
from cmath import *
from itertools import *
from decimal import *  # su dung voi so thuc
from fractions import *  # su dung voi phan so
from sys import *
#from numpy import *

'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r')  a = input.readline()
out = open(".out", mode='w') a.index(val) '''

for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	for x in range(n+5):
		b.append([])
	dem = 0
	for x in input().split():
		a.append(int(x))
		b[int(x)].append(dem)
		dem += 1
	ok = 0
	if n == 1:
		print(0)
		continue
	ans = n+9
	for x in a:
		if len(b[x]) == 1:
			if b[x][0] == 0 or b[x][0] == n-1:
				print(1)
				ok = 1
				break
		elif len(b[x]) == n:
			print(0)
			ok = 1
			break
		else:
			res = 0
			if b[x][0] > 0:
				res += 1
			if b[x][-1] < n-1:
				res += 1
			for y in range(1, len(b[x])):
				if b[x][y] == b[x][y-1]+1:
					res += 0
				else: res += 1
			ans = min(ans, res)
	if not ok:
		print(ans)


# Design_by_JOKER

from math import *
from cmath import *
from itertools import *
from decimal import *  # su dung voi so thuc
from fractions import *  # su dung voi phan so
from sys import *
#from numpy import *

'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r')  a = input.readline()
out = open(".out", mode='w') a.index(val) '''

for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = []
	c = [0] * (n+2)
	b.append(a[0])
	c[a[0]] += 1
	for x in range(1, n):
		if a[x] != a[x-1]:
			b.append(a[x])
			c[a[x]] += 1
	ans = n+5
	print(b)
	for x in b:
		res = c[x] + 1
		if b[0] == x:
			res -= 1
		if b[-1] == x:
			res -= 1
		ans = min(res, ans)
	print(ans)


from collections import *
for _ in range(int(input())):
    n = int(input())
    l = [*map(int,input().split())]
    dic = defaultdict(set)
    for i in range(n):
        dic[l[i]].add(i)

    ans = 10 ** 7
    if len(dic) == 1:
        print(0)
        continue
    for i in dic:
        if 0 not in dic[i] and n - 1 not in dic[i]:
            ans = min(ans, len(dic[i]) + 1)
        elif 0 in dic[i] and n - 1 not in dic[i]:
            ans = min(ans, len(dic[i]))
        elif n - 1 in dic[i] and 0 not in dic[i]:
            ans = min(ans, len(dic[i]))
        else:
            ans = min(ans, len(dic[i]) - 1)
    print(ans)


from collections import *
for _ in range(int(input())):
    n = int(input())
    l = [*map(int,input().split())]
    dic = defaultdict(set)
    for i in range(n):
        dic[l[i]].add(i)

    ans = 10 ** 7
    if len(dic) == 1:
        print(0)
        continue
    for i in dic:
        if 0 not in dic[i] and n - 1 not in dic[i]:
            if len(dic[i]) > 1:
                ans = min(ans, len(dic[i]) + 1)
            else:
                ans = min(ans, len(dic[i]))
        elif 0 in dic[i] and n - 1 not in dic[i]:
            ans = min(ans, len(dic[i]))
        elif n - 1 in dic[i] and 0 not in dic[i]:
            ans = min(ans, len(dic[i]))
        else:
            ans = min(ans, len(dic[i]) - 1)
    print(ans)


from collections import *
from itertools import groupby
for _ in range(int(input())):
    n = int(input())
    m = [*map(int,input().split())]
    l = [i[0] for i in groupby(m)]
    if n == 1:
        print(0)
        continue
    n = len(l)
    dic = defaultdict(set)
    for i in range(n):
        dic[l[i]].add(i)
    ans = 10 ** 7
    if len(dic) == 1:
        print(0)
        continue
    for i in dic:
        if 0 not in dic[i] and n - 1 not in dic[i]:
            ans = min(ans, len(dic[i]) + 1)
            if len(dic[i]) == 1 and len(dic) == 2:
                ans = min(ans, len(dic[i]))
        elif 0 in dic[i] and n - 1 not in dic[i]:
            ans = min(ans, len(dic[i]))
        elif n - 1 in dic[i] and 0 not in dic[i]:
            ans = min(ans, len(dic[i]))
        else:
            ans = min(ans, len(dic[i]) - 1)
    print(ans)


from collections import *
for _ in range(int(input())):
    n = int(input())
    m = [*map(int,input().split())]
    l = []
    i = 0
    while(i < n):
        if i < n - 1 and m[i] == m[i + 1]:
            i += 1
            continue
        else:
            l.append(m[i])
            i += 1
    if n >= 2 and m[-1] == m[-2]:
        l.append(m[-1])
    if n == 1:
        print(0)
        continue
    n = len(l)
    dic = defaultdict(set)
    for i in range(n):
        dic[l[i]].add(i)

    ans = 10 ** 7
    if len(dic) == 1:
        print(0)
        continue
    for i in dic:
        if 0 not in dic[i] and n - 1 not in dic[i]:
            if len(dic[i]) > 1:
                ans = min(ans, len(dic[i]) + 1)
            else:
                ans = min(ans, len(dic[i]))
        elif 0 in dic[i] and n - 1 not in dic[i]:
            ans = min(ans, len(dic[i]))
        elif n - 1 in dic[i] and 0 not in dic[i]:
            ans = min(ans, len(dic[i]))
        else:
            ans = min(ans, len(dic[i]) - 1)
    print(ans)


def CountFrequency(my_list):
    freq = {}
    for item in my_list:
        if (item in freq):
            freq[item] += 1
        else:
            freq[item] = 1
    return freq
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    arr=[l[0]]
    for i in range(1,n):
        if(arr[-1]!=l[i]):
            arr.append(l[i])
    d=CountFrequency(arr)
    d[arr[0]]-=1
    d[arr[-1]]-=1
    print(d)
    print(min(d.values())+1)


#include<cstdio>
int i,fl,n,la,ra,da,ua,l,r,mid,tmp,ans[9],cnt;
inline int ask(int lx,int ly,int rx,int ry){
    if(lx>rx||ly>ry)return 0;
    printf("? %d %d %d %d\n",lx,ly,rx,ry);
    fflush(stdout);scanf("%d",&lx);return lx;
}
inline void sol(int lx,int ly,int rx,int ry){
    l=lx,r=rx,tmp=lx;
    while(l<=r){
        mid=(l+r)>>1;ua=ask(mid,ly,rx,ry);
        if(!ua)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ly;
    while(l<=r){
        mid=(l+r)>>1;ra=ask(lx,mid,rx,ry);
        if(!ra)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=lx,r=rx,tmp=rx;
    while(l<=r){
        mid=(l+r)>>1;da=ask(lx,ly,mid,ry);
        if(!da)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ry;
    while(l<=r){
        mid=(l+r)>>1;la=ask(lx,ly,rx,mid);
        if(!la)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp;
}
int main()
{
    scanf("%d",&n);
    l=1,r=n,fl=0;
    while(l<=r){
        mid=(l+r)>>1;
        la=ask(1,1,n,mid),ra=ask(1,mid+1,n,n);
        if(la&&ra)fl=1;
        if(!la)l=mid+1;else r=mid-1;
    }
    if(fl)sol(1,1,n,l),sol(1,l+1,n,n);
    else{
        l=1,r=n;
        while(l<=r){
           mid=(l+r)>>1;
           da=ask(1,1,mid,n);
           if(!da)l=mid+1;else r=mid-1;
        }sol(1,1,l,n),sol(l+1,1,n,n);
    }
    for(putchar('!'),i=1;i<9;i++)printf("%d ",ans[i]);fflush(stdout);
}


#include<cstdio>
int i,fl,n,la,ra,da,ua,l,r,mid,tmp,ans[9],cnt;
inline int ask(int lx,int ly,int rx,int ry){
    if(lx>rx||ly>ry)return 0;
    printf("? %d %d %d %d\n",lx,ly,rx,ry);
    fflush(stdout);scanf("%d",&lx);return lx;
}
inline void sol(int lx,int ly,int rx,int ry){
    int l=lx,r=rx,tmp=lx;
    while(l<=r){
        mid=(l+r)>>1;ua=ask(mid,ly,rx,ry);
        if(!ua)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ly;
    while(l<=r){
        mid=(l+r)>>1;ra=ask(lx,mid,rx,ry);
        if(!ra)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=lx,r=rx,tmp=rx;
    while(l<=r){
        mid=(l+r)>>1;da=ask(lx,ly,mid,ry);
        if(!da)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ry;
    while(l<=r){
        mid=(l+r)>>1;la=ask(lx,ly,rx,mid);
        if(!la)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp;
}
int main()
{
    scanf("%d",&n);
    l=1,r=n,fl=cnt=0;
    while(l<=r){
        mid=(l+r)>>1;
        la=ask(1,1,n,mid),ra=ask(1,mid+1,n,n);
        if(la&&ra)fl=1;
        if(!la)l=mid+1;else r=mid-1;
    }
    if(fl)sol(1,1,n,l),sol(1,l+1,n,n);
    else{
        l=1,r=n;
        while(l<=r){
           mid=(l+r)>>1;
           da=ask(1,1,mid,n);
           if(!da)l=mid+1;else r=mid-1;
        }
		sol(1,1,l,n);
		sol(l+1,1,n,n);
    }
    for(putchar('!'),putchar(' '),i=1;i<9;i++)printf("%d ",ans[i]);fflush(stdout);
}


#include<cstdio>
int i,fl,n,la,ra,da,ua,l,r,mid,tmp,ans[9],cnt;
inline int ask(int lx,int ly,int rx,int ry){
    if(lx>rx||ly>ry)return 0;
    printf("? %d %d %d %d\n",lx,ly,rx,ry);
    fflush(stdout);scanf("%d",&lx);return lx;
}
inline void sol(int lx,int ly,int rx,int ry){
    l=lx,r=rx,tmp=lx;
    while(l<=r){
        mid=(l+r)>>1;ua=ask(mid,ly,rx,ry);
        if(!ua)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ly;
    while(l<=r){
        mid=(l+r)>>1;ra=ask(lx,mid,rx,ry);
        if(!ra)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=lx,r=rx,tmp=rx;
    while(l<=r){
        mid=(l+r)>>1;da=ask(lx,ly,mid,ry);
        if(!da)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ry;
    while(l<=r){
        mid=(l+r)>>1;la=ask(lx,ly,rx,mid);
        if(!la)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp;
}
int main()
{
    scanf("%d",&n);
    l=1,r=n,fl=0;
    while(l<=r){
        mid=(l+r)>>1;
        la=ask(1,1,n,mid),ra=ask(1,mid+1,n,n);
        if(la&&ra)fl=1;
        if(!la)l=mid+1;else r=mid-1;
    }
    if(fl)sol(1,1,n,l),sol(1,l+1,n,n);
    else{
        l=1,r=n;
        while(l<=r){
           mid=(l+r)>>1;
           da=ask(1,1,mid,n);
           if(!da)l=mid+1;else r=mid-1;
        }sol(1,1,l,n),sol(l+1,1,n,n);
    }
    for(putchar('!'),putchar(' '),i=1;i<9;i++)printf("%d ",ans[i]);fflush(stdout);
}


#include<cstdio>
int i,fl,n,la,ra,da,ua,l,r,mid,tmp,ans[9],cnt;
inline int ask(int lx,int ly,int rx,int ry){
    if(lx>rx||ly>ry)return 0;
    printf("? %d %d %d %d\n",lx,ly,rx,ry);
    fflush(stdout);scanf("%d",&lx);return lx;
}
inline void sol(int lx,int ly,int rx,int ry){
    l=lx,r=rx,tmp=lx;
    while(l<=r){
        mid=(l+r)>>1;ua=ask(mid,ly,rx,ry);
        if(!ua)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ly;
    while(l<=r){
        mid=(l+r)>>1;ra=ask(lx,mid,rx,ry);
        if(!ra)r=mid-1;else l=mid+1,tmp=mid;
    }ans[++cnt]=tmp,l=lx,r=rx,tmp=rx;
    while(l<=r){
        mid=(l+r)>>1;da=ask(lx,ly,mid,ry);
        if(!da)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp,l=ly,r=ry;tmp=ry;
    while(l<=r){
        mid=(l+r)>>1;la=ask(lx,ly,rx,mid);
        if(!la)l=mid+1;else r=mid-1,tmp=mid;
    }ans[++cnt]=tmp;
}
int main()
{
    scanf("%d",&n);
    l=1,r=n,fl=0;
    while(l<=r){
        mid=(l+r)>>1;
        la=ask(1,1,n,mid),ra=ask(1,mid+1,n,n);
        if(la&&ra)fl=1;
        if(!la)l=mid+1;else r=mid-1;
    }
    if(fl)sol(1,1,n,l),sol(1,l+1,n,n);
    else{
        l=1,r=n;
        while(l<=r){
           mid=(l+r)>>1;
           da=ask(1,1,mid,n);
           if(!da)mid+1;else r=mid-1;
        }sol(1,1,l,n),sol(l+1,1,n,n);
    }
    for(putchar('!'),i=1;i<9;i++)printf("%d ",ans[i]);fflush(stdout);
}


#include<bits/stdc++.h>
#define MAXN 3005
#define LL long long
using namespace std;

const int U=0,D=1,L=2,R=3;
int now[4];
int cur[4],ans1[4],ans2[4];
int n;

int check() {
	int ret;
	printf("? %d %d %d %d",now[U],now[L],now[D],now[R]);
	//fflush(stdout);
	scanf("%d",&ret);
	return ret;
}

int main() {
	scanf("%d",&n);
	now[U]=now[L]=1;now[D]=now[R]=n;

	///**********************************
	int l=1,r=n;
	while(r-l>1) {
		now[U]=l+r>>1;
		if(check()==2) l=now[U];
		else r=now[U];
	}
	if(check()!=2) now[U]--;
	l=now[U],r=n;
	while(r-l>1) {
		now[D]=l+r>>1;
		if(check()==2) r=now[D];
		else l=now[D];
	}
	if(check()!=2) now[D]++;
	l=1,r=n;
	while(r-l>1) {
		now[R]=l+r>>1;
		if(check()==2) r=now[R];
		else l=now[R];
	}
	if(check()!=2) now[R]++;
	l=1,r=now[R];
	while(r-l>1) {
		now[L]=l+r>>1;
		if(check()==2) l=now[L];
		else r=now[L];
	}
	if(check()!=2) now[L]--;

	for(int i=0;i<5;i++) cur[i]=now[i];

	///**********************************************
	l=now[U],r=now[D];
	while(r-l>1) {
		now[U]=l+r>>1;
		if(check()>0) l=now[U];
		else r=now[U];
	}
	if(check()<1) now[U]--;
	l=now[U],r=now[D];
	while(r-l>1) {
		now[D]=l+r>>1;
		if(check()>0) r=now[D];
		else l=now[D];
	}
	if(check()<1) now[D]++;
	l=now[L],r=now[R];
	while(r-l>1) {
		now[R]=l+r>>1;
		if(check()>0) r=now[R];
		else l=now[R];
	}
	if(check()<1) now[R]++;
	l=now[L],r=now[R];
	while(r-l>1) {
		now[L]=l+r>>1;
		if(check()>0) l=now[L];
		else r=now[L];
	}
	if(check()<1) now[L]--;
	for(int i=0;i<5;i++) ans1[i]=now[i];
	for(int i=0;i<5;i++) now[i]=cur[i];

	///*************************************
	l=now[U],r=now[D];
	while(r-l>1) {
		now[D]=l+r>>1;
		if(check()>0) r=now[D];
		else l=now[D];
	}
	if(check()<1) now[D]++;
	l=now[U],r=now[D];
	while(r-l>1) {
		now[U]=l+r>>1;
		if(check()>0) l=now[U];
		else r=now[U];
	}
	if(check()<1) now[U]--;
	l=now[L],r=now[R];
	while(r-l>1) {
		now[L]=l+r>>1;
		if(check()>0) l=now[L];
		else r=now[L];
	}
	if(check()<1) now[L]--;
	l=now[L],r=now[R];
	while(r-l>1) {
		now[R]=l+r>>1;
		if(check()>0) r=now[R];
		else l=now[R];
	}
	if(check()<1) now[R]++;
	bool flag=1;
	for(int i=0;i<5;i++) {
		if(ans1[i]!=now[i]) flag=0;
	}
	if(flag) for(int i=0;i<5;i++) ans2[i]=cur[i];
	else for(int i=0;i<5;i++) ans2[i]=now[i];
	///***************************************
	printf("! %d %d %d %d %d %d %d %d",ans1[U],ans1[L],ans1[D],ans1[R],ans2[U],ans2[L],ans2[D],ans2[R]);
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 3005
#define LL long long
using namespace std;

const int U=0,D=1,L=2,R=3;
int now[MAXN];
int cur1[MAXN],cur2[MAXN],ans1[MAXN],ans2[MAXN];
int n;

int check(int a,int b,int c,int d) {
	int ret;
	printf("? %d %d %d %d\n",a,b,c,d);
	fflush(stdout);
	scanf("%d",&ret);
	return ret;
}

int main() {
	scanf("%d",&n);
	cur1[U]=cur1[L]=cur2[U]=cur2[L]=now[U]=now[L]=1;
	cur1[D]=cur1[R]=cur2[D]=cur2[R]=now[D]=now[R]=n;

	///**********************************
	int l=1,r=n,mid;
	while(r>=l) {
		mid=l+r>>1;
		if(check(mid,now[L],now[D],now[R])>0) l=mid+1,now[U]=mid;
		else r=mid-1;
	}
	if(check(now[U],now[L],now[D],now[R])==1&&check(1,now[L],now[U]-1,now[R])==1) {
		cur1[U]=now[U];cur2[D]=now[U]-1;
	}
	else {
		l=1,r=n;now[U]=1;
		while(r>=l) {
			mid=l+r>>1;
			if(check(now[U],now[L],now[D],mid)>0) r=mid-1,now[R]=mid;
			else l=mid+1;
		}
		cur1[R]=now[R];cur2[L]=now[R]+1;
	}

	///**********************************************
	for(int i=0;i<5;i++) now[i]=cur1[i];
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(mid,now[L],now[D],now[R])>0) l=mid+1,now[U]=mid;
		else r=mid-1;
	}
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],mid,now[R])>0) r=mid-1,now[D]=mid;
		else l=mid+1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],now[D],mid)>0) r=mid-1,now[R]=mid;
		else l=mid+1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],mid,now[D],now[R])>0) l=mid+1,now[L]=mid;
		else r=mid-1;
	}
	for(int i=0;i<5;i++) ans1[i]=now[i];

	///*************************************
	for(int i=0;i<5;i++) now[i]=cur2[i];
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],mid,now[R])>0) r=mid-1,now[D]=mid;
		else l=mid+1;
	}
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(mid,now[L],now[D],now[R])>0) l=mid+1,now[U]=mid;
		else r=mid-1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],mid,now[D],now[R])>0) l=mid+1,now[L]=mid;
		else r=mid-1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],now[D],mid)>0) r=mid-1,now[R]=mid;
		else l=mid+1;
	}
	for(int i=0;i<5;i++) ans2[i]=now[i];
	///***************************************
	printf("! %d %d %d %d %d %d %d %d\n",ans1[U],ans1[L],ans1[D],ans1[R],ans2[U],ans2[L],ans2[D],ans2[R]);
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 3005
#define LL long long
using namespace std;

const int U=0,D=1,L=2,R=3;
int now[MAXN];
int cur[MAXN],ans1[MAXN],ans2[MAXN];
int n;

int check(int a,int b,int c,int d) {
	int ret;
	printf("? %d %d %d %d\n",a,b,c,d);
	fflush(stdout);
	scanf("%d",&ret);
	return ret;
}

int main() {
	scanf("%d",&n);
	now[U]=now[L]=1;now[D]=now[R]=n;

	///**********************************
	int l=1,r=n,mid;
	while(r>=l) {
		mid=l+r>>1;
		if(check(mid,now[L],now[D],now[R])==2) l=mid+1,now[U]=mid;
		else r=mid-1;
	}
	l=now[U],r=n;
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],mid,now[R])==2) r=mid-1,now[D]=mid;
		else l=mid+1;
	}
	l=1,r=n;
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],now[D],mid)==2) r=mid-1,now[R]=mid;
		else l=mid+1;
	}
	l=1,r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],mid,now[D],now[R])==2) l=mid+1,now[L]=mid;
		else r=mid-1;
	}
	for(int i=0;i<5;i++) cur[i]=now[i];

	///**********************************************
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(mid,now[L],now[D],now[R])>0) l=mid+1,now[U]=mid;
		else r=mid-1;
	}
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],mid,now[R])>0) r=mid-1,now[D]=mid;
		else l=mid+1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],now[D],mid)>0) r=mid-1,now[R]=mid;
		else l=mid+1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],mid,now[D],now[R])>0) l=mid+1,now[L]=mid;
		else r=mid-1;
	}
	for(int i=0;i<5;i++) ans1[i]=now[i];
	for(int i=0;i<5;i++) now[i]=cur[i];

	///*************************************
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],mid,now[D],now[R])>0) l=mid+1,now[L]=mid;
		else r=mid-1;
	}
	l=now[L],r=now[R];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],now[D],mid)>0) r=mid-1,now[R]=mid;
		else l=mid+1;
	}
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(now[U],now[L],mid,now[R])>0) r=mid-1,now[D]=mid;
		else l=mid+1;
	}
	l=now[U],r=now[D];
	while(r>=l) {
		mid=l+r>>1;
		if(check(mid,now[L],now[D],now[R])>0) l=mid+1,now[U]=mid;
		else r=mid-1;
	}
	bool flag=1;
	for(int i=0;i<5;i++) {
		if(ans1[i]!=now[i]) flag=0;
	}
	if(flag) for(int i=0;i<5;i++) ans2[i]=cur[i];
	else for(int i=0;i<5;i++) ans2[i]=now[i];
	///***************************************
	printf("! %d %d %d %d %d %d %d %d\n",ans1[U],ans1[L],ans1[D],ans1[R],ans2[U],ans2[L],ans2[D],ans2[R]);
	fflush(stdout);
	return 0;
}