#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

for _ in range(int(raw_input ())):
    n = int(raw_input ())
    l = [int(i) for i in raw_input().split()]
    d = defaultdict(list)
    for i in range(n):
        d[l[i]].append(i + 1)
    ret = 10 ** 10
    for i in d:
        if len(d[i]) < 2: continue
        l = d[i]
        for j in range(1, len(l)):
            ret = min(ret, l[j] - l[j - 1] + 1)
    if ret == 10 ** 10: ret = -1
    print ret
