#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int c = 1000000, l = 0;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] == a[j]) {
          l = j - i;
          break;
        }
      }
      if (c > l && l > 0) c = l;
      l = 0;
    }
    if (c && n > 1)
      cout << c + 1 << endl;
    else
      cout << -1 << endl;
  }
}
