์ฒซ์งธ ์ค์ ์ง๋์ ์ธ๋ก ํฌ๊ธฐ N, ๊ฐ๋ก ํฌ๊ธฐ M(1 <= N, M <= 20), ์ฃผ์ฌ์๋ฅผ ๋์ ๊ณณ์ ์ขํ x, y (0 <= x <= N -1, 0 <= y <= M -1), ๊ทธ๋ฆฌ๊ณ ๋ช ๋ น์ ๊ฐ์ K( 1 <= K <= 1000)๊ฐ ์ฃผ์ด์ง๋ค.
# ์ฃผ์ฌ์ ๊ตด๋ฆฌ๊ธฐ
from sys import stdin
input = stdin.readline
N, M, x, y, k = map(int, input().split())
maps = []
for _ in range(N):
maps.append(list(map(int, input().split())))
commands = list(map(int, input().split()))
up = 0
down = 0
right = 0
front = 0
back = 0
left = 0
SOUTH, NORTH, EAST, WEST = 4, 3, 1, 2
# SOUTH => front
# NORTH => back
# EAST => left
# WEST => right
positions = (x, y)
for c in commands:
# ์ด๋ํ ์นธ์ ์ฐ์ฌ ์๋ ์๊ฐ 0์ด๋ฉด, ์ฃผ์ฌ์์ ๋ฐ๋ฅ๋ฉด์ ์ฐ์ฌ ์๋ ์๊ฐ ์นธ์ ๋ณต์ฌ๋๋ค.
# 0์ด ์๋ ๊ฒฝ์ฐ์๋ ์นธ์ ์ฐ์ฌ ์๋ ์๊ฐ ์ฃผ์ฌ์์ ๋ฐ๋ฅ๋ฉด์ผ๋ก ๋ณต์ฌ๋๋ฉฐ, ์นธ์ ์ฐ์ฌ ์๋ ์๋ 0์ด ๋๋ค.
if c == SOUTH:
nx, ny = positions[0] + 1, positions[1]
elif c == NORTH:
nx, ny = positions[0] - 1, positions[1]
elif c == WEST:
nx, ny = positions[0], positions[1] -1
else:
nx, ny = positions[0], positions[1] + 1
# ๋ฒ์ ๋์ด๊ฐ๋ฉด ์๋ฌด๊ฒ๋ ์ํจ
if 0 <= nx < N and 0 <= ny < M:
positions = (nx, ny)
else:
continue
if c == SOUTH:
tmp = front
front = up
up = back
back = down
down = tmp
elif c == NORTH:
tmp = up
up = front
front = down
down = back
back = tmp
elif c == WEST:
tmp = left
left = up
up = right
right = down
down = tmp
else:
tmp = right
right = up
up = left
left = down
down = tmp
if maps[nx][ny] == 0:
maps[nx][ny] = down
else:
down = maps[nx][ny]
maps[nx][ny] = 0
# print()
# print(' ', back)
# print(left, up, right)
# print(' ', front)
# print(' ', down)
print(up)