import java.io.*;
import java.util.*;
import java.math.*;

public class chess_ab implements Runnable {

	private void solve() throws IOException {
		char[][] tab = new char[8][8];
		for (int i = 0; i < 8; ++i) {
			tab[7 - i] = in.readLine().toCharArray(); 
		}
		int n = in.nextInt();
		for (int i = 0; i < n; ++i) {
			String s = in.readLine();
			int x1 = s.charAt(0) - 'a';
			int y1 = s.charAt(1) - '1';
			int x2 = s.charAt(2) - 'a';
			int y2 = s.charAt(3) - '1';
			out.print(tab[y2][x2] = tab[y1][x1]);			
		}
	}

	final int INF = (int) 1e9;

	SimpleScanner in;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new SimpleScanner(new FileReader("chess.in"));
			out = new PrintWriter("chess.out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new chess_ab()).start();
	}

	class SimpleScanner extends BufferedReader {

		private StringTokenizer st;
		private boolean eof;

		public SimpleScanner(Reader a) {
			super(a);
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(readLine());
				} catch (Exception e) {
					eof = true;
					return "";
				}
			}
			return st.nextToken();
		}

		boolean seekEof() {
			String s = next();
			if ("".equals(s) && eof)
				return true;
			st = new StringTokenizer(s + " " + st.toString());
			return false;
		}

		private String cnv(String s) {
			if (s.length() == 0)
				return "0";
			return s;
		}

		int nextInt() {
			return Integer.parseInt(cnv(next()));
		}

		double nextDouble() {
			return Double.parseDouble(cnv(next()));
		}

		long nextLong() {
			return Long.parseLong(cnv(next()));
		}
	}
}