프린터 큐
def solution(N,M,importance):
cnt = 0
idx_list = [i for i in range(N)]
while(1):
if importance[0] == max(importance) and idx_list[0] == M:
cnt += 1
break
elif importance[0] == max(importance):
cnt += 1
idx_list.pop(0)
importance.pop(0)
else:
idx_list.append(idx_list.pop(0))
importance.append(importance.pop(0))
return cnt
test_case = int(input())
answer = []
for i in range(test_case):
N, M = map(int, input().split())
importance = list(map(int, input().split()))
answer.append(solution(N,M,importance))
for i in answer:
print(i)