模拟
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define N 10004
typedef struct node{
int pos,pri;
};
node q[N];
int pri[10];
int main()
{
int n,t,m,maxx,f,r,po,ans;
cin>>t;
node tmp;
while(t--){
cin>>n>>m;
memset(pri,0,sizeof(pri));
maxx=-1;
ans=0;
f=0;
r=n;
for(int i=0;i<n;i++){
scanf("%d",&q[i].pri);
q[i].pos=i;
pri[q[i].pri]++;
maxx=max(maxx,q[i].pri);
}
po=maxx;
while(1){
tmp=q[f++];
if(tmp.pri<po){
q[r++]=tmp;
continue;
}
else{
if(tmp.pos==m){
ans++;
break;
}
else{
ans++;
pri[po]--;
while(!pri[po]&&po>0){
po--;
}
}
}
}
printf("%d\n",ans);
}
return 0;
}