N,K = list(map(int,input().split()))

A = list([int(x)-1 for x in input().split()])



o = [0] * 63



def bi(x):

    i = 0

    while x != 0:

        o[i] = x%2

        x //= 2

        i += 1



bi(K)



n = 0

for i in range(63):

    if o[i]:

        n = A[n]

    A = [A[A[x]] for x in range(N)]

        

print((n+1))
N,K = list(map(int,input().split()))

A = list([int(x)-1 for x in input().split()])

B = [0]*N



o = [0] * 63



def bi(x):

    i = 0

    while x != 0:

        o[i] = x%2

        x //= 2

        i += 1



bi(K)



n = 0

for i in range(63):

    if o[i]:

        n = A[n]

    for j in range(N):

        B[j] = A[A[j]]

    for j in range(N):

        A[j] = B[j]

        

print((n+1))
N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
o = [0] * 63


def bi(x):
    i = 0
    while x != 0:
        o[i] = x % 2
        x //= 2
        i += 1


bi(K)
n = 0
for i in range(63):
    if o[i]:
        n = A[n]
    A = [A[A[x]] for x in range(N)]
print((n + 1))

N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
B = [0] * N
o = [0] * 63


def bi(x):
    i = 0
    while x != 0:
        o[i] = x % 2
        x //= 2
        i += 1


bi(K)
n = 0
for i in range(63):
    if o[i]:
        n = A[n]
    for j in range(N):
        B[j] = A[A[j]]
    for j in range(N):
        A[j] = B[j]
print((n + 1))

+B = [0] * N -    A = [A[A[x]] for x in range(N)] +    for j in range(N): +        B[j] = A[A[j]] +    for j in range(N): +        A[j] = B[j]