이 문제는 기본적인 큐 자료구조를 사용하기 위해 deque를 이용하였다.
import sys
from collections import deque
input = sys.stdin.readline
T = int(input())
for _ in range(T) :
N, M = map(int,input().split())
arr = list(map(int,input().split()))
brr = deque()
for i in range(N) :
brr.append((i,arr[i]))
count = 0
while len(brr) > 0 :
tmp = 1
for i in range(1, len(brr)) :
if brr[0][1] < brr[i][1] :
tmp = 0
if tmp == 0 :
a = brr.popleft()
brr.append(a)
else :
count += 1
temp = brr.popleft()
if temp[0] == M :
print(count)
break