You are given a sequence $A_1, A_2, \ldots, A_N$. You want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \le i \le N$), then choose $j = i-1$ or $j = i+1$ (it is not allowed to choose $j = 0$ or $j = N+1$) and change the value of $A_i$ to $A_j$ — in other words, you should replace the value of one element of the sequence by one of its adjacent elements.
What is the minimum number of moves you need to make in order to make all the elements of the sequence equal?

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer — the minimum required number of moves.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 100$
- $1 \le A_i \le 100$ for each valid $i$

-----Example Input-----
3
5
1 1 1 1 1
4
9 8 1 8
2
1 9

-----Example Output-----
0
2
1

-----Explanation-----
Example case 1: No moves are needed since all the elements are already equal.
Example case 3: We can perform one move on either $A_1$ or $A_2$.

Difficulty: interview

Starter code:

Solutions:
for _ in range(int(input())):
 n=int(input())
 a=[int(z) for z in input().split()]
 m=0
 a1=list(set(a))
 for i in range(len(a1)):
  if a.count(a1[i])>m:
   m=a.count(a1[i])
 print(n-m)
 
   


# cook your dish here
for _ in range(int(input())):
 n=int(input())
 d={}
 l=list(map(int,input().split()))
 for i in l:
  d[i]=l.count(i)
 x=0
 
 for j in d:
  if d[j]>x:
   x=d[j]
 print(n-x)


# cook your dish here
for _ in range(int(input())):
 n=int(input())
 l=list(map(int,input().split()))
 final=[]
 x=sorted(l,key=l.count)
 for i in x:
  if i!=x[-1]:
   final.append(i)
 print(len(final))
 


# cook your dish here
t=int(input());
for i in range(t):
 n=int(input());
 a=list(map(int,input().split()))[:n];
 c=0;
 d=0;
 e=0;
 ma=0;
 index=0
 for i in range(len(a)):
  j=i+1;
  for k in range(j,len(a)):
   if a[i]==a[k]:
    c=c+1;
    break;
 #print(c);
 if c==len(a)-1:
  print((0));
 else:
  for i in range(len(a)):
   j=i+1;
   f=1;
   for k in range(j,len(a)):
    if a[i]==a[k]:
     f=f+1;
   #print(f);
   if f>ma:
    ma=f;
    index=a[i];
  #print(ma,index)
  #print(new);
  for i in [index]:
   for j in range(len(a)):
    if i!=a[j]:
     #print(i,a[j])
     d=d+1;
  #print(d);
  if d>0:
   print(d);
  else:
   for i in range(1,len(a)):
    if a[0]!=a[i]:
     #print(a[0],a[i]);
     e=e+1;
   print(e);
   
 
   
   
 


for i in range(int(input())):
 n=int(input())
 t=input().split()
 m=set(t)
 ma=0
 for j in m:
  x=t.count(j)
  if(ma<x):
   ma=x
 print(n-ma)

for i in range(int(input())):
 n=int(input())
 t=input().split()
 m=set(t)
 ma=0
 for j in m:
  x=t.count(j)
  if(ma<x):
   ma=x
 print(n-ma)

t=int(input())
for i in range(t):
 n=int(input())
 a=input().split()
 b=set(a)
 ma=0
 for j in b:
  p=a.count(j)
  if(ma<p):
   ma=p
 print(n-ma)

# cook your dish here
for _ in range(int(input())):
 n=int(input())
 a=list(map(int,input().split()))
 l=[]
 for i in a:
  l.append(a.count(i))
 #print(s1,l2)
 print(n-a.count(a[l.index(max(l))]))
  


# vivek hirpara
for _ in range(int(input())):
 n=int(input())
 s1=list(map(int,input().split()))
 l2=[]
 for i in s1:
  l2.append(s1.count(i))
 #print(s1,l2)
 print(n-s1.count(s1[l2.index(max(l2))]))
  


# cook your dish here
for t in range(int(input())):
 n=int(input())
 a=[int(x)for x in input().rstrip().split()]
 b=list(set(a))
 max1=0
 for i in range(0,len(b)):
  s=a.count(b[i])
  if s>max1:
   max1=s
 print(n-max1)

# cook your dish here
from collections import Counter
for i in range(int(input())):
 n = int(input())
 l = list(map(int,input().split()))
 x = dict(Counter(l))
 m = max(list(x.values()))
 print(n-m)

# cook your dish here
for _ in range(int(input())):
 n=int(input())
 arr=list(map(int,input().split()))
 m=0
 s=list(set(arr))
 for i in range(len(s)):
  m=max(m,arr.count(s[i]))
 print(n-m)

for _ in range (int(input())):
 a = int(input())
 ass = list(map(int , input().split()))
 b = 0
 for i in range(a):
  if ass.count(ass[i]) > b:
   b = ass.count(ass[i])
 print(a - b)


# cook your dish here
for _ in range (int(input())):
 n = int(input())
 ass = list(map(int , input().split()))
 m = 0
 for i in range(n):
  if ass.count(ass[i]) > m:
   m = ass.count(ass[i])
 print(n - m)

# cook your dish here
ans=[]
for test in range(int(input())):
 n=int(input())
 arr=list(map(int,input().split()))
 m=0
 s=set(arr)
 for i in s:
  if arr.count(i)>m:
   m=arr.count(i)
 ans.append(n-m)
for i in ans:
 print(i)


T=int(input())
for i in range(T):
 N=int(input())
 A=list(map(int,input().split()))[:N]
 B=set(A)
 L=[]
 for j in range(len(B)):
  L.append(A.count(A[j]))
 print(len(A)-max(L))


T=int(input())
for i in range(T):
 N=int(input())
 A=list(map(int,input().split()))[:N]
 B=set(A)
 L=[]
 for j in range(len(B)):
  L.append(A.count(A[j]))
 print(len(A)-max(L))
  


def changeIt(n,arr):
 m = dict()
 for i in range(n):
  m[arr[i]] = m.get(arr[i],0)+1
 count = 0
 for i in m.keys():
  if m[i] > count:
   count = m[i]
  else:
   continue
 print(len(arr) - count)
 return

#Driver code starts here
t = int(input())
for _ in range(t):
 n = int(input())
 arr = list(map(int,input().split()))
 changeIt(n,arr)

# cook your dish here
tests = int(input())
for test in range(tests):
 n = int(input())
 a = [int(x) for x in input().split()]
 maxx = max(set(a), key = a.count)
 moves = a.index(maxx)
 if len(a) > 1:
  for i in range(moves+1, len(a)):
   if a[i] != maxx:
    moves += 1
 print(moves)


# cook your dish here
from collections import Counter
T = int(input())
for _ in range(T):
 n = int(input())
 a = list(map(int,input().split()))
 c = dict(Counter(a))
 m = max(list(c.values()))
 print(n-m)

# cook your dish here
from collections import Counter
T = int(input())
for i in range(T):
 n = int(input())
 lst = list(map(int, input().split()))
 count = Counter(lst)
 print(n - max(count.values()))

def change_it(_list):
 if(len(set(_list)) <= 2):
  return len(set(_list))-1
 k = []
 for i in range(len(_list)):
  r = _list.count(_list[i])
  k.append(r)
 s = max(k)
 return len(_list)-s


def __starting_point():
 t = int(input())
 for i in range(t):
  n = int(input())
  _list = list(map(int, input().split()))
  print(f'{change_it(_list)}')


__starting_point()

# cook your dish here
for i in range(int(input())):
 n=int(input())
 l=list(map(int,input().split()))
 k=[]
 for i in range(len(l)):
  r=l.count(l[i])
  k.append(r)
 s=max(k)
 print(len(l)-s)

# cook your dish here
from collections import Counter
val=int(input())
for i in range(val):
 n=input()
 n=int(n)
 p=list(map(int,input().split()))
 c=Counter(p)
 print(n-max(c.values()))

t=int(input())
for _ in range(t):
 n = int(input())
 l = list(map(int,input().split()))
 s = list(set(l))
 sum = 0 
 for i in s:
  x = l.count(i)
  if x>sum:
   sum=x 
 print(len(l)-sum)