//
// Written by Fyodor Menshikov 07.03.2010
//

   procedure ac;
   begin
      writeln('a');
      halt(0);
   end;

   procedure wa;
   begin
      writeln('wa');
      halt(1);
   end;

   procedure pe;
   begin
      writeln('pe');
      halt(2);
   end;

   procedure ie;
   begin
      writeln('ie');
      while true do;
   end;

const
   EOT = #0;
   EOL = #13;
var
   c : char;

   procedure nextChar;
   begin
      if eof then begin
         c := EOT;
      end
      else if eoln then begin
         c := EOL;
         readln;
      end
      else begin
         read(c);
         if c = EOT then begin
            pe;
         end;
         if c = EOL then begin
            pe;
         end;
      end;
   end;

   function number:integer;
   var
      value : integer;
   begin
      if not (c in ['0'..'9']) then begin
         pe;
      end;
      value := ord(c) - ord('0');
      nextChar;
      while c in ['0'..'9'] do begin
         value := value * 10 + ord(c) - ord('0');
         nextChar;
         if value > 1000000 then begin
            pe;
         end;
      end;
      number := value;
   end;

   procedure skip(s : string);
   var
      i : integer;
   begin
      for i := 1 to length(s) do begin
         if c <> s[i] then begin
            pe;
         end;
         nextChar;
      end;
   end;
   
var
   need, s : string;
   jActions, uActions, i, from, till : integer;
begin
   assign(input, 'kmp.in');
   reset(input);
   readln(need);
   assign(input, 'kmp.chk');
   reset(input);
   readln(jActions);
   assign(input, 'kmp.out');
   reset(input);
   nextChar;
   uActions := number;
   if uActions < 0 then begin
      pe;
   end;
   skip(EOL);
   s := '';
   for i := 1 to uActions do begin
      if c = 'l' then begin
         skip('letter');
         skip(EOL);
         if length(s) >= length(need) then begin
            wa;
         end;
         s := s + need[length(s) + 1];
      end
      else if c = 'c' then begin
         skip('copy ');
         from := number;
         skip(' ');
         till := number;
         skip(EOL);
         if from < 1 then begin
            pe;
         end;
         if till <= from then begin
            pe;
         end;
         if till > length(s) + 1 then begin
            pe;
         end;
         s := s + copy(s, from, till - from);
         if length(s) > length(need) then begin
            wa;
         end;
      end
      else begin
         pe;
      end;
   end;
   skip(EOT);
   if s <> need then begin
      wa;
   end;
   if uActions > jActions then begin
      wa;
   end;
   if uActions < jActions then begin
      ie;
   end;
   ac;
end.