import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
m = int(next(it))
n = int(next(it))
k = int(next(it))
grid = [next(it) for _ in range(m)]
rs = int(next(it))
cs = int(next(it))
s = next(it)
re = int(next(it))
ce = int(next(it))
# map junction letters to their coordinates (1‑based)
junction_pos = {}
for i in range(m):
row = grid[i]
for j in range(n):
ch = row[j]
if 'a' <= ch <= 'z':
junction_pos[ch] = (i + 1, j + 1)
cur_r, cur_c = rs, cs
cur_time = 0
if k == 0:
print(cur_r, cur_c)
return
# list of targets: junctions in the given order, then the destination
targets = [junction_pos[ch] for ch in s]
targets.append((re, ce))
for tr, tc in targets:
# direction from current position to target
dr = 0
dc = 0
if tr > cur_r:
dr = 1
elif tr < cur_r:
dr = -1
if tc > cur_c:
dc = 1
elif tc < cur_c:
dc = -1
# move one step at a time along the straight line
while (cur_r, cur_c) != (tr, tc):
nr = cur_r + dr
nc = cur_c + dc
# cost to leave the current block
u = grid[cur_r - 1][cur_c - 1]
if 'a' <= u <= 'z': # junction
cost = 1
else: # street block (digit)
cost = int(u)
nxt_time = cur_time + cost
if k < nxt_time:
print(cur_r, cur_c)
return
elif k == nxt_time:
print(nr, nc)
return
else:
cur_time = nxt_time
cur_r, cur_c = nr, nc
# after reaching the target, cur_time is the arrival time.
# if k equaled that time we would have returned inside the loop.
# thus here k > cur_time, and we continue to the next target.
# all legs completed: the Peykan stays at the destination
print(cur_r, cur_c)
if __name__ == "__main__":
solve()