deque의 특징 중 하나인 popleft()를 활용한다.
from collections import deque
for tc in range(1, int(input())+1):
N,M= map(int,input().split())
arr= deque(map(int, input().split()))
for i in range(M):
num=arr.popleft()
arr.append(num)
print(f'#{tc} {arr[0]}')