#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);
}
long long power(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = ((res % 1000000007) * (base % 1000000007));
    base = ((base % 1000000007) * (base % 1000000007));
    exp /= 2;
  }
  return res % 1000000007;
}
long long n, k;
string s;
int solve() {
  cin >> n;
  long long a[n];
  long long b[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  vector<long long> v[n];
  for (long long i = 0; i < n; i++) {
    long long x = i;
    for (long long j = 0; j < n; j++) {
      if (a[j] == b[x]) {
        v[i].push_back(b[x]);
        x++;
        if (x == n) break;
      }
    }
  }
  long long ma = 0;
  for (long long i = 0; i < n; i++) ma = max(ma, (long long)v[i].size());
  cout << n - ma << '\n';
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}
