//
// Written by Fyodor Menshikov 21.02.2006
// 10:45-11:12
//
type
   tset=set of 'a'..'j';
var
   sets:array[1..100,1..100]of tset;
   sum:tset;
   s:string;
   n:integer;
   mul:array['a'..'j','a'..'j']of char;
   lastc:char;

   function res(left,right:integer;need:char):string;
   var
      part:integer;
      ci,cj:char;
   begin
      if left=right then begin
         assert(s[left]=need);
         res:=need;
         exit;
      end;
      assert(left<right);
      for part:=1 to right-left do begin
         for ci:='a' to lastc do begin
            if ci in sets[left,left+part-1] then begin
               for cj:='a' to lastc do begin
                  if cj in sets[left+part,right] then begin
                     if mul[ci,cj]=need then begin
                        res:='('+res(left,left+part-1,ci)+res(left+part,right,cj)+')';
                        exit;
                     end;
                  end;
               end;
            end;
         end;
      end;
      assert(false);
   end;

var
   ci,cj,need:char;
   len,left,right,part:integer;
begin
//   assign(input,'input.txt');
   reset(input);
  // assign(output,'output.txt');
   rewrite(output);
   readln(n);
   lastc:=chr(ord('a')+(n-1));
   readln(s);
   assert(length(s)<=100);
   readln(need);
   for ci:='a' to lastc do begin
      for cj:='a' to lastc do begin
         assert(not eoln);
         read(mul[ci,cj]);
         assert(('a'<=mul[ci,cj])and(mul[ci,cj]<=lastc));
      end;
//      assert(eoln);
      readln;
   end;
   for len:=1 to length(s) do begin
      for left:=1 to length(s)-len+1 do begin
         right:=left+len-1;
         if len=1 then begin
            sets[left,right]:=[s[left]];
         end
         else begin
            sum:=[];
            for part:=1 to len-1 do begin
               for ci:='a' to lastc do begin
                  if ci in sets[left,left+part-1] then begin
                     for cj:='a' to lastc do begin
                        if cj in sets[left+part,right] then begin
                           include(sum,mul[ci,cj]);
                        end;
                     end;
                  end;
               end;
            end;
            sets[left,right]:=sum;
         end;
      end;
   end;
   if not(need in sets[1,length(s)]) then begin
      writeln('NO');
      halt;
   end;
   writeln('YES');
   writeln(res(1,length(s),need));
end.