//16:36 - 17:13

{$APPTYPE CONSOLE}

const
  NMAX = 10;
  LENMAX = 100;

var
  n: integer;
  s: string;
  res: char;
  a: array['a'..chr(ord('a')+NMAX-1),'a'..chr(ord('a')+NMAX-1)] of char;
  p: array[1..LENMAX,1..LENMAX] of string [NMAX];

procedure makeanswer(i,j: integer; res:char);
var
  k,i1,i2: integer;
  s1,s2: string;
begin

  if i=j then
  begin
    write(s[i]); exit;
  end;
  if (j=i+1) then begin write(s[i],s[i+1]); exit; end;

  for k:=i to j-1 do 
  begin
    s1 := p[i,k]; s2 := p[k+1,j]; 
    for i1 :=1 to length(s1) do
      for i2 := 1 to length(s2) do
        if a[s1[i1]][s2[i2]] = res then
        begin
          if k>i then write('(');
          makeanswer(i,k,s1[i1]);
          if k>i then write(')');
          if j>k+1 then write('(');
          makeanswer(k+1,j,s2[i2]);
          if j>k+1 then write(')');
          exit;
        end;
  end;

end;

procedure find(i,j: integer);
var
  k: integer;
  i1,i2: integer;
  c: char;
  s1,s2: string;
  q: array['a'..chr(ord('a')+NMAX-1)] of byte;
begin
     fillchar(q,sizeof(q),0);
      //перебираем место, после которого поставить последний знак
      for k:=i to j-1 do
      begin
        if p[i,k]='' then find(i,k); s1 := p[i,k];
        if p[k+1,j]='' then find(k+1,j); s2 := p[k+1,j];
        for i1 :=1 to length(s1) do
          for i2 :=1 to length(s2) do
            q[a[s1[i1],s2[i2]]] := 1;
      end;
      p[i,j] := '';
      for c:='a' to chr(ord('a')+n-1) do
        if q[c]=1 then p[i,j] := p[i,j] + c;
    end;

procedure readdata;
var
  c,c1: char;
begin
  readln(n);
  readln(s);
  readln(res);
  for c:='a' to chr(ord('a')+n-1) do
  begin
    for c1:='a' to chr(ord('a')+n-1) do read(a[c,c1]);
    readln;
  end;
end;

procedure answer;
var
  found: boolean;
  i,j: integer;
begin
  for i:=1 to length(s) do for j:=1 to length(s) do p[i][j]:='';
  for i:=1 to length(s) do p[i,i] := s[i];
  find(1,length(s));

  found := false;
  for i:=1 to length(p[1,length(s)]) do
    if p[1,length(s)][i] = res then found := true;

  if not found
  then
    writeln('NO')
  else
  begin
    writeln('YES');
    makeanswer(1,length(s),res);
  end;
end;

begin

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

  readdata;
  answer;

end.

