/* Problem 3--Circular Buffer
   This one was pretty straightforward.  Just process the commands and
   print the results! */

import java.io.*;
import java.util.*;

public class prob3 {

 public static Scanner in=null;
 public static PrintWriter out=null;
 public static char[] buffer = new char[54];
 public static int wbeg = 0, rbeg = 0, len=54;

 public static void main (String[] args) throws Exception {

  in = new Scanner (new File ("prob3.in"));
  out = new PrintWriter ("prob3.out");
  String inp = null;
  while (!(inp=in.nextLine()).equals("0")) {
   if (inp.charAt(0)=='W') { // write command
    String writer = inp.substring(1);
    if (writer.length() <= len) { //Will it fit?
     for (int i=wbeg, j=0; j < writer.length(); i=(i+1)%54, j++)
      buffer[i] = writer.charAt(j);
     wbeg += writer.length()%54;
     len -= writer.length();
    }
   } else { // read command
    int rlen = Integer.parseInt (inp.substring(1));
    rlen = Math.min (rlen,54-len);
    rbeg = (rbeg+rlen)%54;
    len += rlen;
   }
   out.println (wbeg+", "+len);
  }
  for (int i=0; i < 54-len; i++) // print buffer
   out.print (buffer[(rbeg+i)%54]);
  out.println();
  in.close();
  out.close();
 }
}
