{
Written by Fyodor Menshikov 12.02.2004
12:35-13:41,bug found 13:58
Delphi!
}
{-$R+,Q+}
{$S-}
//{$define timeopt}
const
   maxDictLen=1000;{TP -> 3 Delphi -> 1000}
   maxWordLen=20;
   maxForms=
      maxWordLen*25{change}+
      maxWordLen-1{dup}+
      maxWordLen{skip}+
      maxWordLen-1{swap}+
      1{correct};
type
   integer=longint;
   word=string[maxWordLen];
var
   forms:array[0..maxDictLen*maxForms+1] of record
      w:word;
      original:boolean;
      src1,src2,src3,src4,dummy:smallint;
   end;
   formsLen:integer;
   dict:array[1..maxDictLen]of word;

   function findForm(w:word):integer;
   var
      l,r,m:integer;
   begin
      l:=1;
      r:=formsLen;
      while l<=r do begin
         m:=(l+r) div 2;
         if w<forms[m].w then
            r:=m-1
         else if w>forms[m].w then
            l:=m+1
         else begin
            findForm:=m;
            exit;
         end;
      end;
      findForm:=-1;
   end;

   procedure checkword(w:word;line,wordinline:integer);
   var
      downw:word;
      f,i:integer;
   begin
      downw:=w;
      for i:=1 to length(w) do
         if downw[i] in ['A'..'Z'] then
            downw[i]:=chr(ord(downw[i])-ord('A')+ord('a'));
      f:=findForm(downw);
      if f=-1 then begin
         writeln(w,' ',line,' ',wordinline,' NO VARIANTS');
         exit;
      end;
      if forms[f].original then
         exit;
      write(w,' ',line,' ',wordinline);
      write(' ',dict[forms[f].src1]);
      if forms[f].src2=0 then begin
         writeln;
         exit;
      end;
      write(' ',dict[forms[f].src2]);
      if forms[f].src3=0 then begin
         writeln;
         exit;
      end;
      write(' ',dict[forms[f].src3]);
      if forms[f].src4=0 then begin
         writeln;
         exit;
      end;
      writeln('...');
   end;

var
   key:word;

   procedure sortForms(l,r:integer);
   var
      i,j:integer;
   begin
      key:=forms[(l+r)div 2].w;
      i:=l;
      j:=r;
      repeat
         while forms[i].w<key do
            inc(i);
         while key<forms[j].w do
            dec(j);
         if i<=j then begin
            forms[0]:=forms[i];
            forms[i]:=forms[j];
            forms[j]:=forms[0];
            inc(i);
            dec(j);
         end;
      until i>j;
      if l<j then
         sortForms(l,j);
      if i<r then
         sortForms(i,r);
   end;

   procedure addForm(w:word;original:boolean;src:integer);
   begin
      inc(formsLen);
      forms[formsLen].w:=w;
      forms[formsLen].original:=original;
      forms[formsLen].src1:=src;
      forms[formsLen].src2:=0;
      forms[formsLen].src3:=0;
      forms[formsLen].src4:=0;
   end;

   procedure orderForms;
   var
      i,dest:integer;
      prevw:word;
   begin
      sortForms(1,formsLen);
      {$ifdef timeopt}writeln('sorted');{$endif}
      prevw:='*';
      dest:=0;
      for i:=1 to formsLen do begin
         if forms[i].w<>prevw then begin
            inc(dest);
            forms[dest]:=forms[i];
            prevw:=forms[i].w;
         end
         else {same word} if forms[dest].original then
            {nothing}
         else if forms[i].original then
            forms[dest]:=forms[i]
         else {both not original} begin
            if (forms[dest].src4=0) {may be added} and
               (forms[i].src1<>forms[dest].src1) and
               (forms[i].src1<>forms[dest].src2) and
               (forms[i].src1<>forms[dest].src3)
            then begin
               if forms[dest].src2=0 then
                  forms[dest].src2:=forms[i].src1
               else if forms[dest].src3=0 then
                  forms[dest].src3:=forms[i].src1
               else
                  forms[dest].src4:=forms[i].src1
            end;
         end;
      end;
      formsLen:=dest;
      {$ifdef timeopt}writeln('compressed');{$endif}      
   end;

   procedure addForms(dictw:word;dicti:integer);
   var
      w:word;
      i,j:integer;
      c:char;
   begin
      {correct}
      addForm(dictw,true,0);
      {change}
      for i:=1 to length(dictw) do
         for c:='a' to 'z' do
            if dictw[i]<>c then begin
               w:=dictw;
               w[i]:=c;
               addForm(w,false,dicti);
            end;
      {dup}
      if length(dictw)<maxWordLen then
         for i:=1 to length(dictw) do begin
            w:=dictw;
            for j:=length(dictw) downto i do
               w[j+1]:=w[j];
            inc(w[0]);
            addForm(w,false,dicti);
         end;
      {skip}
      if length(dictw)>1 then
         for i:=1 to length(dictw) do begin
            w:=dictw;
            for j:=i to length(dictw)-1 do
               w[j]:=w[j+1];
            dec(w[0]);
            addForm(w,false,dicti);
         end;
      {swap}
      if length(dictw)>1 then
         for i:=1 to length(dictw)-1 do begin
            w:=dictw;
            c:=w[i];
            w[i]:=w[i+1];
            w[i+1]:=c;
            addForm(w,false,dicti);
         end;
   end;

var
   dictLen,i,n,line,linepos,wordinline:integer;
   prev,curw:word;
   c:char;
begin
//   assign(input,'input.txt');
   reset(input);
   readln(dictLen);
   formsLen:=0;
   prev:='';
   for i:=1 to dictLen do begin
      readln(dict[i]);
      if dict[i]<=prev then begin
         writeln('dictionary words not ordered: ',prev,' ',dict[i]);
         halt;
      end;
      prev:=dict[i];
      addForms(dict[i],i);
   end;
   {$ifdef timeopt}
   writeln(maxDictLen*maxForms+1);
   writeln('dictionary loaded');
   {$endif}
   orderForms;
//   assign(output,'output.txt');
   rewrite(output);
   readln(n);
   line:=1;
   linepos:=0;
   wordinline:=0;
   curw:='';
   while true do begin
      if eoln then
         c:=#13
      else begin
         read(c);
         inc(linepos);
      end;
      if c in ['A'..'Z','a'..'z'] then begin
         if length(curw)=maxWordLen then begin
            writeln('word too long (line ',line,' pos ',linepos);
         end;
         curw:=curw+c;
      end
      else begin
         if curw<>'' then begin
            inc(wordinline);
            checkword(curw,line,wordinline);
            curw:='';
         end;
      end;
      if c=#13 then begin
         readln;
         inc(line);
         linepos:=0;
         wordinline:=0;
         if line>n then begin
            if not eof then
               writeln('EOF expected!');
            halt;
         end;
      end
   end;
end.