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

public class chess_aa {
	public static void main(String[] args) {
		new chess_aa().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

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

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean u, String message) {
		if (!u) {
			throw new Error("Assertion failed!!! " + message);
		}
	}

	int inBounds(int x, int l, int r, String name) {
		myAssert(l <= x && x <= r, name + " is not in bounds: " + x
				+ " not in [" + l + ", " + r + "]");
		return x;
	}

	String FNAME = "chess";

	private void solve() throws IOException {
		char[][] a = new char[8][];
		for (int i = a.length - 1; i >= 0; i--) {
			a[i] = nextToken().toCharArray();
		}
		int n = inBounds(nextInt(), 0, 100000, "n");
		for (int i = 0; i < n; i++) {
			char[] s = nextToken().toCharArray();
			int y1 = s[0] - 'a';
			int x1 = s[1] - '1';
			int y2 = s[2] - 'a';
			int x2 = s[3] - '1';
			out.print(a[x1][y1]);
			a[x2][y2] = a[x1][y1];
			a[x1][y1] = '.';
		}
	}
}
