#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &str, vector<T> &a) {
  for (auto &i : a) {
    str << i << " ";
  }
  return str;
}
template <class T>
istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) {
    str >> i;
  }
  return str;
}
template <class T>
ostream &operator<<(ostream &str, pair<T, T> &a) {
  str << a.first << " " << a.second;
  return str;
}
template <class T>
istream &operator>>(istream &str, pair<T, T> &a) {
  str >> a.first >> a.second;
  return str;
}
void solve();
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(6);
  solve();
  return 0;
}
const long long MOD = 998244353, MAXN = 2e5 + 10, INF = 1e18 + 10, BASE = 37;
void query() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  cin >> a;
  vector<long long> b = a;
  sort((b).begin(), (b).end());
  map<long long, long long> mp;
  long long T = 1;
  for (auto it : b) {
    mp[it] = T++;
  }
  for (long long i = 0; i < n; ++i) {
    a[i] = mp[a[i]];
  }
  vector<long long> dp(n);
  dp[0] = 1;
  for (long long i = 1; i < n; ++i) {
    dp[i] = 1;
    for (long long j = i - 1; j >= 0; --j) {
      if (a[j] == a[i] - 1) {
        dp[i] = dp[j] + 1;
        break;
      }
    }
  }
  cout << n - *max_element((dp).begin(), (dp).end()) << '\n';
}
void solve() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; ++i) {
    query();
  }
}
