#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <list>
#include <sstream>
#include <cmath>
#include <map>
#include <set>
using namespace std;

#define fr(x,y,z) for((x)=(y);(x)<(z);++(x))
#define fo(x,y) fr(x,0,y)
#define fir(n) fo(i,n)
#define fjr(n) fo(j,n)
#define fkr(n) fo(k,n)
#define V(x) vector<x >

struct img {
	int x, y, w, h;
};

struct frag {
	int x, l, f;
};

int i, j, k, l, m, n, t, w, h, C;

string s;

list<img> imgs;
frag frags[1005];
int fs, down = 0, curf = 0, up = -1, downn = 0;
img tmpi;
char cs[1005], ccs[1005];
bool a[1003];

void makefrags() {
	up = down;
	memset(a, 0, sizeof(a));
	int i;
	list<img>::iterator li = imgs.begin(), li2;
	while (li != imgs.end()) {
		if (li->y + li->h <= up) {
			li2 = li; li2++; imgs.erase(li); li = li2;
		}
		else {
			fr(i,li->x,li->x + li->w)
				a[i] = 1;
			++li;
		}
	}
	fs = 0;
	i = 0;
	while (i < w) {
		while (a[i])
			++i;
		if (i >= w) break;
		frags[fs].x = i;
		frags[fs].f = 1;
		while (i < w && !a[i])
			++i;
		frags[fs].l = i - frags[fs].x;
		++fs;
	}
	down += h;
	curf = 0;
}

int findspace(int l, bool prob) {
	int i;
	while (1) {
		fr(i,curf,fs)
			if (l + C * (prob && !frags[i].f) <= frags[i].l)
				return i;
		makefrags();
	}
}

void insert(int where, int l, bool prob, int h) {
	frags[where].l -= l + C * (prob && !frags[where].f);
	frags[where].x += l + C * (prob && !frags[where].f);
	frags[where].f = 0;
	if (prob) {
		if (up + h > down)
			down = up + h;
	}
}

bool newline() {
	int cc = 0;
	char c;
	c = getc(stdin);
	while (c == 32 || c == 9)
		c = getc(stdin);
	if (c == 10 || c == 13) { 
		/*c = getc(stdin);
		if (c != 10 && c != 13)
			ungetc(c, stdin);*/
		return true;
	}
	else {
		ungetc(c, stdin);
		return false;
	}
}
int main() {
	
	// FILE SIZE ASSERT
	freopen("layout.in", "r", stdin);
	t = 0;
	while (!feof(stdin)) {
		getc(stdin);
		++t;
	}
	assert(t <= 1000);
	fclose(stdin);

	freopen("layout.in", "r", stdin);
	freopen("layout.out", "w", stdout);
	scanf(" %d %d %d", &w, &h, &C);
	assert(w >= 1);
	assert(w <= 1000);
	assert(h >= 1);
	assert(h <= 50);
	assert(C >= 1);
	assert(C <= w);
	newline();
	assert(!newline());
	makefrags();
	while (!feof(stdin)) {
		newline();
		if (newline()) {
			if (down < downn)
				down = downn;
			makefrags();
		}
		assert(!newline());
		if (scanf(" %s", ccs) <= 0) break;
		if (ccs[0] == '(') { // IMAGE
			int ww = 0, hh = 0, type, dx = 0, dy = 0;
			bool nya = 1;
			while (nya) {
				scanf(" %s", cs);
				l = strlen(cs);
				if (cs[l-1] == ')') { --l; nya = 0; }
				if (l >= 8 && 
					cs[0] == 'l' && cs[1] == 'a' && cs[2] == 'y' &&
					cs[3] == 'o' && cs[4] == 'u' && cs[5] == 't' &&
					cs[6] == '=' ) {
					if (cs[7] == 'e') type = 1;
					else if (cs[7] == 's') type = 2;
					else if (cs[7] == 'f') type = 3;					
				}
				else if (l >= 7 &&
						 cs[0] == 'w' && cs[1] == 'i' && cs[2] == 'd' &&
						 cs[3] == 't' && cs[4] == 'h' && cs[5] == '=') {
					fr(i,6,l) 
						ww = ww*10 + cs[i] - '0';
				}
				else if (l >= 7 &&
					     cs[0] == 'h' && cs[1] == 'e' && cs[2] == 'i' &&
						 cs[3] == 'g' && cs[4] == 'h' && cs[5] == 't' &&
						 cs[6] == '=') {
					fr(i,7,l) 
						hh = hh*10 + cs[i] - '0';
				}
				else if (l >= 4 && 
					 	 cs[0] == 'd' && cs[1] == 'x' && cs[2] == '=') {
					if (cs[3] == '-') {
						fr(i,4,l) 
							dx = dx*10 + cs[i] - '0';
						dx = -dx;
					}
					else {
						int o = 3;
						if (cs[3] == '+') ++o;
						fr(i,3,l) 
							dx = dx*10 + cs[i] - '0';
					}
				}
				else if (l >= 4 && 
					 	 cs[0] == 'd' && cs[1] == 'y' && cs[2] == '=') {
					if (cs[3] == '-') {
						fr(i,4,l) 
							dy = dy*10 + cs[i] - '0';
						dy = -dy;
					}
					else {
						int o = 3;
						if (cs[3] == '+') ++o;
						fr(i,o,l) 
							dy = dy*10 + cs[i] - '0';
					}
				}
			}
			assert(ww <= w);
			assert(hh <= 1000);
			if (type == 1) {
				curf = findspace(ww, true);
				cout << frags[curf].x + C * (true && !frags[curf].f) 
					 << " " << up << endl;
				insert(curf, ww, true, hh);
			}
			else if (type == 2) {
				curf = findspace(ww, false);
				cout << frags[curf].x << " " << up << endl;
				tmpi.h = hh, tmpi.w = ww, tmpi.y = up, tmpi.x = frags[curf].x;
				insert(curf, ww, false, hh);
				frags[curf].f = 1;
				imgs.push_back(tmpi);
				if (downn < up + hh)
					downn = up + hh;
			}
			else if (type == 3) {
				assert(abs(dx) <= 1000);
				assert(abs(dy) <= 1000);
				int xx = frags[curf].x + dx;
				int yy = up + dy;
				if (xx < 0) xx = 0;
				if (xx + ww > w) xx = w - ww;
				cout << xx << " " << yy << endl;
			}
		}
		else { // WORD
			l = strlen(ccs) * C;
			curf = findspace(l, true);
			insert(curf, l, true, h);
		}
	}
	return 0;
}
