#include <iostream>
#include <algorithm>
using namespace std;
class quee {
int f;
int b;
int* arr;
public:
quee(int n) {
f = 0;
b = -1;
arr = new int[n];
}
void push(int n) {
arr[++b] = n;
}
int pop() {
if (empty()) return -1;
return arr[f++];
}
int size() {
return b - f + 1;
}
int empty() {
return (b - f) == -1;
}
int front() {
if (empty()) return -1;
return arr[f];
}
int back() {
if (empty()) return -1;
return arr[b];
}
~quee() {
delete[] arr;
}
};
bool compare(int i, int j)
{
return i > j;
}
int main(void)
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, check, t, cnt;
cin >> t;
while (t--) {
cin >> n >> check;
int temp;
int* arr = new int[n];
quee q(n * n); //값 입력
quee p(n * n); //인덱스값 입력
cnt = 0; //인쇄한 순서
for (int i = 0; i < n; i++)
{
cin >> temp;
q.push(temp);
arr[i] = temp;
p.push(i);
}
sort(arr, arr + n, compare); //내림 차순
while (q.size() != 0)
{
while (arr[cnt] != q.front()) //입력한 값들 중 가장 큰 값인지 확인 아니라면 순서 뒤로 미루기
{
q.push(q.pop());
p.push(p.pop());
}
q.pop(); //인쇄
cnt++;
if (p.pop() == check) { //인덱스 값과 해당 인덱스 값이 맞는지 확인
cout << cnt << endl;
break;
}
}
delete[] arr;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIHF1ZWUgewoJaW50IGY7CglpbnQgYjsKCWludCogYXJyOwpwdWJsaWM6CglxdWVlKGludCBuKSB7CgkJZiA9IDA7CgkJYiA9IC0xOwoJCWFyciA9IG5ldyBpbnRbbl07Cgl9Cgl2b2lkIHB1c2goaW50IG4pIHsKCQlhcnJbKytiXSA9IG47Cgl9CglpbnQgcG9wKCkgewoJCWlmIChlbXB0eSgpKSByZXR1cm4gLTE7CgkJcmV0dXJuIGFycltmKytdOwoJfQoJaW50IHNpemUoKSB7CgkJcmV0dXJuIGIgLSBmICsgMT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