#include<iostream>#include<fstream>#include<algorithm>#include<queue>#defineTEST0usingnamespace std;intmain(){
ofstream ofs;if(TEST){
ofs.open("/home/lixiaoqi/Documents/Code/C++/1.txt");if(!ofs.is_open())throwruntime_error("FILE NOT OPEN!");}
ostream &os = TEST ? ofs : cout;int n, m, k, pos;
cin >> m;while(m--){int time =0;int cnt[10]={0};
queue<int> tasks;
cin >> n >> pos;for(int i =0; i != n;++i){
cin >> k;
cnt[k]++;
tasks.push(k +(pos == i ?10:0));}while(1){bool to_back =false;for(int i = tasks.front()%10+1; i <=9;++i)if(cnt[i]){
to_back =true;break;}if(!to_back){
time++;if(tasks.front()>10)break;
cnt[tasks.front()%10]--;}else
tasks.push(tasks.front());
tasks.pop();}
os << time <<'\n';}return0;}