import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.InputMismatchException;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.OutputStream; OutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.InputMismatchException; InputMismatchException java.util import java.util.Queue; Queue java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

} Main static int INF = 1 << 30; INF 1 << 30 1 30 static long LINF = 1L << 55; LINF 1L << 55 1L 55 static int MOD = 1000000007; MOD 1000000007 static int[] mh4 = { 0, -1, 1, 0 }; mh4 { 0, -1, 1, 0 } 0 -1 1 1 0 static int[] mw4 = { -1, 0, 0, 1 }; mw4 { -1, 0, 0, 1 } -1 1 0 0 1 static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 }; mh8 { -1, -1, -1, 0, 0, 1, 1, 1 } -1 1 -1 1 -1 1 0 0 1 1 1 static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 }; mw8 { -1, 0, 1, -1, 1, -1, 0, 1 } -1 1 0 1 -1 1 1 -1 1 0 1 public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	} main {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, 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) TaskX solver = new TaskX(); solver new TaskX() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		}
	} TaskX public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		} solve {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		} char[] a = in.nextString().toCharArray(); a in.nextString().toCharArray() in.nextString().toCharArray in.nextString() in.nextString in char[] b = in.nextString().toCharArray(); b in.nextString().toCharArray() in.nextString().toCharArray in.nextString() in.nextString in char[] c = in.nextString().toCharArray(); c in.nextString().toCharArray() in.nextString().toCharArray in.nextString() in.nextString in Queue<Character> aq = new ArrayDeque<Character>(); aq new ArrayDeque<Character>() Queue<Character> bq = new ArrayDeque<Character>(); bq new ArrayDeque<Character>() Queue<Character> cq = new ArrayDeque<Character>(); cq new ArrayDeque<Character>() for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
				aq.add(a[i]);
			} {
				aq.add(a[i]);
			} aq.add(a[i]) aq.add aq a[i] a i for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			} int i = 0; int i = 0; i 0 i < b.length i b.length b b.length i++ i++ i {
				bq.add(b[i]);
			} {
				bq.add(b[i]);
			} bq.add(b[i]) bq.add bq b[i] b i for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			} int i = 0; int i = 0; i 0 i < c.length i c.length c c.length i++ i++ i {
				cq.add(c[i]);
			} {
				cq.add(c[i]);
			} cq.add(c[i]) cq.add cq c[i] c i char cur = aq.remove(); cur aq.remove() aq.remove aq while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			} true {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			} if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				} cur == 'a' cur 'a' {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} if (aq.isEmpty()) {
						out.println("A");
						return;
					} aq.isEmpty() aq.isEmpty aq {
						out.println("A");
						return;
					} out.println("A") out.println out "A" return; cur = aq.remove() cur aq.remove() aq.remove aq if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				} cur == 'b' cur 'b' {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} if (bq.isEmpty()) {
						out.println("B");
						return;
					} bq.isEmpty() bq.isEmpty bq {
						out.println("B");
						return;
					} out.println("B") out.println out "B" return; cur = bq.remove() cur bq.remove() bq.remove bq if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				} cur == 'c' cur 'c' {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				} if (cq.isEmpty()) {
						out.println("C");
						return;
					} cq.isEmpty() cq.isEmpty cq {
						out.println("C");
						return;
					} out.println("C") out.println out "C" return; cur = cq.remove() cur cq.remove() cq.remove cq int testNumber testNumber InputReader in in PrintWriter out out static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	} InputReader BufferedReader in; in StringTokenizer tok; tok public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		} nextString {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		} while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			} !tok.hasMoreTokens() tok.hasMoreTokens() tok.hasMoreTokens tok {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			} try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				} catch (IOException e) {
					throw new InputMismatchException();
				} IOException e {
					throw new InputMismatchException();
				} throw new InputMismatchException(); new InputMismatchException() {
					tok = new StringTokenizer(in.readLine(), " ");
				} tok = new StringTokenizer(in.readLine(), " ") tok new StringTokenizer(in.readLine(), " ") return tok.nextToken(); tok.nextToken() tok.nextToken tok public int nextInt() {
			return Integer.parseInt(nextString());
		} nextInt {
			return Integer.parseInt(nextString());
		} return Integer.parseInt(nextString()); Integer.parseInt(nextString()) Integer.parseInt Integer nextString() nextString public long nextLong() {
			return Long.parseLong(nextString());
		} nextLong {
			return Long.parseLong(nextString());
		} return Long.parseLong(nextString()); Long.parseLong(nextString()) Long.parseLong Long nextString() nextString public double nextDouble() {
			return Double.parseDouble(nextString());
		} nextDouble {
			return Double.parseDouble(nextString());
		} return Double.parseDouble(nextString()); Double.parseDouble(nextString()) Double.parseDouble Double nextString() nextString public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		} nextIntArray {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		} int[] res = new int[n]; res new int[n] n for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				res[i] = nextInt();
			} {
				res[i] = nextInt();
			} res[i] = nextInt() res[i] res i nextInt() nextInt return res; res int n n public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		} nextIntArrayDec {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		} int[] res = new int[n]; res new int[n] n for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				res[i] = nextInt() - 1;
			} {
				res[i] = nextInt() - 1;
			} res[i] = nextInt() - 1 res[i] res i nextInt() - 1 nextInt() nextInt 1 return res; res int n n public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		} nextLongArray {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		} long[] res = new long[n]; res new long[n] n for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				res[i] = nextLong();
			} {
				res[i] = nextLong();
			} res[i] = nextLong() res[i] res i nextLong() nextLong return res; res int n n public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		} nextLongArrayDec {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		} long[] res = new long[n]; res new long[n] n for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				res[i] = nextLong() - 1;
			} {
				res[i] = nextLong() - 1;
			} res[i] = nextLong() - 1 res[i] res i nextLong() - 1 nextLong() nextLong 1 return res; res int n n public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		} InputReader {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		} in = new BufferedReader(new InputStreamReader(inputStream)) in new BufferedReader(new InputStreamReader(inputStream)) tok = new StringTokenizer("") tok new StringTokenizer("") InputStream inputStream inputStream public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

} public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.InputMismatchException;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] a = in.nextString().toCharArray();
			char[] b = in.nextString().toCharArray();
			char[] c = in.nextString().toCharArray();

			Queue<Character> aq = new ArrayDeque<Character>();
			Queue<Character> bq = new ArrayDeque<Character>();
			Queue<Character> cq = new ArrayDeque<Character>();

			for (int i = 0; i < a.length; i++) {
				aq.add(a[i]);
			}
			for (int i = 0; i < b.length; i++) {
				bq.add(b[i]);
			}
			for (int i = 0; i < c.length; i++) {
				cq.add(c[i]);
			}

			char cur = aq.remove();
			while (true) {

				if (cur == 'a') {
					if (aq.isEmpty()) {
						out.println("A");
						return;
					}
					cur = aq.remove();
				} else if (cur == 'b') {
					if (bq.isEmpty()) {
						out.println("B");
						return;
					}
					cur = bq.remove();
				} else if (cur == 'c') {
					if (cq.isEmpty()) {
						out.println("C");
						return;
					}
					cur = cq.remove();
				}

			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}
