#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a[N], n;
    cin >> n;
    memset(a, 0, sizeof a);
    int res = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n < 2) {
      cout << -1 << endl;
      continue;
    }
    for (int i = 1; i <= n; i++)
      for (int j = i - 1; j > 0; j--) {
        if (i == j)
          continue;
        else {
          if (a[i] == a[j]) {
            res = min(res, i - j + 1);
          }
        }
      }
    cout << res << endl;
  }
  return 0;
}
