/* Problem 3--Presentation Error
   I didn't think this problem was too hard; just tedious.  The problem
   description gave the exact algorithm you need to solve the problem.
   The trick was making sure all the nitty gritty details got entered.*/

#include <fstream>
#include <cstring>
#include <cctype>
using namespace std;

ifstream in ("prob3.in");
ofstream out ("prob3.out");

class bracket;

class bracket { //bracket represents the beginning and position of each
 public:        //essential.
  int b, e;
};

int main (int argc, char **argv);
void append (char *L, int &l, char *line, bracket *b, int &bl);
bool validate (char *official, char *input, bracket *b, int bl);
void cap (char *str);
void trimeol (char *str, int c);

int main (int argc, char **argv) {

 int cases;
 char official[811],input[811],line[81];//official is CorrectOut; input
                                        //is SubmitOut.
 bracket b[800];
 in >> cases;
 for (int i=0;i<cases;i++) {
  int il, ol, l, bl = 0;
  in >> ol >> il; in.getline (line,sizeof line);
  l=0;
  for (int j=0; j<ol; j++) { //Get CorrectOut.
   in.getline (line,sizeof line);
   append (official,l,line,b,bl); //Add this line to CorrectOut.
  }
  trimeol (official,l); //Kill trailing blank lines.
  l=0;
  for (int j=0; j<il; j++) { //Get SubmitOut.
   in.getline (line,sizeof line);
   append (input,l,line,b,bl);
  }
  trimeol (input,l); //Kill trailing blank lines.
  if (strcmp(official,input)==0) out << "Accepted" << endl;
      //If they match, the output is accepted.
  else {
   cap (official); cap (input); //Capitalize both.
   if (validate (official,input,b,bl)) //If the essentials match
    out << "Presentation Error" << endl;
   else out << "Wrong Answer" << endl;
  }
 }
 return 0;
}

/* append adds a line of line of text to output listing L.  All trailing
   spaces are removed and the positions of the essentials are noted. */

void append (char *L, int &l, char *line, bracket *b, int &bl) {

 int c;
 for (c = strlen (line)-1; c >= 0; c--)
  if (line[c] != ' ') break; //Remove trailing spaces.
 line[c+1] = 0;
 for (int c=0; line[c]!=0; c++)
  switch (line[c]) {
   case '[': {b[bl].b = l; break;} //Beginning of essential
   case ']': {b[bl++].e = l-1; break;} //End of essential
   default: L[l++] = line[c]; //Otherwise, just add it to the output.
  }
 L[l++] = '\n'; //Add <EOLN> to the output.
}

/* validate compares the two matches essentials within the outputs.  It
   returns true if they match, false if they don't. */

bool validate (char *official, char *input, bracket *b, int bl) {

 char *pos = input; //Beginning position of string
 for (int i=0;i<bl;i++) {
  char essential[80]={}; //Copy the essential we're looking at.
  memcpy (essential,official+b[i].b,b[i].e-b[i].b+1);
  char * loc = strstr (pos,essential); //Is this essential in the string
  if (loc==NULL) return false;         //starting from pos?
  pos = loc+b[i].e-b[i].b+1; //Move pos to just past essential.
 }
 return true;
}

/* cap capitalizes a string. */

void cap (char *str) {

 for (int c=0; str[c]!=0; c++) str[c] = toupper (str[c]);
}

/* trimeol removes trailing blank lines from the end of a string. */

void trimeol (char *str, int c) {

 for (c--; c >= 0; c--)
  if (str[c]!='\n') break;
 if (c==-1) str[0] = 0; else str[c+2] = 0; //Be careful not to strip off
                                         //the <EOLN> for the last line.
}
