var
  i, n, x1, x2, y1, y2 : integer;
  tab : array[1..8] of string;
  s : string;
begin
  reset(input, 'chess.in');
  rewrite(output, 'chess.out');
  for i := 1 to 8 do begin
    readln(tab[9 - i]);
  end;
  readln(n);
  for i := 1 to n do begin
    readln(s);
    y1 := ord(s[1]) - ord('a') + 1;
    x1 := ord(s[2]) - ord('1') + 1;
    y2 := ord(s[3]) - ord('a') + 1;
    x2 := ord(s[4]) - ord('1') + 1;
    write(tab[x1][y1]);
    tab[x2][y2] := tab[x1][y1];
    tab[x1][y1] := '.';
  end;
end.