#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
long long int dxk[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long int dyk[] = {1, -1, 0, 0, 1, -1, 1, -1};
const long long int inf = 1e+18;
const long long int mod = 1e+9 + 7;
long long int cMoves(vector<long long int> a) {
  long long int n = a.size();
  vector<long long int> b;
  b = a;
  sort(b.begin(), b.end());
  for (long long int i = 0; i < n; i++) {
    long long int num = a[i],
                  itr = lower_bound(b.begin(), b.end(), num) - b.begin();
    a[i] = itr;
  }
  long long int cnt = 0, cur = 0, tc = 0;
  for (long long int i = 0; i < n; i++) {
    tc = 0;
    cur = i;
    for (long long int j = 0; j < n; j++) {
      if (a[j] == cur) {
        cur++;
        tc++;
      }
    }
    cnt = max(cnt, tc);
  }
  return n - cnt;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int ans = cMoves(a);
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
