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