/* ACM ICPC Japan Domestic 99 Problem A: Where's Your Robot? by Naoyuki Tamura (tamura@kobe-u.ac.jp) */ import java.io.*; import java.util.*; public class A { static boolean dbg = false; static DataInputStream in = new DataInputStream(System.in); static int M; static int N; static String cmd; static int arg; static int x; static int y; static int dx; static int dy; static void debug(String msg) { if (dbg) System.err.print(msg); } static boolean read() throws Exception { String line = null; debug("# Enter\n"); line = in.readLine(); StringTokenizer st = new StringTokenizer(line); M = Integer.parseInt(st.nextToken()); N = Integer.parseInt(st.nextToken()); if (M == 0) return false; return true; } static boolean readCommand() throws Exception { String line = null; line = in.readLine(); StringTokenizer st = new StringTokenizer(line); cmd = st.nextToken(); if (cmd.equals("STOP")) return false; if (cmd.equals("FORWARD") || cmd.equals("BACKWARD")) arg = Integer.parseInt(st.nextToken()); return true; } static void solve() throws Exception { int dx1, dy1; x = 1; y = 1; dx = 0; dy = 1; while (readCommand()) { if (cmd.equals("FORWARD")) { x += arg * dx; y += arg * dy; } else if (cmd.equals("BACKWARD")) { x -= arg * dx; y -= arg * dy; } else if (cmd.equals("RIGHT")) { dx1 = dy; dy1 = -dx; dx = dx1; dy = dy1; } else if (cmd.equals("LEFT")) { dx1 = -dy; dy1 = dx; dx = dx1; dy = dy1; } x = Math.min(Math.max(x, 1), M); y = Math.min(Math.max(y, 1), N); debug("# " + x + " " + y + "\n"); } } public static void main(String args[]) { if (args.length > 0) dbg = true; try { while (read()) { solve(); System.out.println(x + " " + y); } } catch (Exception e) { e.printStackTrace(); } } }