Let's call an array $t$ dominated by value $v$ in the next situation.

At first, array $t$ should have at least $2$ elements. Now, let's calculate number of occurrences of each number $num$ in $t$ and define it as $occ(num)$. Then $t$ is dominated (by $v$) if (and only if) $occ(v) > occ(v')$ for any other number $v'$. For example, arrays $[1, 2, 3, 4, 5, 2]$, $[11, 11]$ and $[3, 2, 3, 2, 3]$ are dominated (by $2$, $11$ and $3$ respectevitely) but arrays $[3]$, $[1, 2]$ and $[3, 3, 2, 2, 1]$ are not.

Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.

You are given array $a_1, a_2, \dots, a_n$. Calculate its shortest dominated subarray or say that there are no such subarrays.

The subarray of $a$ is a contiguous part of the array $a$, i. e. the array $a_i, a_{i + 1}, \dots, a_j$ for some $1 \le i \le j \le n$.


-----Input-----

The first line contains single integer $T$ ($1 \le T \le 1000$) — the number of test cases. Each test case consists of two lines.

The first line contains single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array $a$.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the corresponding values of the array $a$.

It's guaranteed that the total length of all arrays in one test doesn't exceed $2 \cdot 10^5$.


-----Output-----

Print $T$ integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or $-1$ if there are no such subarrays.


-----Example-----
Input
4
1
1
6
1 2 3 4 5 1
9
4 1 2 4 5 4 3 2 1
4
3 3 3 3

Output
-1
6
3
2



-----Note-----

In the first test case, there are no subarrays of length at least $2$, so the answer is $-1$.

In the second test case, the whole array is dominated (by $1$) and it's the only dominated subarray.

In the third test case, the subarray $a_4, a_5, a_6$ is the shortest dominated subarray.

In the fourth test case, all subarrays of length more than one are dominated.

Difficulty: interview

Starter code:

Solutions:
for _ in range(int(input())):
    lasts = {}
    ans = n = int(input())
    for i, a in enumerate(input().split()):
        if a in lasts:
            ans = min(ans, i - lasts[a])
        lasts[a] = i
    ans += 1
    if ans > n:
        ans = -1
    print(ans)


import sys
def I():
        return sys.stdin.readline().rstrip()

for _ in range(int(I())):
    n = int(I())
    a = list( map( int, I().split() ) )
    d = dict()
    for i, x in enumerate(a):
        if x in d:
            n = min( n, i - d[ x ] )
        d[ x ] = i
    print( n + 1 if n < len(a) else -1 )


import math

import collections

a = collections.OrderedDict()

def main():
    t = int(input())
    for i in range(t):
        n = int(input())
        t = tuple([int(x) for x in input().split()])

        result = None
        occ = dict()
        for k in range(len(t)):
            ele = t[k]
            if ele in occ:
                new_result = k - occ[ele] + 1
                if result is None or new_result < result:
                    result = new_result
            occ[ele] = k
        if result is None:
            print(-1)
        else:
            print(result)

def __starting_point():
    main()

__starting_point()

# [t0, ... tn-1] dominerad av V: minst 2 element
# occ(num) förekomster av num i t
# occ(v) > occ(v') -- när v förekommer flest gånger och inget annat förekommer lika många gånger.
# kortaste dominerade dellista (slice, sammanhängande).

# 4 <- T

# 1
# 1 (jaha, minst längd 2)

# 6
# 1 2 3 4 5 1 - hela grejen har 2 ettor

# 9
# 4 1 2 4 5 4 3 2 1 - 4 5 4 har 2 fyror

# 4
# 3 3 3 3 - 3 3 har 2 treor

# OK N^3-algoritm - enkelt - aha, det räcker med att hitta 2 likadana element och olika mellan.
# För varje x - lista var alla förekomster är. gå igenom alla och hitta närmaste.

import collections

def sol(lst):
  d = collections.defaultdict(list)
  for i, x in enumerate(lst):
    d[x].append(i)

  MIN_SOL = 10**10
  for x in d:
    for a, b in zip(d[x], d[x][1:]):
      MIN_SOL = min(MIN_SOL, b-a+1)
  if MIN_SOL == 10**10:
    print(-1)
  else: print(MIN_SOL)

t = int(input())
for _ in range(t):
  _ = int(input())
  sol([int(x) for x in input().split()])


t = int(input())
for i in range(t):
	n = int(input())
	mas = list(map(int, input().split()))
	ans = []
	mini = n
	for i in range(n):
		ans.append([mas[i], i])
	ans.sort()
	flag = False
	for i in range(n - 1):
		if ans[i][0] == ans[i + 1][0]:
			mini = min(ans[i + 1][1] - ans[i][1] + 1, mini)
			flag = True
	if not(flag):
		print(-1)
	else:
		print (mini)


import sys
input = sys.stdin.readline

t=int(input())

for testcases in range(t):
    n=int(input())
    A=list(map(int,input().split()))

    LIST=[[] for i in range(n+1)]

    for ind,a in enumerate(A):
        LIST[a].append(ind)

    ANS=n+10

    for i in range(n+1):
        if len(LIST[i])<2:
            continue
        for j in range(1,len(LIST[i])):
            ANS=min(ANS,LIST[i][j]-LIST[i][j-1])

    if ANS==n+10:
        print(-1)
    else:
        print(ANS+1)


import sys
T = int(sys.stdin.readline())
for i in range(T):
	n = int(sys.stdin.readline())
	array = sys.stdin.readline().split(" ")
	lastSeen = [-10**6 for i in range(n + 1)]
	best = 10**6
	for j in range(len(array)):
		if j - lastSeen[int(array[j])] < best:
			best = j - lastSeen[int(array[j])]
		lastSeen[int(array[j])] = j
	if best == 10**6:
		print(-1)
	else:
		print(best + 1)

#!/usr/bin/env python3
import math
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**9

t = int(input())
for i in range(t):
    n = int(input())
    a = [int(item) for item in input().split()]
    if len(a) == 1:
        print(-1)
        continue
    seen = dict()
    ret = INF
    for i, item in enumerate(a):
        if item not in seen:
            seen[item] = i
        else:
            ret = min(ret, abs(seen[item] - i) + 1)
            seen[item] = i
    if ret == INF:
        print(-1)
    else:
        print(ret)

inf = 10**18
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    cnt = {}
    ans = inf
    for i in range(n):
        if a[i] in cnt:
            ans = min(ans, i - cnt[a[i]] + 1)
        cnt[a[i]] = i
    print(ans if ans != inf else -1)


T = int(input())

for t in range(T):
	n = int(input())

	A = list(map(int, input().split()))

	if n < 2:
		print(-1)

	elif len(set(A)) == n:
		print(-1)

	else:
		M = {a: [] for a in A}

		for i in range(n):
			M[A[i]].append(i)

		ans = n

		for x in M:
			if len(M[x]) > 1:
				for i in range(1, len(M[x])):
					ans = min(ans, M[x][i] - M[x][i-1] + 1)

		print(ans)

q = int(input())
for rew in range(q):
	n = int(input())
	l = list(map(int,input().split()))
	if len(l) == 1:
		print(-1)
	else:
		poz = {}
		for i in range(n + 1):
			poz[i] = []
		for i in range(n):
			poz[l[i]].append(i)
		spr = [10000000] * (n+1)
		for i in range(n+1):
			k = len(poz[i])
			for j in range(1, k):
				spr[i] = min(spr[i], poz[i][j]-poz[i][j-1])
		if min(spr) == 10000000:
			print(-1)
		else:
			print(min(spr) + 1)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
t = int(input())
for y in range(t):
	n = int(input())
	l = list(map(int,input().split()))
	d = dict()
	m = 1e9
	for i in range(n):
		if l[i] not in d:
			d[l[i]] = [i]
		else:
			d[l[i]].append(i)
			m = min(m,i - d[l[i]][-2]+1)
	if(m == 1e9):
		print(-1)
	else:
		print(m)


3

import os
import sys


def main():
    T = read_int()
    for _ in range(T):
        N = read_int()
        A = read_ints()
        print(solve(N, A))


def solve(N, A):
    if N <= 1:
        return -1
    INF = N + 1
    best = INF
    pos = {}
    for i, a in enumerate(A):
        if a in pos:
            best = min(best, i - pos[a] + 1)
        pos[a] = i
    if best == INF:
        return -1
    return best


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def __starting_point():
    main()

__starting_point()

#    !/usr/bin/env python3
#    encoding: UTF-8
#    Last Modified: 13/Nov/19 08:24:06 PM


import sys


def main():
    from collections import Counter
    from operator import itemgetter

    for tc in range(int(input())):
        n = int(input())
        arr = get_array()
        if n < 2:
            print(-1)
            continue
        d = {}
        ans = 10 ** 9
        for i in range(n):
            if arr[i] not in d:
                d[arr[i]] = i
            else:
                ans = min(ans, i - d[arr[i]] + 1)
                d[arr[i]] = i
        if ans == 10 ** 9:
            ans = -1
        print(ans)


get_array = lambda: list(map(int, sys.stdin.readline().split()))


get_ints = lambda: list(map(int, sys.stdin.readline().split()))


input = lambda: sys.stdin.readline().strip()


def __starting_point():
    main()

__starting_point()

from collections import Counter

# inf = open('input.txt', 'r')
# reader = (map(int, line.split()) for line in inf)

# t, = next(reader)
t = int(input())

for _ in range(t):
#     n, = next(reader)
#     a = list(next(reader))
    n = int(input())
    a = [int(x) for x in input().split()]
    prev = Counter()
    mn = n + 1
    for i, el in enumerate(a):
        if el in prev:
            mn = min(mn, i - prev[el] + 1)
        prev[el] = i
    print(mn if mn < n + 1 else -1)
    
# inf.close()


def main():
    inf = 10**9
    T = int(input())
    Ans = []
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        L = [-inf] * (N+1)
        ans = inf
        for i, a in enumerate(A):
            ans = min(ans, i-L[a])
            L[a] = i
        Ans.append(ans+1 if ans < inf else -1)
    print("\n".join(map(str, Ans)))

main()


#import time
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')

#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
show_flg=True

t=I()
for _ in range(t):
    n=I()
    a=LI()
    p=[-1]*(1+n)
    ans=inf
    for i in range(n):
        if p[a[i]]!=-1:
            ans=min(ans,i-p[a[i]]+1)
        p[a[i]]=i
    if ans==inf:
        ans=-1
    print(ans)


from collections import defaultdict

t = int(input())

for _ in range(t):
    n = int(input())

    a = list(map(int, input().split()))
    pos = defaultdict(list)
    for i, v in enumerate(a):
        pos[v].append(i)

    ans = 10000000
    for p in pos.values():
        if len(p) <= 1:
            continue

        for i in range(len(p)-1):
            ans = min(p[i+1]-p[i]+1, ans)


    if ans==10000000:
        print(-1)
    else:
        print(ans)

"""
NTC here
"""
from sys import stdin

def iin(): return int(stdin.readline())
 
 
def lin(): return list(map(int, stdin.readline().split()))


# range = xrange
# input = raw_input


def main():
    t=iin()
    while t:
        t-=1
        n=iin()
        a=lin()
        d={}
        for i in range(n):
            try:
                d[a[i]].append(i)
            except:
                d[a[i]]=[i]
        ans=-1
        for i in d:
            l=len(d[i])
            for j in range(l-1):
                if ans==-1:
                    ans=d[i][j+1]-d[i][j]+1
                else:
                    ans=min(d[i][j+1]-d[i][j]+1,ans)
        print(ans)











main()
# try:
#     main()
# except Exception as e: print(e)


from sys import stdin
def rl():
    return [int(w) for w in stdin.readline().split()]

t, = rl()
for _ in range(t):
    n, = rl()
    a = rl()
    d = {}
    r = -1
    for i, x in enumerate(a):
        if x in d and (r < 0 or r > i - d[x] + 1):
            r = i - d[x] + 1
        d[x] = i
    print(r)


for _ in range(int(input())):
	last = {}

	n = int(input())

	a = list(map(int, input().split()))

	nexts = [-1] * n

	for i in range(n - 1, -1, -1):
		if a[i] in last:
			nexts[i] = last[a[i]]

		last[a[i]] = i

	b = 10 ** 6

	for i in range(n):
		if nexts[i] != -1:
			b = min(b, nexts[i] - i + 1)

	print(-1 if b == 10 ** 6 else b)

t = int(input())
def check(arr, n):
    hehe = [0]*n
    for i in range (n):
        j = arr[i] - 1
        if hehe[j] == 1:
            return False
        hehe[j] += 1
    return True
for i in range (t):
    n = int(input())
    arr = list(map(int,input().split()))
    initial = [-1]*n
    diff = [n]*n
    if check(arr, n):
        print(-1)
    else:
        for j in range (n):
            l = arr[j] - 1
            k = initial[l]
            initial[l] = j
            if k == -1:
                continue
            differ = j - k + 1
            if differ < diff[l]:
                diff[l] = differ
        print(min(diff))

from sys import stdin, stdout  

import collections
def main():
    T = int(input())
    for _ in range(T):
        n = int(input())
        a = [int(x) for x in input().split(' ')]
        prev_idx = {}
        min_dist = float('inf')
        for i, v in enumerate(a):
            if v in prev_idx:
                min_dist = min(min_dist, i - prev_idx[v] + 1)
            prev_idx[v] = i
        print(-1 if min_dist == float('inf') else min_dist)

def __starting_point():
    main()
__starting_point()

t = int(input())

for _ in range(t):
    n = int(input())
    seen = [-1] * (n+1)
    ans = n*n
    for i, v in enumerate(map(int, input().split())):
        if seen[v] != -1:
            ans = min(ans, i - seen[v] + 1)
        seen[v] = i
    print(ans if ans != n*n else -1)