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