# 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:
            s = set(l)
            d = {}
            for i in s:
                d[i] = []
            ans = 2e18
            for t in range(n):
                d[l[t]].append(t)
            for j in d:
                d[j].sort()
                if len(d[j]) > 1:
                    for y in range(1, len(d[j])):
                        ans = min(ans, d[j][y]-d[j][y-1])
            print(ans + 1)
        else:
            print(-1)
