#include <iostream>
#include <queue>
using namespace std;
int main() {
int T, N, M;
cin >> T;
for (int t = 0; t < T; t++) {
cin >> N >> M;
queue<pair<int, int>> q;
for (int j = 0; j < N; j++) {
int x;
cin >> x;
q.push({x, j});
}
int count = 0;
while (!q.empty()) {
int now = q.front().first;
int index = q.front().second;
q.pop();
bool check = false;
int s = q.size();
for (int i = 0; i < s; i++) {
if (now < q.front().first) {
check = true;
}
q.push(q.front());
q.pop();
}
if (check == true) {
q.push({now, index});
} else {
count++;
if (index == M) {
cout << count << endl;
break;
}
}
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: