# HEY STALKER
from collections import Counter
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    if n == 1:
        print(-1)
    else:
        f = 0
        x = Counter(l)
        for g in x:
            if x[g] > 1:
                f = 1
                break
        if f:
            ans = []
            prev = 0
            curr = -1
            d = {}
            for t in range(n):
                curr = l[t]
                d[curr] = d.get(curr, 0) + 1
                if d[curr] > 1:
                    ans.append(t-prev)
                    prev = t
                    d.clear()
                    d[curr] = 1
            print(min(ans) + 1)
        else:
            print(-1)
