#include <bits/stdc++.h>
using namespace std;
const long long INFLL = LLONG_MAX;
const int INF = INT_MAX;
const long long MAXLL = 0x3f3f3f3f3f3f3f3f;
const int MAX = 0x3f3f3f3f;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T, class U>
void sort(vector<T>& v, U func) {
  sort(v.begin(), v.end(), func);
}
template <class T>
int lb_index(vector<T>& v, T k) {
  return lower_bound(v.begin(), v.end(), k) - v.begin();
}
template <class T>
int ub_index(vector<T>& v, T k) {
  return upper_bound(v.begin(), v.end(), k) - v.begin();
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<int> a = v;
  sort(a);
  for (int i = 0; i < n; i++) v[i] = lb_index(a, v[i]);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int temp = i;
    for (int j = 0; j < n; j++) {
      if (v[j] == temp) temp++;
    }
    ans = max(ans, temp - i);
  }
  cout << n - ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  int numberofsubtestcases = 1;
  cin >> numberofsubtestcases;
  while (numberofsubtestcases--) {
    solve();
  }
}
