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

public class layout_rs implements Runnable {
    private int w, h, c;
    
    private class MyImage {
        private static final int STYLE_EMBEDDED = 0;
        private static final int STYLE_FLOATING = 1;
        private static final int STYLE_SURROUNDED = 2;
        public int height;
        public int width;
        public int dx, dy;
        public int style;
        public int x, y;
        public boolean text;
        
        public void setStyle(String value) {
            if (value.equals("surrounded")) {
                this.style = STYLE_SURROUNDED;
            } else if (value.equals("floating")) {
                this.style = STYLE_FLOATING;
            } else if (value.equals("embedded")) {
                this.style = STYLE_EMBEDDED;
            }
        }
    }
    
    private class MyReader {
        private BufferedReader in;
        private char[][] text;
        private int curParagraph;
        
        public MyReader(BufferedReader reader) throws IOException {
            in = reader;
            
            ArrayList<String> str = new ArrayList<String>();
            StringBuffer sb = new StringBuffer();
            while (true) {
                String cur = in.readLine();
                if (cur == null)
                    break;
                
                cur = cur.trim();
                if (cur.length() == 0) {
                    str.add(sb.toString());
                    sb = new StringBuffer();
                    continue;
                }
                
                sb.append(" ");
                sb.append(cur);
            }
            
            if (sb.length() > 0) {
                str.add(sb.toString());
            }
            
            text = new char[str.size()][];
            for (int i = 0; i < str.size(); i++) {
                text[i] = str.get(i).toCharArray();
            }
        }
        
        public MyImage[] nextParagraph() throws IOException {
            if (curParagraph == text.length) {
                return null;
            }
            
            ArrayList<MyImage> images = new ArrayList<MyImage>();
            char[] str = text[curParagraph++];
            int cur = 0;
            
            while (cur < str.length) {
                if (Character.isWhitespace(str[cur])) {
                    cur++;
                    continue;
                }
                if (str[cur] == '(') {
                    int from = cur + 1;
                    while (str[cur] != ')') {
                        cur++;
                    }
                    int to = cur;
                    cur++;
                    
                    char[] info = new char[to - from];
                    for (int i = from; i < to; i++) {
                        info[i - from] = str[i];
                    }
                    
                    Scanner scan = new Scanner(new String(info));
                    scan.useDelimiter("[\\s=]+");
                    scan.next(); // image
                    
                    MyImage image = new MyImage();
                    while (scan.hasNext()) {
                        String field = scan.next();
                        String value = scan.next();
                        
                        if (field.equals("layout")) {
                            image.setStyle(value);
                            continue;
                        }
                            
                        if (field.equals("dx")) {
                            image.dx = Integer.parseInt(value);
                            continue;
                        }
                        
                        if (field.equals("dy")) {
                            image.dy = Integer.parseInt(value);
                            continue;
                        }
                        
                        if (field.equals("width")) {
                            image.width = Integer.parseInt(value);
                            continue;
                        }
                        
                        if (field.equals("height")) {
                            image.height = Integer.parseInt(value);
                            continue;
                        }
                    }
                    
                    images.add(image);
                    continue;
                }
                
                int size = 0;
                while ((cur < str.length) && (str[cur] != '(') && (!Character.isWhitespace(str[cur]))) {
                    cur++;
                    size++;
                }
                
                MyImage image = new MyImage();
                image.text = true;
                image.setStyle("embedded");
                image.width = size * c;
                image.height = h;
                images.add(image);
            }
            
            MyImage[] result = new MyImage[images.size()];
            images.toArray(result);
            return result;
        }
        
        public void close() throws IOException {
            in.close();
        }
    }
    
    private class MyDocument {
        private int startPosition;
        
        public void addParagraph(MyImage[] images) {
            int curPosition = 0;
            int curHeightPos = startPosition;
            int curHeight = h;
            
            boolean needWhiteSpace = false;
            for (int i = 0; i < images.length; i++) {
                MyImage curImage = images[i];
                
                if (curImage.style == MyImage.STYLE_FLOATING) {
                    // If previous page is floating too - special case
                    if ((i > 0) && (images[i - 1].style == MyImage.STYLE_FLOATING)) {
                        curImage.y = images[i - 1].y + curImage.dy;
                        curImage.x = images[i - 1].x + images[i - 1].width + curImage.dx;
                        curImage.x = Math.max(curImage.x, 0);
                        curImage.x = Math.min(curImage.x, w - curImage.width);
                        continue;
                    }
                    curImage.y = curHeightPos + curImage.dy;
                    curImage.x = curPosition + curImage.dx;
                    curImage.x = Math.max(curImage.x, 0);
                    curImage.x = Math.min(curImage.x, w - curImage.width);
                    continue;
                }
                
                while (true) {
                    int newPos = w;
                    int left = w;
                    int width = curImage.width; 
                    if ((curImage.style == MyImage.STYLE_EMBEDDED) && needWhiteSpace) {
                        width += c;
                    }
                    
                    for (int j = 0; j < i; j++) {
                        if ((images[j].style == MyImage.STYLE_SURROUNDED) && (images[j].y + images[j].height > curHeightPos) && (images[j].x >= curPosition)) {
                            if (images[j].x < left) {
                                left = images[j].x;
                                newPos = images[j].x + images[j].width;
                            }
                        }
                    }
                    
                    if (curPosition + width <= left) {
                        break;
                    }
                    
                    curPosition = newPos;
                    needWhiteSpace = false;
                    if (curPosition == w) {
                        curPosition = 0;
                        curHeightPos += curHeight;
                        curHeight = h;
                    }
                }
                
                if ((curImage.style == MyImage.STYLE_EMBEDDED) && needWhiteSpace) {
                    curImage.x = curPosition + c;
                } else {
                    curImage.x = curPosition;
                }
                
                curImage.y = curHeightPos;
                needWhiteSpace = false;
                if (curImage.style == MyImage.STYLE_EMBEDDED) {
                    curHeight = Math.max(curHeight, curImage.height);
                    needWhiteSpace = true;
                }
                
                curPosition = curImage.x + curImage.width;
            }
            if (images.length > 0)
                startPosition = curHeightPos + curHeight;
            else
                startPosition = curHeightPos;
            
            for (int i = 0; i < images.length; i++) {
                if (images[i].style != MyImage.STYLE_SURROUNDED)
                    continue;
                
                startPosition = Math.max(startPosition, images[i].y + images[i].height);
            }
        }
    }
    
    
    private void solve() throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(new File("layout.in")));
        PrintWriter out = new PrintWriter("layout.out");
        
        StringTokenizer st = new StringTokenizer(reader.readLine());
        w = Integer.parseInt(st.nextToken());
        h = Integer.parseInt(st.nextToken());
        c = Integer.parseInt(st.nextToken());
        
        MyReader in = new MyReader(reader);
        MyDocument doc = new MyDocument();
        
        ArrayList<MyImage> allImages = new ArrayList<MyImage>();
        while (true) {
            MyImage[] cur = in.nextParagraph();
            if (cur == null)
                break;
            
            for (int i = 0; i < cur.length; i++) {
                allImages.add(cur[i]);
            }
            doc.addParagraph(cur);
        }
        
        for (MyImage image : allImages) {
            if (!image.text)
                out.println(image.x + " " + image.y);
        }
        
        in.close();
        out.close();
    }
    
    public static void main(String[] args) {
        new Thread(new layout_rs()).start();
    }

    public void run() {
        try {
            solve();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
