# 1966번. 프린터 큐
importsysinput=sys.stdin.readlineT=int(input())for_inrange(T):n,m=map(int,input().split())paper=list(map(int,input().split()))imp=[0foriinrange(n)]imp[m]=1cnt=0whileTrue:ifpaper[0]==max(paper):cnt+=1ifimp[0]==1:print(cnt)breakelse:paper.pop(0)imp.pop(0)else:# 맨 뒤에 넣어줌
paper.append(paper.pop(0))imp.append(imp.pop(0))