for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    b = {}
    
    minr = -1
    
    for i in range(n):
        if a[i] not in b:
            b[a[i]] = []
        b[a[i]].append(i)
        
    for pa in b.values():
        if len(pa) > 1:
            for i in range(1, len(pa)):
                if pa[i] - pa[i - 1] + 1 < minr or minr == -1:
                    minr = pa[i] - pa[i - 1] + 1
                if minr == 2:
                    break
        if minr == 2:
            break
            
    print(minr)