#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int t, n;
int a[1000010], b[1000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    int maxx = 0;
    for (int i = 1; i <= n; ++i) {
      int pos = i;
      for (int j = 1; j <= n && pos <= n; ++j) {
        if (b[pos] == a[j]) {
          pos++;
        }
      }
      maxx = max(maxx, pos - i);
    }
    cout << n - maxx << "\n";
  }
  return 0;
}
