from collections import Counter
import math

def printArr(arr):
    for i in arr:
        print(i,end=" ")
        
def proA(arr):
    dic={}
    mini=math.inf
    for i in range(len(arr)):
        if(dic.get(arr[i])==None):
            dic[arr[i]]=[i]
        else:
            dic[arr[i]].append(i)
    for i,j in dic.items():
        if(len(j)==1):
            continue
        for k in range(len(j)-1):
            mini=min(mini,j[k+1]-j[k]+1)
    return mini
t=int(input())

for i in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    print(proA(arr))