I = lambda: map(int, raw_input().split())

def s_1257c():
    def help(arr):
        d = {}
        res = -1
        for idx, val in enumerate(arr):
            v = d.get(val, [])
            v.append(idx)
            d[val] = v

        minv = len(arr)
        for val in d.values():
            if len(val) > 1:
                minv = min(minv, min(i[1] - i[0]+1 for i in zip(val, val[1:])))
        return minv

    t = input()
    for _ in range(t):
        n = input()
        arr = I()
        if n == 1:
            print -1
        else:
            print help(arr)

s_1257c()