#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> prime;
void sieve(long long int n) {
  bool bakh[n + 1];
  memset(bakh, true, sizeof(bakh));
  for (long long int p = 2; p * p <= n; p++) {
    if (bakh[p] == true) {
      for (long long int i = p * p; i <= n; i += p) bakh[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (bakh[p]) prime.push_back(p);
}
long long int eulertotient(long long int z) {
  long long int fac = z;
  for (long long int i = 0; prime[i] * prime[i] <= z; i++) {
    if (z % prime[i] == 0) {
      fac -= (fac / prime[i]);
      while (z % prime[i] == 0) z /= prime[i];
    }
  }
  if (z > 1) fac -= (fac / z);
  return fac;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  long long int g = gcd(a, b);
  long long int ans = (a * b) / g;
  return ans;
}
long long int modInverse(long long int a, long long int m) {
  long long int hvf = gcd(a, m);
  if (hvf == 1) return power(a, m - 2, m);
  return -1;
}
void multiply(long long int F[2][2], long long int M[2][2]) {
  long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];
  long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];
  long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];
  long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];
  F[0][0] = x;
  F[0][1] = y;
  F[1][0] = z;
  F[1][1] = w;
}
void powermat(long long int F[2][2], long long int n) {
  if (n == 0 || n == 1) return;
  long long int M[2][2] = {{1, 1}, {1, 0}};
  powermat(F, n / 2);
  multiply(F, F);
  if (n % 2 != 0) multiply(F, M);
}
long long int fib(long long int n) {
  long long int F[2][2] = {{1, 1}, {1, 0}};
  if (n == 0) return 0;
  powermat(F, n - 1);
  return F[0][0];
}
vector<long long int> merge(vector<long long int> v1,
                            vector<long long int> v2) {
  vector<long long int> temp;
  long long int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j])
      temp.push_back(v1[i]), i++;
    else
      temp.push_back(v2[j]), j++;
  }
  while (i < v1.size()) temp.push_back(v1[i]), i++;
  while (j < v2.size()) temp.push_back(v2[j]), j++;
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t, n;
  cin >> t;
  map<long long int, long long int> mp, dp;
  while (t--) {
    cin >> n;
    long long int ar[n];
    for (long long int i = 0; i < n; i++) cin >> ar[i];
    mp.clear();
    dp.clear();
    long long int j = 0;
    long long int ans = INT_MAX;
    for (long long int i = 0; i < n; i++) {
      mp[ar[i]] += 1;
      dp[mp[ar[i]]] += 1;
      if (dp[2] == 0) continue;
      while (j < i) {
        mp[ar[j]] -= 1;
        dp[mp[ar[j]] + 1] -= 1;
        if (dp[2] == 0 and mp[ar[j]] == 1) {
          ans = min(ans, i - j + 1);
          j++;
          break;
        }
        j++;
      }
    }
    if (ans == INT_MAX) ans = -1;
    cout << ans << endl;
  }
}

### Prompt

Please create a solution in CPP to the following problem:

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, ..., 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}, ..., a_j for some 1 ≤ i ≤ j ≤ n.

Input

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

The first line contains single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array a.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 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 ⋅ 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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> prime;
void sieve(long long int n) {
  bool bakh[n + 1];
  memset(bakh, true, sizeof(bakh));
  for (long long int p = 2; p * p <= n; p++) {
    if (bakh[p] == true) {
      for (long long int i = p * p; i <= n; i += p) bakh[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (bakh[p]) prime.push_back(p);
}
long long int eulertotient(long long int z) {
  long long int fac = z;
  for (long long int i = 0; prime[i] * prime[i] <= z; i++) {
    if (z % prime[i] == 0) {
      fac -= (fac / prime[i]);
      while (z % prime[i] == 0) z /= prime[i];
    }
  }
  if (z > 1) fac -= (fac / z);
  return fac;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  long long int g = gcd(a, b);
  long long int ans = (a * b) / g;
  return ans;
}
long long int modInverse(long long int a, long long int m) {
  long long int hvf = gcd(a, m);
  if (hvf == 1) return power(a, m - 2, m);
  return -1;
}
void multiply(long long int F[2][2], long long int M[2][2]) {
  long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];
  long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];
  long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];
  long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];
  F[0][0] = x;
  F[0][1] = y;
  F[1][0] = z;
  F[1][1] = w;
}
void powermat(long long int F[2][2], long long int n) {
  if (n == 0 || n == 1) return;
  long long int M[2][2] = {{1, 1}, {1, 0}};
  powermat(F, n / 2);
  multiply(F, F);
  if (n % 2 != 0) multiply(F, M);
}
long long int fib(long long int n) {
  long long int F[2][2] = {{1, 1}, {1, 0}};
  if (n == 0) return 0;
  powermat(F, n - 1);
  return F[0][0];
}
vector<long long int> merge(vector<long long int> v1,
                            vector<long long int> v2) {
  vector<long long int> temp;
  long long int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j])
      temp.push_back(v1[i]), i++;
    else
      temp.push_back(v2[j]), j++;
  }
  while (i < v1.size()) temp.push_back(v1[i]), i++;
  while (j < v2.size()) temp.push_back(v2[j]), j++;
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t, n;
  cin >> t;
  map<long long int, long long int> mp, dp;
  while (t--) {
    cin >> n;
    long long int ar[n];
    for (long long int i = 0; i < n; i++) cin >> ar[i];
    mp.clear();
    dp.clear();
    long long int j = 0;
    long long int ans = INT_MAX;
    for (long long int i = 0; i < n; i++) {
      mp[ar[i]] += 1;
      dp[mp[ar[i]]] += 1;
      if (dp[2] == 0) continue;
      while (j < i) {
        mp[ar[j]] -= 1;
        dp[mp[ar[j]] + 1] -= 1;
        if (dp[2] == 0 and mp[ar[j]] == 1) {
          ans = min(ans, i - j + 1);
          j++;
          break;
        }
        j++;
      }
    }
    if (ans == INT_MAX) ans = -1;
    cout << ans << endl;
  }
}

```