#include <bits/stdc++.h>
using namespace std;
const long long int N = 1000001;
vector<long long int> adj[N];
long long int vis[N];
long long int dis[N];
void DFS(long long int node) {
  vis[node] = 1;
  for (long long int child : adj[node]) {
    if (vis[child] == 0) {
      DFS(child);
    }
  }
}
void BFS(long long int src) {
  dis[src] = 0;
  vis[src] = 1;
  queue<long long int> q;
  q.push(src);
  while (!q.empty()) {
    long long int curr = q.front();
    q.pop();
    for (long long int child : adj[src]) {
      if (vis[child] == 0) {
        q.push(child);
        dis[child] = dis[src] + 1;
        vis[child] = 1;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> a(n);
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<long long int> b(n);
    for (long long int i = 0; i < n; i++) {
      b[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (a[j] < a[i]) b[i]++;
      }
    }
    long long int dp[n];
    for (long long int i = 0; i < n; i++) {
      dp[i] = 1;
    }
    long long int maxo = INT_MIN;
    for (long long int i = 1; i < n; i++) {
      for (long long int j = 0; j < i; j++) {
        if (b[j] == b[i] - 1) dp[i] = max(dp[i], dp[j] + 1);
      }
      maxo = max(maxo, dp[i]);
    }
    int ans = n - maxo;
    if (n == 1) ans = 0;
    cout << ans << "\n";
  }
  return 0;
}
