H. Shortest Subarray
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

For an array $$$x$$$, let $$$f(x)$$$ be the array obtained by deleting all $$$x_i$$$ such that there exists some $$$j \lt i$$$, and $$$x_j$$$ is equal to $$$x_i$$$, and concatenating the rest together. In other words, it keeps the first occurrence of each value and concatenates them in the order they appear in the $$$x$$$. For example, $$$f([1, 2, 1, 3]) = [1, 2, 3]$$$.

Given an array $$$a$$$, find the length of the shortest subarray $$$b$$$ of $$$a$$$ such that $$$f(a)$$$ is equal to $$$f(b)$$$.

A subarray is an array obtained by deleting several (possibly zero) elements from the beginning and end of the original array.

Input

The first line has $$$t$$$, the number of testcases. — ($$$1 \le t \le 3 \cdot 10^5$$$)

The first line of each test case has $$$n$$$, the length of $$$a$$$. — ($$$1 \le n \le 3 \cdot 10^5$$$)

The second line of each test case has $$$n$$$ integers, which is the array $$$a$$$. — ($$$1 \le a_i \le n$$$)

The sum of $$$n$$$ over all test cases will not exceed $$$3 \cdot 10^5$$$.

Output

The output of each test case has a single integer, the length of the shortest subarray.

Example
Input
3
9
1 1 2 2 3 3 1 2 3
12
1 2 2 2 2 2 2 3 1 2 1 3
13
1 2 2 2 2 2 3 4 1 4 2 3 4
Output
3
4
8
Note

In the first test case, the optimal subarray is the last 3 elements.