#include <iostream>

#include <string>

using namespace std;



const int MAXSIZE = 20;



bool room[MAXSIZE][MAXSIZE];

int nRow, nCol;



int calcMaxPossible(string s, int n)

{

	int max=0;

	if (s == "down" || s == "up") {

		for(int col = 0; col <nCol; col++) {

			int count = 0;

			for(int row=0; row<nRow; row++) {

				if (room[row][col])

					count++;

			}

			if (count > max)

				max = count;

		}

		return (n<nRow-max)? n : nRow-max;

	}

	else {

		for(int row = 0; row <nRow; row++) {

			int count = 0;

			for(int col=0; col<nCol; col++) {

				if (room[row][col])

					count++;

			}

			if (count > max)

				max = count;

		}

		return (n<nCol-max)? n : nCol-max;

	}

}



void process(string s, int n)

{

	n = calcMaxPossible(s, n);

	if (s == "down") {

		int count = 0;

                int row,col;

		for(col = 0; col <nCol; col++) {

			for(row=0; row<n; row++) {

				if (room[row][col]) {

					room[row][col] = false;

					count++;

				}

			}

			for(;row<nRow; row++) {

				if (count == 0)

					break;

				if (!room[row][col]) {

					room[row][col] = true;

					count--;

				}

			}

		}

	}

	if (s == "up") {

		int count = 0;

                int row,col;

		for(col = 0; col <nCol; col++) {

			for(row=nRow-1; row>nRow-1-n; row--) {

				if (room[row][col]) {

					room[row][col] = false;

					count++;

				}

			}

			for(; row>=0; row--) {

				if (count == 0)

					break;

				if (!room[row][col]) {

					room[row][col] = true;

					count--;

				}

			}

		}

	}

	if (s == "right") {

		int count = 0;

                int row,col;

		for(row = 0; row <nRow; row++) {

			for(col=0; col<n; col++) {

				if (room[row][col]) {

					room[row][col] = false;

					count++;

				}

			}

			for(;col<nCol; col++) {

				if (count == 0)

					break;

				if (!room[row][col]) {

					room[row][col] = true;

					count--;

				}

			}

		}

	}

	if (s == "left") {

		int count = 0;

                int row,col;

		for(row = 0; row <nRow; row++) {

			for(col=nCol-1; col>nCol-1-n; col--) {

				if (room[row][col]) {

					room[row][col] = false;

					count++;

				}

			}

			for(; col>=0; col--) {

				if (count == 0)

					break;

				if (!room[row][col]) {

					room[row][col] = true;

					count--;

				}

			}

		}

	}

}



int main()

{

	cin >> nRow >> nCol;

	int icase = 0;

	while (nRow != 0) {

		icase++;

                int i, j;

		for(i=0; i<nRow; i++)

			for(j=0; j<nCol; j++)

				room[i][j] = false;

		int nBoxes;

		cin >> nBoxes;

		for(i=0; i<nBoxes; i++) {

			int r, c;

			cin >> r >> c;

			room[r][c] = true;

		}



		string s;

		cin >> s;

		while (s != "done") {

			int n;

			cin >> n;

			process(s, n);

			cin >> s;

		}



		cout << "Data set " << icase << " ends with boxes at locations";

		for(i=0; i<nRow; i++)

			for(int j=0; j<nCol; j++)

				if (room[i][j]) {

					cout << " (" << i << ',' << j << ")";

				}

		cout << '.' << endl;



		cin >> nRow >> nCol;

	}

return 0;
}

