#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, j, p, tempindex, valuee, count, count1, currentValue;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> a;
    vector<int> b;
    for (i = 0; i < n; i++) {
      cin >> p;
      a.push_back(p);
      b.push_back(p);
    }
    sort(b.begin(), b.end());
    for (i = 0; i < n; i++) {
      valuee = a[i];
      tempindex = lower_bound(b.begin(), b.end(), valuee) - b.begin();
      a[i] = tempindex;
    }
    count = 0;
    currentValue = 0;
    count1 = 0;
    for (i = 0; i <= n - 1; i++) {
      count1 = 0;
      currentValue = i;
      for (j = 0; j < n; j++) {
        if (a[j] == currentValue) {
          currentValue++;
          count1++;
        }
      }
      count = max(count, count1);
    }
    cout << n - count << endl;
  }
}
