import operator

t = int(raw_input())

for i in xrange(t):
    n = int(raw_input())
    l = map(int, raw_input().split())

    d = dict()
    for j in xrange(n):
        d[j] = l[j]
    
    ld = sorted(d.items(), key = operator.itemgetter(1))

    mn = 300000
    for j in xrange(len(ld)-1):
        if(ld[j][1] == ld[j+1][1]):
            tmp = abs(ld[j][0] - ld[j+1][0])
            if(tmp < mn):
                mn = tmp

    if(mn == 300000):
        print("-1")
    else:
        print(mn+1)