// BoxT.cc
// Pushing Boxes problem
// T Feil

#include <string.h>
#include <iostream>
using namespace std;

int Boxes[20][20];

void initBoxes(int h,  int w){
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      Boxes[i][j]=0;
}

void printBoxes(int h,  int w){
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(Boxes[i][j])
        cout<<" ("<<i<<','<<j<<')';
  cout<<'.'<<endl;
}
int main(){
  int h,w,n,ii,jj,count,k;
  int Case=1;
//  string direction;
  char direction[10];

  cin>>h>>w;
  while(h>0 && w>0){
    cout<<"Data set "<<Case++<<" ends with boxes at locations";
    initBoxes(h,w);
    cin>>n;
    for(int i=0;i<n;i++){
      cin>>ii>>jj;
      Boxes[ii][jj]=1;
    }
    cin>>direction;
    while(strcmp(direction,"done")!=0){
      cin>>n;
      if(strcmp(direction,"down")==0){
        //1st see how far down
        int max=0;
        for(int j=0;j<w;j++){
          count=0;
          for(int i=0;i<h;i++)
            count += Boxes[i][j];
          if(count>max) max=count;
        }
        if(h-max<n) n=h-max;
        //move down each column (start at top box)
        for(int j=0;j<w;j++){
          for(int i=0;i<n;i++)
            if(Boxes[i][j]){   //this box moved down
              Boxes[i][j]=0;
              k=i+1;           //find where box gets moved to
              while(Boxes[k][j]) k++;
              Boxes[k][j]=1;
            }
        }
     
      }
//      else if(direction=="up"){
      else if(strcmp(direction,"up")==0){
        //1st see how far up 
        int max=0;
        for(int j=0;j<w;j++){
          count=0;
          for(int i=0;i<h;i++)
            count += Boxes[i][j];
          if(count>max) max=count;
        }
        if(h-max<n) n=h-max;
        //move up each column (start at bottom box)
        for(int j=0;j<w;j++){
          for(int i=h-1;i>=h-n;i--){
            if(Boxes[i][j]){ //found a box to move up
              Boxes[i][j]=0;
              k=i-1;
              while(Boxes[k][j]) k--;
              Boxes[k][j]=1;
            }
          }
        }
     
      }
//      else if(direction=="left"){
      else if(strcmp(direction,"left")==0){
        //1st see how farleft 
        int max=0;
        for(int i=0;i<h;i++){
          count=0;
          for(int j=0;j<w;j++)
            count += Boxes[i][j];
          if(count>max) max=count;
        }
        if(w-max<n) n=w-max;
        //move left each row (start at right box)
        for(int i=0;i<h;i++){
          for(int j=w-1;j>=w-n;j--){
            if(Boxes[i][j]){ //found a box to move up
              Boxes[i][j]=0;
              k=j-1;
              while(Boxes[i][k]) k--;
              Boxes[i][k]=1;
            }
          }
        }
      }
//      else if(direction=="right"){
      else if(strcmp(direction,"right")==0){
        //1st see how far right
        int max=0;
        for(int i=0;i<h;i++){
          count=0;
          for(int j=0;j<w;j++)
            count += Boxes[i][j];
          if(count>max) max=count;
        }
        if(w-max<n) n=w-max;
        //move right each row (start at left box)
        for(int i=0;i<h;i++){
          for(int j=0;j<n;j++){
            if(Boxes[i][j]){ //found a box to move up
              Boxes[i][j]=0;
              k=j+1;
              while(Boxes[i][k]) k++;
              Boxes[i][k]=1;
            }
          }
        }
      }
      else  // this shouldn't happen
      {
        cout<<"bogus direction : "<<direction<<endl;
        return 0;
      }

//
//printBoxes(h,w);
      cin>>direction;
    }
      
    printBoxes(h,w);

    cin>>h>>w;
  }

  return 0;
}
