program kp_brackets;

{$APPTYPE CONSOLE}

// Complexity O(m^3*n^2)
// But should get TLE, because of too much useless string concatenations and assigments

const
  maxn=10;
  maxm=100;

var
  s, ch, s1: string;
  n, m, i, j, k: integer;
  a: array ['a'..'j','a'..'j'] of char;
  c: array [1..maxm,1..maxm,'a'..'j'] of string;
  cL, cR, eC: char;

begin
//  reset(input,'input.txt');
//  rewrite(output,'output.txt');

  // reading and checking input

  readln(n);
  assert((1<=n) and (n<=maxn));

  readln(s); m:= length(s);
  assert((m>=1) and (m<=maxm));
  for i:=1 to m do assert((s[i] in ['a'..'z']) and (ord(s[i])-ord('a')+1<=n));
  readln(ch);
  assert((length(ch)=1) and (ch[1] in ['a'..'z']) and (ord(ch[1])-ord('a')+1<=n));
  for i:=1 to n do begin
    eC:= char(i+ord('a')-1);
    readln(s1);
    assert(length(s1)=n);
    for j:=1 to n do assert((s1[j] in ['a'..'z']) and (ord(s1[j])-ord('a')+1<=n));
    for j:=1 to n do a[eC,char(j+ord('a')-1)]:= s1[j];
  end;

  eC:= char(ord('a')+n-1);

  // solving
  fillchar(c,sizeof(c),0);
  for i:=1 to m do c[i,i,s[i]]:= s[i];

  for i:=2 to m do
    for j:=1 to m-i+1 do
      for k:=j to j+i-2 do
        for cL:= 'a' to eC do
          for cR:= 'a' to eC do
            if (c[j,k,cL]<>'') and (c[k+1,j+i-1,cR]<>'') then
              c[j,j+i-1,a[cL,cR]]:= '('+c[j,k,cL]+')('+c[k+1,j+i-1,cR]+')';

  if c[1,m,ch[1]]='' then writeln('NO')
  else begin
    writeln('YES');
    writeln(c[1,m,ch[1]]);
  end;
end.