import java.util.*;
import java.io.*;

public class layout_ia implements Runnable {
	
	public void run() {
		try {
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}		
	}
	
	private Element endOfParagraph;
	private Element endOfFile;
	private int w;
	private int h;
	private int c;
	
	private void solve() throws Exception {
		Locale.setDefault(Locale.US); 
		
		BufferedReader in = new BufferedReader(new FileReader("layout.in"));
		PrintWriter out = new PrintWriter("layout.out");
		StringTokenizer st = new StringTokenizer(in.readLine());
		w = Integer.parseInt(st.nextToken());
		h = Integer.parseInt(st.nextToken());
		c = Integer.parseInt(st.nextToken());
		
		endOfParagraph = new Element();
		endOfFile = new Element();
		InputParser parser = new InputParser(in);
		
		
		int x = 0;
		int y = 0;
		int lineH = h;
		
		SurroundedImage bound = new SurroundedImage(w, 0, Integer.MAX_VALUE);
		bound.next = bound;
		bound.prev = bound;		
		SurroundedImage cur = bound;
		boolean fragmentBegins = true;
		
		while (true) {
			Element elem = parser.nextElement();
			if (elem == endOfFile) {
				break;
			}
			
			int curX = -1;
			int curY = -1;
			
			if (elem == endOfParagraph) {
				x = 0;
				y += lineH;
				lineH = h;
				fragmentBegins = true;
			} else if (elem.layout == LayOut.FLOATING) {
//				curX = lastX + elem.dx;
//				curY = lastY + elem.dy;
				curX = x + elem.dx;
				curY = y + elem.dy;
				if (curX < 0) {
					curX = 0;
				}
				if (curX > w - elem.width) {
					curX = w - elem.width;
				}
			} else {
				if ((elem.layout == LayOut.EMBEDDED) && (!fragmentBegins)) {
					x += c;
				}
				while (true) {
					while (cur.y <= y) {
						SurroundedImage prev = cur.prev;
						cur = cur.next;
						prev.next = cur;
						cur.prev = prev;
					}
					if (x + elem.width <= cur.x1) {
						break;
					}
					if (cur == bound) {
						y += lineH;
						lineH = h;
					}
					x = cur.x2;
					cur = cur.next;
				}
				curX = x;
				curY = y;
				
				if (elem.layout == LayOut.EMBEDDED) {
					if (lineH < elem.height) {
						lineH = elem.height;
					}
					fragmentBegins = false;
				} else {
					SurroundedImage img = new SurroundedImage(x, x + elem.width, y + elem.height);
					SurroundedImage prev = cur.prev;
					prev.next = img;
					img.prev = prev;
					img.next = cur;
					cur.prev = img;
					fragmentBegins = true;
				}
				x += elem.width;
			}
			if (elem.isImage) {
				out.println(curX + " " + curY);
			}			
		}
		
		in.close();
		out.close();
	}
	
	private class SurroundedImage {
		int x1, x2, y;
		SurroundedImage next, prev;
		
		SurroundedImage(int x1, int x2, int y) {
			this.x1 = x1;
			this.x2 = x2;
			this.y = y;
		}
	}
	
	private class InputParser {
		private BufferedReader reader;
		private boolean eof; 
		private boolean eop;
		private StringTokenizer tokenizer;
		
		public InputParser(BufferedReader reader) throws IOException {
			this.reader = reader;
			initTokenizer();
			eof = false;
			eop = false;
		}
		
		private void initTokenizer() throws IOException {
			while (true) {
				String str = reader.readLine();
				if (str == null) {
					eof = true;
					return;
				}
				tokenizer = new StringTokenizer(str);
				if (tokenizer.hasMoreTokens()) {
					break;
				}
				eop = true;
			}
		}
		
		public Element nextElement() throws IOException {
			if (!tokenizer.hasMoreTokens()) {
				initTokenizer();
			}
			if (eof) {
				return endOfFile;
			}
			if (eop) {
				eop = false;
				return endOfParagraph;
			}
			String token = tokenizer.nextToken();
			if (token.equals("(image")) {
				Element res = new Element();
				res.isImage = true;
				
				boolean loop = true;
				while (loop) {
					if (!tokenizer.hasMoreTokens()) {
						initTokenizer();
					}
					token = tokenizer.nextToken();
					if (token.charAt(token.length() - 1) == ')') {
						token = token.substring(0, token.length() - 1);
						loop = false;
					}
					int pos = token.indexOf('=');
					String key = token.substring(0, pos);
					String value = token.substring(pos + 1);
					if (key.equals("width")) {
						res.width = Integer.parseInt(value);
					} else if (key.equals("height")) {
						res.height = Integer.parseInt(value);
					} else if (key.equals("dx")) {
						res.dx = Integer.parseInt(value);
					} else if (key.equals("dy")) {
						res.dy = Integer.parseInt(value);
					} else if (key.equals("layout")) {
						if (value.equals("embedded")) {
							res.layout = LayOut.EMBEDDED;
						} else if (value.equals("surrounded")) {
							res.layout = LayOut.SURROUNDED;
						} else if (value.equals("floating")) {
							res.layout = LayOut.FLOATING;
						} else {
							throw new Error(); 
						}
					} else {
						throw new Error();
					}
				}
				return res;
			}
			Element res = new Element();
			res.isImage = false;
			res.width = c * token.length();
			res.height = h;
			res.layout = LayOut.EMBEDDED;
			return res;
		}
	}
	
	private enum LayOut {
		EMBEDDED, SURROUNDED, FLOATING
	}

	private class Element {
		int width, height, dx, dy;
		boolean isImage;
		LayOut layout;
	}
	
	public static void main(String[] args) {
		new Thread(new layout_ia()).start();
	}

}
