#include <iostream>
#include <string>
using namespace std;
int stoneLocation[2];
int kingLocation[2];
bool overlap() {
if ((kingLocation[0] == stoneLocation[0]) && (kingLocation[1] == stoneLocation[1])) {
return true;
}
return false;
}
// king location and stone location are overlapped
bool except() {
if (kingLocation[0] > 8 || kingLocation[0] < 1 || kingLocation[1]>8 || kingLocation[1] < 1) {
return true;
}
if (stoneLocation[0] > 8 || stoneLocation[0] < 1 || stoneLocation[1]>8 || stoneLocation[1] < 1) {
return true;
}
return false;
}
// king location or stone location are escape
void moveFun(string command) {
if (command == "R") {
kingLocation[0]++;
if (overlap()) {
stoneLocation[0]++;
if (except()) {
kingLocation[0]--;
stoneLocation[0]--;
}
return;
}
if (except()) {
kingLocation[0]--;
}
}
else if (command == "L") {
kingLocation[0]--;
if (overlap()) {
stoneLocation[0]--;
if (except()) {
kingLocation[0]++;
stoneLocation[0]++;
}
return;
}
if (except()) {
kingLocation[0]++;
}
}
else if (command == "B") {
kingLocation[1]--;
if (overlap()) {
stoneLocation[1]--;
if (except()) {
kingLocation[1]++;
stoneLocation[1]++;
}
return;
}
if (except()) {
kingLocation[1]++;
}
}
else if (command == "T") {
kingLocation[1]++;
if (overlap()) {
stoneLocation[1]++;
if (except()) {
kingLocation[1]--;
stoneLocation[1]--;
}
return;
}
if (except()) {
kingLocation[1]--;
}
}
else if (command == "RT") {
kingLocation[0]++;
kingLocation[1]++;
if (overlap()) {
stoneLocation[0]++;
stoneLocation[1]++;
if (except()) {
kingLocation[0]--;
kingLocation[1]--;
stoneLocation[0]--;
stoneLocation[1]--;
}
return;
}
if (except()) {
kingLocation[0]--;
kingLocation[1]--;
}
}
else if (command == "LT") {
kingLocation[0]--;
kingLocation[1]++;
if (overlap()) {
stoneLocation[0]--;
stoneLocation[1]++;
if (except()) {
kingLocation[0]++;
kingLocation[1]--;
stoneLocation[0]++;
stoneLocation[1]--;
}
return;
}
if (except()) {
kingLocation[0]++;
kingLocation[1]--;
}
}
else if (command == "RB") {
kingLocation[0]++;
kingLocation[1]--;
if (overlap()) {
stoneLocation[0]++;
stoneLocation[1]--;
if (except()) {
kingLocation[0]--;
kingLocation[1]++;
stoneLocation[0]--;
stoneLocation[1]++;
}
return;
}
if (except()) {
kingLocation[0]--;
kingLocation[1]++;
}
}
else if (command == "LB") {
kingLocation[0]--;
kingLocation[1]--;
if (overlap()) {
stoneLocation[0]--;
stoneLocation[1]--;
if (except()) {
kingLocation[0]++;
kingLocation[1]++;
stoneLocation[0]++;
stoneLocation[1]++;
}
return;
}
if (except()) {
kingLocation[0]++;
kingLocation[1]++;
}
}
else {
return;
}
}
int main() {
string stoneStart, kingStart;
string command;
int count;
cin >> kingStart >> stoneStart >> count;
kingLocation[0] = kingStart[0] - 64;
kingLocation[1] = kingStart[1] - 48;
stoneLocation[0] = stoneStart[0] - 64;
stoneLocation[1] = stoneStart[1] - 48;
//Initialize
for (int i = 0; i < count; i++) {
cin >> command;
moveFun(command);
}
cout << char(kingLocation[0] + 64) << kingLocation[1] << endl;
cout << char(stoneLocation[0] + 64) << stoneLocation[1] << endl;
}