#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[n], b[n + 1];
    b[n] = -1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      b[i] = a[i];
    }
    sort(b, b + n);
    int ans = n - 1;
    for (int i = 0; i < n - 1; i++) {
      int tmp, count = 1;
      for (int j = 0; j < n; j++) {
        if (b[j] == a[i]) tmp = j;
      }
      for (int j = i + 1; j < n; j++) {
        if (a[j] == b[tmp + 1]) {
          count++;
          tmp++;
        }
      }
      ans = min(ans, n - count);
    }
    printf("%d\n", ans);
  }
}
