#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const int64_t LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, ans = INF;
    cin >> n;
    vector<int> arr(n), sor;
    for (int i = 0; i < n; i++) cin >> arr[i];
    sor = arr;
    sort(sor.begin(), sor.end());
    for (int i = 0; i < n; i++) {
      int x = lower_bound(sor.begin(), sor.end(), arr[i]) - sor.begin();
      int a = 0, b = 0;
      for (int j = i, it = x; j < n; j++) {
        if (it < n && sor[it] == arr[j]) it++, b++;
      }
      for (int j = i, it = x; ~j; j--) {
        if (~it && sor[it] == arr[j]) it--, a++;
      }
      ans = min(ans, n - a - b + 1);
    }
    cout << ans << '\n';
  }
  return 0;
}
