This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem.

You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array elements:  choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the begin of the array;  choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the end of the array. 

For example, if $n = 5$, $a = [4, 7, 2, 3, 9]$, then the following sequence of operations can be performed:   after performing the operation of the first type to the second element, the array $a$ will become $[7, 4, 2, 3, 9]$;  after performing the operation of the second type to the second element, the array $a$ will become $[7, 2, 3, 9, 4]$. 

You can perform operations of any type any number of times in any order.

Find the minimum total number of operations of the first and second type that will make the $a$ array sorted in non-decreasing order. In other words, what is the minimum number of operations that must be performed so the array satisfies the inequalities $a[1] \le a[2] \le \ldots \le a[n]$.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases in the test. Then $t$ test cases follow.

Each test case starts with a line containing an integer $n$ ($1 \le n \le 3000$) — length of the array $a$.

Then follow $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — an array that needs to be sorted by the given operations. All numbers in the given array are distinct.

The sum of $n$ for all test cases in one test does not exceed $3000$.


-----Output-----

For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order.


-----Example-----
Input
4
5
4 7 2 3 9
5
3 5 8 1 7
5
1 4 5 7 12
4
0 2 1 3

Output
2
2
0
2



-----Note-----

In the first test case, you first need to move 3, and then 2 to the beginning of the array. Therefore, the desired sequence of operations: $[4, 7, 2, 3, 9] \rightarrow [3, 4, 7, 2, 9] \rightarrow [2, 3, 4, 7, 9]$.

In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: $[3, 5, 8, 1, 7] \rightarrow [1, 3, 5, 8, 7] \rightarrow [1, 3, 5, 7, 8]$.

In the third test case, the array is already sorted.

Difficulty: introductory

Starter code:

Solutions:
import sys
input = sys.stdin.readline
import bisect

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

    compression_dict={a: ind for ind, a in enumerate(sorted(set(A)))}
    A=[compression_dict[a] for a in A]

    Q=[0]*n
     
    for i in range(n):
        Q[A[i]]=i
     
    count=1
    Ans=0
    #print(A,Q)
    for i in range(1,n):
        if Q[i]>Q[i-1]:
            count+=1
        else:
            Ans=max(count,Ans)
            count=1

    Ans=max(count,Ans)
     
    print(n-Ans)

    


t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    id = list(zip(l,list(range(n))))
    id.sort()
    val, pos = zip(*id)
    best = 1
    i = 1
    count = 1
    while True:
        if i >= n:
            break
        if pos[i] > pos[i-1]:
            count += 1
            best = max(count,best)
        else:
            count = 1
        i += 1
    print(n-best)

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n):
        a[i] = a[i] * n + i
    a.sort()
    p = [0 for _ in range(n)]
    for i in range(n):
        p[a[i]%n] = i
    q = [0 for _ in range(n)]
    for i in range(n):
        q[p[i]] = i
    cnt = 1
    m = 0
    for i in range(1, n):
        if q[i-1] < q[i]:
            cnt += 1
        else:
            m = max(cnt, m)
            cnt = 1
    m = max(cnt, m)
    print(n - m)

def search(lis,idx,val):
    low = 0
    high = idx
    while(low<=high):
        mid = (low+high)//2
        if lis[mid] == val:
            return mid
        if lis[mid] > val:
            high = mid-1
        else:
            low = mid+1
        
def ans(arr):
    
    lis_f = list(sorted(arr))
    ans_arr = [0]*len(arr)
    for i in range(len(arr)):
        ans_arr[search(lis_f,len(arr)-1,arr[i])]=i
    #print(ans_arr)
    c = 1
    p=0
    for j in range(1,len(arr)):
        #print(ans_arr[j],ans_arr[j-1])
        if ans_arr[j]>ans_arr[j-1]:
            c+=1
        elif c>p:
            p=c
            c=1
        else:
            c = 1
        #print(c,p)

    if c>p:
        p=c


    print(len(arr)-p)
    
    

k=int(input())
for i in range(k):
    input()
    ans(list(map(int,input().split())))

def search(lis,idx,val):
    low = 0
    high = idx
    while(low<=high):
        mid = (low+high)//2
        if lis[mid] == val:
            return mid
        if lis[mid] > val:
            high = mid-1
        else:
            low = mid+1
        
def ans(arr):
    hj=9;ghkd=898291
    lis_f = sorted(arr)
    ans_arr = [0]*len(arr)
    for i in range(len(arr)):
        ans_arr[search(lis_f,len(arr)-1,arr[i])]=i
    #print(ans_arr)
    c = 1
    p=0
    for j in range(1,len(arr)):
        #print(ans_arr[j],ans_arr[j-1])
        if ans_arr[j]>ans_arr[j-1]:
            c+=1
        elif c>p:
            p=c
            ghkd=898291
            c=1
        else:
            c = 1
        #print(c,p)

    if c>p:
        p=c


    print(len(arr)-p)
    
    

k=int(input())
for i in range(k):
    input()
    l=list(map(int,input().split()))
    ans(l)

import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = sorted(a)
    c = {}
    for i in range(n-1):
        c[b[i+1]] = b[i]
    c[b[0]] = -1
    li = {}
    for i in a:
        if c[i] in li:
            li[i] = li[c[i]] + 1
        else:
            li[i] = 1
    print(n-max(li.values()))

from sys import stdin
def search(lis,idx,val):
    low = 0
    high = idx
    while(low<=high):
        mid = (low+high)//2
        if lis[mid] == val:
            return mid
        if lis[mid] > val:
            high = mid-1
        else:
            low = mid+1
        
def ans(arr):
    
    lis_f = sorted(arr)
    ans_arr = [0]*len(arr)
    for i in range(len(arr)):
        ans_arr[search(lis_f,len(arr)-1,arr[i])]=i
    #print(ans_arr)
    c = 1
    p=0
    for j in range(1,len(arr)):
        #print(ans_arr[j],ans_arr[j-1])
        if ans_arr[j]>ans_arr[j-1]:
            c+=1
        elif c>p:
            p=c
            c=1
        else:
            c = 1
        #print(c,p)

    if c>p:
        p=c


    print(len(arr)-p)
    
    
for i in range(1000):
    continue
for i in range(int(stdin.readline())):
    stdin.readline()
    ans(list(map(int,stdin.readline().split())))

import sys

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

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

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

def solve():
	n = mint()
	a = list(mints())
	b = list(enumerate(a))
	b.sort(key=lambda a:a[1])
	c1 = [0]*n
	#c2 = [0]*n
	c = 0
	h = 0
	p = -1
	for i, v in b:
		if i > p:
			c += 1
		else:
			c = 1
		h += 1
		c1[i] = h-c
		p = i
	c = 0
	h = 0
	p = -1
	ans = n+n
	for z in range(len(b)-1,-1,-1):
		i, v = b[z]
		if i < p:
			c += 1
		else:
			c = 1
		h += 1
		#c2[i] = h-c
		ans = min(ans, h - c + c1[i])
		p = i
	print(ans)

for i in range(mint()):
	solve()


from sys import stdin
def bsearch(lis,idx,val):
    l = 0
    h=idx
    while(l<=h):
        mid = (l+h)//2
        if lis[mid] == val:
            return mid
        if lis[mid] > val:
            h= mid-1
        else:
            l = mid+1
        
def res(arr):
    lis_f = sorted(arr)
    _arr = [0 for i in range(len(arr))]
    for i in range(len(arr)):
        _arr[bsearch(lis_f,len(arr)-1,arr[i])]=i
    c=1
    p=0
    for j in range(1,len(arr)):
        if _arr[j]>_arr[j-1]:
            c+=1
        elif c>p:
            p=c
            c=1
        else:
            c=1
    if c>p:
        p=c
    print(len(arr)-p)
k=int(stdin.readline())
while(k):
    stdin.readline()
    res(list(map(int,stdin.readline().split())))
    k-=1

tt = int(input())

for loop in range(tt):

    n = int(input())

    a = list(map(int,input().split()))
    ai = []
    for i in range(n):
        ai.append( ( a[i] , i ) )

    ai.sort()
    ind = 0

    b = [0] * n #newlist
    non = [0] * (n+1) #numbers of numbers

    for i in range(n):

        if i != 0 and ai[i][0] != ai[i-1][0]:
            ind += 1

        b[ai[i][1]] = ind
        non[ind] += 1

    dp = [0] * (n+1)

    for i in range(n):

        dp[b[i]] += max( dp[b[i]] , dp[b[i]-1] + 1)

    print (n - max(dp))

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    indexOf = {}
    for i in range(n):
        indexOf[a[i]] = i
    values = sorted(list(set(a)))
    visited = [False for _ in range(n)]
    ng = [n for _ in range(n)]
    for i in range(n):
        lo = 0
        hi = len(values)-1
        while lo < hi:
            mid = (lo + hi) // 2
            if values[mid] < a[i]:
                lo = mid + 1
            else:
                hi = mid
        if lo != len(values) - 1:
            ng[i] = indexOf[values[lo+1]]
    ans = n
    for i in range(n):
        if visited[i]:
            continue
        tempAns = n
        at = i
        while at != n:
            visited[at] = True
            tempAns -= 1
            if ng[at] > at:
                at = ng[at]
            else:
                at = n
        ans = min(ans, tempAns)
    print(ans)


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    p = []
    for i in range(n):
        p.append((a[i],i))
    p.sort(key = lambda x: x[0])
    aOrder = [-1] * n
    for i in range(n):
        aOrder[p[i][1]] = i
    maxSubseq = []
    for i in range(n):
        maxSubseqcur = 0
        for j in range(i):
            if aOrder[i] - aOrder[j] == 1 and maxSubseqcur < maxSubseq[j]:
                maxSubseqcur = maxSubseq[j]
        maxSubseq.append(maxSubseqcur + 1)
    print(n - max(maxSubseq))

from sys import stdin,stdout
def findops(l):
    ans=0
    count=1
    for i in range(1,len(l)):
        if l[i]>l[i-1]:
            count+=1
        else:
            ans=max(ans,count)
            count=1
    return len(l)-max(ans,count)
    

def main():
    for _ in range(int(stdin.readline())):
        stdin.readline()
        l=list(map(int,stdin.readline().split()))
        print(findops(sorted(range(len(l)),key=lambda x:l[x])))

main()

t=int(input())
for you in range(t):
    n=int(input())
    l=input().split()
    li=[int(i) for i in l]
    z=list(li)
    z.sort()
    hashi=dict()
    for i in range(n):
        hashi[z[i]]=i+1
    for i in range(n):
        li[i]=hashi[li[i]]
    hashi=dict()
    dp=[0 for i in range(n)]
    for i in range(n):
        if(li[i]-1 in hashi):
            dp[i]=hashi[li[i]-1]+1
            hashi[li[i]]=dp[i]
        else:
            dp[i]=1
            hashi[li[i]]=1
    z=max(dp)
    print(n-z)


t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(n):
        b.append([a[i],i])
    b=sorted(b, key=lambda R: R[0])
    positions=[0]*n
    for i in range(n):
        positions[b[i][1]]=i
    leftmin=[]
    rightmin=[]
    for i in range(n):
        leftmin.append(0)
        rightmin.append(0)
    for i in range(n-1):
        for j in range(i+1):
            if a[j]>a[i+1]:
                l=positions[i+1]+1
                r=n-positions[j]
                for k in range(l-1,-1,-1):
                    if leftmin[k]>=r:
                        break
                    leftmin[k]=r
                for k in range(r-1,-1,-1):
                    if rightmin[k]>=l:
                        break
                    rightmin[k]=l
    maximum=n
    for i in range(n):
        maximum=min(maximum,leftmin[i]+i)
        maximum=min(maximum,rightmin[i]+i)
    print(maximum)


I=lambda:list(map(int,input().split()))
def lis(arr): 
    n = len(arr) 
    lis = [1]*n 
    for i in range (1 , n): 
        for j in range(0 , i): 
            if arr[i]==arr[j]+1  and lis[i]< lis[j] + 1 : 
                lis[i] = lis[j]+1
    maximum = 0
    for i in range(n): 
        maximum = max(maximum ,lis[i]) 
    return maximum 
for tc in range(int(input())):
	n,=I()
	l=I()
	ar=l.copy()
	ar.sort()
	f={}
	for i in range(n):	
		f[ar[i]]=i+1
	for i in range(n):
		l[i]=f[l[i]]
	print(n-lis(l))


def maxSubsequenceSubstring(x, y, n, m): 
    dp = [[0 for i in range(n+1)] 
             for i in range(n+1)] 
    for i in range(1, m + 1): 
        for j in range(1, n + 1): 
            if(x[j - 1] == y[i - 1]): 
                dp[i][j] = 1 + dp[i - 1][j - 1] 
            else: 
                dp[i][j] = dp[i][j - 1] 
    ans = 0
    for i in range(1, m + 1): 
        ans = max(ans, dp[i][n]) 
    return ans 
    
t = int(input())
while(t):
    t-=1
    n = int(input())
    l = list(map(int,input().split()))
    q = sorted(l)
    print(n - maxSubsequenceSubstring(l,q,len(l),len(q)))