#include #include #include #include #include #include #include #include #include #include #define LL long long #define INF 0x3f3f3f3f #define RR freopen("in.txt","r",stdin) #define WW freopen("out.txt","w",stdout) using namespace std; int t,n,s,a[20],b[20]; int find(int x) { for(int i=1;i<=n;i++) if(a[i]==x) return i; } void turn(int x) { int j=find(x); for(int i=j;i>=2;i--) a[i]=a[i-1]; a[1]=x; } int main() { scanf("%d",&t); while(t--) { s=0; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",a+i); b[n]=find(n); for(int i=n-1;i>=1;i--) { b[i]=find(i); if(b[i]>b[i+1]) { s++;b[i]=1; turn(i); } } printf("%d\n",s); } }