#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, j, k, l;
    cin >> n;
    long long a[n];
    map<long long, pair<long long, long long> > mp;
    vector<long long> uni;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (mp[a[i]].first == 0) {
        mp[a[i]].first = mp[a[i]].second = i + 1;
      } else {
        mp[a[i]].second = i + 1;
      }
      uni.push_back(a[i]);
    }
    sort((uni).begin(), (uni).end());
    uni.resize(unique((uni).begin(), (uni).end()) - uni.begin());
    long long mx = 0;
    for (i = 0; i < uni.size();) {
      long long tmp = 1;
      for (j = i + 1; j < uni.size(); j++) {
        if (mp[uni[j]].first > mp[uni[j - 1]].second)
          tmp++;
        else
          break;
      }
      i = j;
      mx = max(mx, tmp);
    }
    cout << (long long)uni.size() - mx << endl;
  }
}
