include [HTML_REMOVED]
using namespace std;
const int N = 3010;
int n;
int a[N], f[N];
int main()
{
int t;
cin>>t;
while(t -- )
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++ )
scanf("%d", &a[i]);
for (int i = 1; i <= n; i ++ )
{
f[i] = 1;
for (int j = 1; j < i; j ++ )///前i个数字
if (a[j] < a[i])
f[i] = max(f[i], f[j] + 1);///也就是
}
int res = 0;
for (int i = 1; i <= n; i ++ )
res = max(res, f[i]);
memset(f,0,sizeof f);
cout<<n-res<<endl;
}
return 0;
}