#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#define MAXN 104
#define MOD 1000000009
#define INF 0x7ffffff
#define lowbit(x) (x)&(-x)
using namespace std;
map<char,int> mp;
int edge[MAXN][MAXN];
int dir[4][2] = {
-1,0, //U
0,1, //R
1,0, //D
0,-1 //L
};
inline void init(){
mp['U'] = 0;
mp['R'] = 1;
mp['D'] = 2;
mp['L'] = 3;
}
int main(){
int n,m;
while(cin >> n >> m){
init();
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
cin >> edge[i][j];
}
}
int x,y;
char s;
int k;
int d;
cin >> x >> y >> s >> k;
d = mp[s];
int i,tx,ty;
while(k--){
if(edge[x][y] == 1){
i = (d+1+4)%4;
}
else{
i = (d-1+4)%4;
}
tx = x + dir[i][0];
ty = y + dir[i][1];
d = i;
edge[x][y] ^= 1;
x = tx;
y = ty;
}
cout << x << ' ' << y << endl;
}
return 0;
}