#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
#define y front().first
#define x front().second
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int tc; cin >> tc;
for (int i = 0; i < tc; i++)
{
// 문서의 개수와 몇번째로 인쇄되었는지 확인
int t, f, cnt = 0;
cin >> t >> f;
queue<pair<int, int>> q;
priority_queue<int> pq;
for (int j = 0; j < t; j++)
{
int val; cin >> val;
q.push({ j,val });
pq.push(val);
}
while (!q.empty())
{
int curIdx = q.y, curVal = q.x;
q.pop();
if (pq.top() == curVal)
{
pq.pop();
cnt++;
if (curIdx == f)
{
cout << cnt << '\n';
break;
}
}
else
q.push({curIdx, curVal});
}
}
return 0;
}