import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int[][]ds={{0,1},{1,0},{0,-1},{-1,0}};for(int[]n={0,0};(n[0]=s.nextInt())>0;){n[1]=s.nextInt();int[]p={1,1};int d=0,i,x;for(String y;!(y=s.next()).equals("STOP");System.out.println(p[0]+" "+p[1])){if(y.endsWith("D"))for(i=2,x=s.nextInt();i-->0;)p[i]=Math.min(n[i],Math.max(1,p[i]+ds[d][i]*x*(y.charAt(0)==70?1:-1)));if(y.charAt(0)==76)d=(d+3)%4;if(y.charAt(0)==82)d=(d+1)%4;}}}}