importsysfromcollectionsimportdeque# import timeN=int(sys.stdin.readline().rstrip())# start = time.time() # 시작 시간 저장q=deque()for_inrange(N):command=sys.stdin.readline().split()ifcommand[0]=="push":q.append(command[1])elifcommand[0]=="pop":ifq:print(q.popleft())else:print(-1)elifcommand[0]=="size":print(len(q))elifcommand[0]=="empty":ifnotq:print(1)else:print(0)elifcommand[0]=="front":ifq:print(q[0])else:print(-1)elifcommand[0]=="back":ifq:print(q[len(q)-1])else:print(-1)# print("time :", time.time() - start) # 현재시각 - 시작시간 = 실행 시간# q[len(q)-1] VS q[-1] 속도 비교# q[len(q)-1] 이 더 빠름.
importsysfromcollectionsimportdequeforTinrange(int(input())):N,M=map(int,sys.stdin.readline().split())q=deque(map(int,sys.stdin.readline().split()))idx=deque([0foriinrange(N)])idx[M]=1count=0whileTrue:ifq[0]==max(q):count+=1ifidx[0]==1:print(count)breakelse:q.popleft()idx.popleft()else:q.append(q.popleft())idx.append(idx.popleft())# 큐를 사용하는 알고리즘을 고민하는데# 아주 좋은 문제!!