import sys
input = sys.stdin.readline
king, doll, N = input().split()
N = int(N)
graph = [[0]*8 for _ in range(8)]
def find_idx(piece):
return 8-int(piece[1]), ord(piece[0])-65
def next_idx(x, y, direction):
next_direction = {
'R': (1, 0),
'L': (-1, 0),
'B': (0, 1),
'T': (0, -1),
'RT': (1, -1),
'LT': (-1, -1),
'RB': (1, 1),
'LB': (-1, 1),
}
x += next_direction[direction][1]
y += next_direction[direction][0]
return x, y
king_x, king_y = find_idx(king)
doll_x, doll_y = find_idx(doll)
graph[king_x][king_y] = 'K'
graph[doll_x][doll_y] = 'D'
for i in range(N):
direction = input().rstrip()
nx, ny = next_idx(king_x, king_y, direction)
if 0 <= nx < 8 and 0 <= ny < 8:
if graph[nx][ny] == 'D':
ndx, ndy = next_idx(nx, ny, direction)
if 0 <= ndx < 8 and 0 <= ndy < 8:
try:
graph[ndx][ndy] = 'D'
graph[nx][ny] = 'K'
graph[king_x][king_y] = 0
king_x, king_y = nx, ny
except:
continue
else:
graph[nx][ny] = 'K'
graph[king_x][king_y] = 0
king_x, king_y = nx, ny
for i in range(8):
for j in range(8):
if graph[i][j] == 'K':
king = (f'{chr(65+j)}{8-i}')
elif graph[i][j] == 'D':
doll = (f'{chr(65+j)}{8-i}')
print(king)
print(doll)