import java.util.Scanner;
public class TestOne {
/*测试数据
5 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
2 3 L 5
3 3
0 0 0
1 1 1
1 1 1
1 1 U 6
* */
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();//行
int n = sc.nextInt();//列
int[][] g = new int[m][n];
for(int i=0;i<m;i++) { //格子
for(int j=0;j<n;j++) {
g[i][j] = sc.nextInt();
}
}
int r = sc.nextInt();//初始坐标(r,c)
int c = sc.nextInt();
String to = sc.next();//初始头的朝向
int step = sc.nextInt();//蚂蚁需走的步数
int toNum = getToNum(to);
int nowStep=0;
while(true) {
//1.确定头旋转的方向
if(g[r][c]==1) {//当前处于黑格子,头右转90度
toNum = toNum%4 +1;
g[r][c]=0;
}else{//当前处于白格子,头左转90度
toNum--;
if(toNum==0) toNum=4;
g[r][c] = 1;
}
//2.向前移动一格
if(toNum==1) {
r--;
}
if(toNum==2) {
c++;
}
if(toNum==3) {
r++;
}
if(toNum==4) {
c--;
}
//3.已走步数+1
nowStep++;
if(step==nowStep) {
System.out.println("行号:"+r);
System.out.println("列号:"+c);
break;
}
}
}
private static int getToNum(String to) {
if(to.equals("U")) return 1;
if(to.equals("R")) return 2;
if(to.equals("D")) return 3;
if(to.equals("L")) return 4;
return 0;
}
}