#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  srand(time(NULL));
  ;
  int T = 1;
  cin >> T;
  while (T--) {
    int n, r = 0;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < int(n); i++) cin >> a[i], b[i] = a[i];
    sort(b, b + n);
    for (int i = 0; i < int(n); i++) {
      int j = 0, k = i, c = 0;
      while (j < n && k < n) {
        if (a[j] == b[k])
          j++, k++, c++;
        else
          j++;
      }
      r = max(r, c);
    }
    cout << n - r << endl;
  }
  return 0;
}
