문제


- 일단 for i in range(N)으로 문서를 만든다.
- 중요도에서 max를 찾는다
- while importance: 일때 popleft()가 max가 아니라면 다시 append해준다. 문서도 같이
- max라면 빼준뒤 cnt += 1 또한 문서도 빼준다
- 만약 문서의 popleft()가 M과 같고 max라면 cnt += 1 후 break
import sys
from collections import deque
T = int(input())
for i in range(T):
N, M = list(map(int,sys.stdin.readline().split()))
importances = deque(list(map(int, sys.stdin.readline().split())))
max_import = max(importances)
cnt = 0
order_lst = deque([i for i in range(N)])
while order_lst:
pop_order = order_lst.popleft()
pop_import = importances.popleft()
if pop_import == max_import:
cnt += 1
if pop_order == M:
print(cnt)
break
else:
max_import = max(importances)
else:
order_lst.append(pop_order)
importances.append(pop_import)