import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

for _ in range(r()):
    n = r()
    a = rl()
    mini = math.inf
    occ = defaultdict(int)
    for i in range(n):
        if occ[a[i]]==-1:
            mini = min(mini, i-occ[a[i]]+1)
        occ[a[i]]=i
    print(mini)
