#code
n = int(input())

for i in range(n):
    inp = list(input().split())
    for i in range(len(inp)):
        inp[i] = int(inp[i])
    val = list(input().split())
    for i in range(len(val)):
        val[i] = int(val[i])
    op = val[inp[1]:] + val[:inp[1]]
    print(op)
9f5881e9a1fcf48b8c8592708539545007e62659
<mask token>

<mask token>
for i in range(n):
    inp = list(input().split())
    for i in range(len(inp)):
        inp[i] = int(inp[i])
    val = list(input().split())
    for i in range(len(val)):
        val[i] = int(val[i])
    op = val[inp[1]:] + val[:inp[1]]
    print(op)

n = int(input())
for i in range(n):
    inp = list(input().split())
    for i in range(len(inp)):
        inp[i] = int(inp[i])
    val = list(input().split())
    for i in range(len(val)):
        val[i] = int(val[i])
    op = val[inp[1]:] + val[:inp[1]]
    print(op)

#code
n = int(input())

for i in range(n):
    inp = list(input().split())
    for i in range(len(inp)):
        inp[i] = int(inp[i])
    val = list(input().split())
    for i in range(len(val)):
        val[i] = int(val[i])
    op = val[inp[1]:] + val[:inp[1]]
    print(op)