#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n], sor[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      sor[i] = arr[i];
    }
    sort(sor, sor + n);
    for (int i = 0; i < n; i++) {
      int ind = lower_bound(sor, sor + n, arr[i]) - sor;
      arr[i] = ind;
    }
    int dp[n];
    for (int i = 0; i < n; i++) dp[i] = 1;
    for (int i = 1; i < n; ++i) {
      for (int j = i - 1; j >= 0; j--) {
        if (arr[j] == arr[i] - 1) {
          dp[i] = max(dp[j] + 1, dp[j]);
          break;
        }
      }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) mx = max(dp[i], mx);
    cout << n - mx << endl;
  }
}
