#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <deque>
using namespace std;
typedef struct
{
int id;
int priority;
}Elem;
deque<Elem> de_queue; //使用双端队列,其操作类似vector,但是可以两头操作
int main()
{
freopen("data5_7_h.in", "r", stdin);
freopen("data5_7_h.out", "w", stdout);
int total, num, cur_id;
Elem ele;
cin >> total;
for (int i = 0; i < total; i++)
{
de_queue.clear();
cin >> num >> cur_id; //信息获取
for (int j = 0; j < num; j++)
{
ele.id = j;
cin >> ele.priority;
de_queue.push_back(ele);
}
//模拟操作
int count = 0;
while (true)
{
//先找到最高优先级
int max_pri = 0;
for (deque<Elem>::iterator it = de_queue.begin(); it != de_queue.end(); it++)
max_pri > (*it).priority ? max_pri : max_pri = (*it).priority;
//如果是出队该数据
if (de_queue.front().id == cur_id&&de_queue.front().priority == max_pri)
{
count++;
break;
}
else
{
if (de_queue.front().priority == max_pri)
{
de_queue.pop_front();
count++;
}
else
{
ele = de_queue.front();
de_queue.pop_front();
de_queue.push_back(ele);
}
}
}
cout << count << endl;
}
freopen("CON", "r", stdin);
freopen("CON", "w", stdout);
return 0;
}