#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, f, n, m, i, j, k, l, r, o, p, g, t, y, mx, a2, h, q, w,
    k1, k2, x;
long long A[400005];
long long B[400005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (y = 0; y < t; y++) {
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> A[i];
      B[i] = A[i];
    }
    sort(B, B + n);
    mx = 0;
    B[n] = -1;
    for (i = 0; i < n; i++) {
      a = i;
      for (j = 0; j < n; j++) {
        if (A[j] == B[a]) a++;
      }
      mx = max(mx, a - i);
    }
    n -= mx;
    cout << n << "\n";
  }
}
