#include <bits/stdc++.h>
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,sse4.2")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    vector<long long> arr(n);
    set<long long> tyanki;
    long long curr = 1;
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
      tyanki.insert(arr[i]);
    }
    map<long long, long long> lol;
    for (long long x : tyanki) {
      lol[x] = curr++;
    }
    for (long long i = 0; i < n; i++) {
      arr[i] = lol[arr[i]];
    }
    vector<long long> kek(n);
    for (long long i = 0; i < n; i++) {
      kek[i] = 1;
      for (long long j = 0; j < i; j++) {
        if (arr[j] + 1 == arr[i]) {
          kek[i] = max(kek[i], 1 + kek[j]);
        }
      }
    }
    long long best = n;
    for (long long i = 0; i < n; i++) {
      best = min(best, n - kek[i]);
    }
    cout << best << '\n';
  }
  fflush(stdout);
  return 0;
}
