
def main():
    n = int(input())
    pos = [-1] * (n + 1)
    val = list(map(int, input().split()))
    ans = -1
    for idx, v in enumerate(val):
        if pos[v] is not -1:
            ans = idx - pos[v] + 1 if ans is -1 else min(ans, idx - pos[v] + 1)
        pos[v] = idx
    print(ans)

if __name__ == "__main__":
    t = int(input())
    for _ in range(t):
        main()
