#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
int main() {
  int t;
  cin >> t;
  while (t--) {
    set<int> s;
    int n;
    int ans = INT_MAX;
    map<int, int> mp;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      if (mp[a] != 0) {
        ans = min(ans, i - mp[a] + 1);
      }
      mp[a] = i;
    }
    if (ans == INT_MAX)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
