import java.util.*;;
class Main{
static int a[][];
static int in(String s) {
if(s.charAt(0)==’U’) {
return 1;
}
if(s.charAt(0)==’R’) {
return 2;
}
if(s.charAt(0)==’D’) {
return 3;
}else {
return 4;
}
}
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
a=new int [n][m];
for(int i=0;i<n;i) {
for(int j=0;j<m;j) {
a[i][j]=in.nextInt();
}
}
int x=in.nextInt();
int y=in.nextInt();
String s=in.next();
int d=in(s);
int k=in.nextInt();
while(k–!=0) {
if(a[x][y]==1) {
d=d%4+1;
a[x][y]=0;
}else {
d–;
if(d==0) {
d=4;
}
a[x][y]=1;
}
if(d==1) {
x–;
}
if(d==2) {
y+=1;
}
if(d==3) {
x++;
}
if(d==4) {
y–;
}
}
System.out.println(x+" "+y);
}
}