char op[9];w,h,x,y,d;move(r){x+=d-1?d-3?0:-r:r;y+=d?d-2?0:-r:r;x=x<1?1:x>w?w:x;y=y<1?1:y>h?h:y;}main(r){for(;scanf("%d%d",&w,&h)*w;printf("%d %d\n",x,y))for(x=y=1,d=0;scanf("%s",op),*op!='S';){if(*op=='F'||*op=='B')scanf("%d",&r),move(*op=='F'?r:-r);if(*op=='R')d=(d+1)%4;if(*op=='L')d=(d+3)%4;}}