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

public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		String[] ss = new String[3];
		int[] beg = new int[3];
		int[] sz = new int[3];

		Arrays.fill(beg, 0);
		for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		}

		int cur = 0;

		while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		}

		char ans = (char)(cur + 'A');
		
		out.println(ans);
	}

	private int getId(char ch) {
		return ch - 'a';
	}
}


class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} import java.lang.*; lang.* java import java.io.*; io.* java import java.util.*; util.* java public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
} Main public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	} main {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	} InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) TaskA solver = new TaskA(); solver new TaskA() solver.solve(in, out) solver.solve solver in out out.close() out.close out String[] args args class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		String[] ss = new String[3];
		int[] beg = new int[3];
		int[] sz = new int[3];

		Arrays.fill(beg, 0);
		for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		}

		int cur = 0;

		while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		}

		char ans = (char)(cur + 'A');
		
		out.println(ans);
	}

	private int getId(char ch) {
		return ch - 'a';
	}
} TaskA public void solve(InputReader in, PrintWriter out) {
		String[] ss = new String[3];
		int[] beg = new int[3];
		int[] sz = new int[3];

		Arrays.fill(beg, 0);
		for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		}

		int cur = 0;

		while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		}

		char ans = (char)(cur + 'A');
		
		out.println(ans);
	} solve {
		String[] ss = new String[3];
		int[] beg = new int[3];
		int[] sz = new int[3];

		Arrays.fill(beg, 0);
		for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		}

		int cur = 0;

		while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		}

		char ans = (char)(cur + 'A');
		
		out.println(ans);
	} String[] ss = new String[3]; ss new String[3] 3 int[] beg = new int[3]; beg new int[3] 3 int[] sz = new int[3]; sz new int[3] 3 Arrays.fill(beg, 0) Arrays.fill Arrays beg 0 for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		} int i=0; int i=0; i 0 i<3 i 3 ++i ++i i {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		} {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		} ss[i] = in.next() ss[i] ss i in.next() in.next in sz[i] = ss[i].length() sz[i] sz i ss[i].length() ss[i].length ss[i] ss i int cur = 0; cur 0 while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		} beg[cur] < sz[cur] beg[cur] beg cur sz[cur] sz cur {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		} int nxt = getId(ss[cur].charAt(beg[cur])); nxt getId(ss[cur].charAt(beg[cur])) getId ss[cur].charAt(beg[cur]) ss[cur].charAt ss[cur] ss cur beg[cur] beg cur beg[cur]++ beg[cur] beg cur cur = nxt cur nxt char ans = (char)(cur + 'A'); ans (char)(cur + 'A') cur 'A' out.println(ans) out.println out ans InputReader in in PrintWriter out out private int getId(char ch) {
		return ch - 'a';
	} getId {
		return ch - 'a';
	} return ch - 'a'; ch - 'a' ch 'a' char ch ch class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	} InputReader {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	} reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	} next {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	} while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		} tokenizer==null || !tokenizer.hasMoreTokens() tokenizer==null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		} try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			} catch (IOException e) {
				throw new RuntimeException(e);
			} IOException e {
				throw new RuntimeException(e);
			} throw new RuntimeException(e); new RuntimeException(e) {
				tokenizer = new StringTokenizer(reader.readLine());
			} tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public int nextInt() {
		return Integer.parseInt(next());
	} nextInt {
		return Integer.parseInt(next());
	} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {
		return Long.parseLong(next());
	} nextLong {
		return Long.parseLong(next());
	} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {
		return Double.parseDouble(next());
	} nextDouble {
		return Double.parseDouble(next());
	} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
} public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
} Main
import java.lang.*;
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		String[] ss = new String[3];
		int[] beg = new int[3];
		int[] sz = new int[3];

		Arrays.fill(beg, 0);
		for (int i=0; i<3; ++i) {
			ss[i] = in.next();
			sz[i] = ss[i].length();
		}

		int cur = 0;

		while (beg[cur] < sz[cur]) {
			int nxt = getId(ss[cur].charAt(beg[cur]));
			beg[cur]++;
			cur = nxt;
		}

		char ans = (char)(cur + 'A');
		
		out.println(ans);
	}

	private int getId(char ch) {
		return ch - 'a';
	}
}


class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

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

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

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