#include <iostream>
#include <queue>

#define endl '\n'

using namespace std;

int T, N, M;

int main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);

    cin >> T;

    for (int i = 0; i < T; ++i)
    {
        queue<int> q;
        int arr[10] = {
            0,
        };

        cin >> N >> M;

        int tar;

        for (int i = 0; i < N; ++i)
        {
            int tmp;
            cin >> tmp;

            if (i == M)
                tar = tmp;

            arr[tmp]++;
            q.push(tmp);
        }

        int mx = 9;
        int cnt = 0;
        int index = M;

        while (1)
        {
            for (int i = mx; i >= 1; --i)
            {
                if (arr[i])
                {
                    mx = i;
                    break;
                }
            }

            if (index)
            {
                if (q.front() != mx)
                {
                    q.push(q.front());
                    q.pop();
                }
                else
                {
                    q.pop();
                    arr[mx]--;
                    cnt++;
                }

                index--;
            }
            else
            {
                if (tar == mx)
                {
                    cnt++;
                    break;
                }
                else
                {
                    q.push(q.front());
                    q.pop();
                    index = q.size() - 1;
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}


실버 3 문제가 왜캐 어렵지 하면서 머리 꽁꽁 싸매면서


제일 큰 값 정하고 제일 큰 값 아니면 뒤로 push하고
값 중복이면 내가 찾고자 하는 문서가 뭔지 모르니깐

index 추적해서 푸니깐 졸라 조잡하게 풀어서


풀이 보니깐 죄다 우선순위 큐인가 뭔 듣도보도 못한 거로 푸네

근데 사실 우선순위 큐 모르고도 푼 내가 자랑스러워서 올림
나 코딩에 재능있다고 해줘 씨발