https://www.acmicpc.net/problem/1966
import sys
case_count = int(input())
n = 0
while n < case_count:
n += 1
temp_count, target_index = [int(x) for x in sys.stdin.readline().strip().split()]
temp_list = [int(x) for x in sys.stdin.readline().strip().split()]
# print('target_index: ', target_index)
rlt = []
for i in range(0, len(temp_list)):
rlt.append(['data'+str(i), temp_list[i]])
# print(rlt)
count = 0
while True:
if rlt[0][1] == max(temp_list):
if rlt[0][0] == ('data'+str(target_index)):
count += 1
break
else:
rlt.pop(0)
temp_list.remove(max(temp_list))
count += 1
else:
rlt.append(rlt[0])
rlt.pop(0)
# print(rlt)
print(count)