#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T& x) {     x = 0;     int fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     x *= fl;   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   const int N = 3005;   int T, n, a[N], b[N];   int main() {     for (read(T); T; T--) {       read(n);       for (int i = 1; i <= n; i++) read(a[i]), b[i] = a[i];       sort(b + 1, b + n + 1);       int len = unique(b + 1, b + n + 1) - (b + 1);       for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;       int now = 1, mx = 0;       while (now <= n) {         int len = 0;         for (int i = 1; i <= n; i++)           if (a[i] == now) len++, now++;         mx = max(mx, len);       }       printf( %d n , n - mx);     }     return 0;   }   