#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int ans = 355555;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      if (m[a] != 0) {
        ans = min(ans, abs(i - m[a] + 1));
      }
      m[a] = i;
    }
    cout << (ans == 355555 ? -1 : ans) << endl;
    m.clear();
  }
  return 0;
}
