#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pr(vector<T> &v) {
  for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " ";
  cout << endl;
}
template <typename T>
void pr(vector<vector<T>> &v) {
  for (int i = 0; i < (int)(v).size(); i++) {
    pr(v[i]);
  }
}
template <typename T>
void re(T &first) {
  cin >> first;
}
template <typename T>
void re(vector<T> &a) {
  for (int i = 0; i < (int)(a).size(); i++) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &...rest) {
  re(first);
  re(rest...);
}
template <typename T>
void pr(T first) {
  cout << first << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &...rest) {
  cout << first << " ";
  pr(rest...);
  cout << endl;
}
void ps() { cout << endl; }
template <class T, class... Ts>
void ps(const T &t, const Ts &...ts) {
  cout << t;
  if (sizeof...(ts)) cout << " ";
  ps(ts...);
}
int n;
vector<int> cur;
int cnt(vector<int> &v, int mn) {
  int a = 0;
  for (int i = 0; i < (int)(v).size(); i++) {
    if (mn < n && v[i] == cur[mn]) {
      mn++;
      a++;
    }
  }
  return (int)(v).size() - a;
}
int rec(vector<int> v, int mn) {
  if ((int)(v).size() == 0) return 0;
  int ind = 0;
  for (int i = 0; i < (int)(v).size(); i++) {
    if (v[i] == cur[mn]) ind = i;
  }
  int xx = cnt(v, mn);
  v.erase(v.begin() + ind);
  int yy = 1 + rec(v, mn + 1);
  int ack = min(xx, yy);
  return ack;
}
void solve() {
  re(n);
  vector<int> a(n);
  re(a);
  cur.clear();
  cur = a;
  sort(cur.begin(), cur.end());
  pr(rec(a, 0));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  re(t);
  for (int tt = 0; tt < t; tt++) {
    solve();
  }
}
