#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
int k;
cin >> k;
for (int i = 0; i < k; i++){
queue<int>itant;
queue<int>indexo;
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
itant.push(x);
indexo.push(i);
}
int coutner = 0;
while (true){
int cur = itant.front();
int incur = indexo.front();
bool tin = false;
queue<int>q = itant;
q.pop();
for (int i = 0; i < indexo.size(); i++){
if (cur < q.front()){
tin = true;
break;
}
else{
q.pop();
}
}
if (tin){
itant.push(cur);
itant.pop();
indexo.push(incur);
indexo.pop();
}
else{
coutner++;
if (incur == m){
cout << coutner << "\n";
break;
}
else{
itant.pop();
indexo.pop();
}
}
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: