#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b, b + n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      int cntx = 0;
      int j = i;
      for (int k = 0; k < n; k++) {
        if (a[k] == b[j] && j < n) {
          cntx++;
          j++;
        }
      }
      cnt = max(cnt, cntx);
    }
    cout << n - cnt << "\n";
  }
  return 0;
}
