#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    if (i != v.size() - 1) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << " : " << it.second << "\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  return os;
}
void go() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void solve() {
  int n, ans;
  cin >> n;
  ans = 1;
  vector<int> a(n), c;
  for (int& x : a) cin >> x;
  c = a;
  sort(c.begin(), c.end());
  for (int i = 0; i < n; i++) {
    int f = i, s = 0, res = 0;
    for (int j = 0; j < n and s < n and f < n; j++) {
      if (c[f] == a[s]) {
        res++;
        f++;
      }
      s++;
    }
    ans = max(ans, res);
  }
  cout << n - ans << '\n';
}
int main() {
  go();
  int t;
  cin >> t;
  while (t--) solve();
}
