import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
} Main InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	} _main {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	} Scanner sc = new Scanner(in); sc new Scanner(in) String[] X = new String[3]; X new String[3] 3 X[0] = sc.next() X[0] X 0 sc.next() sc.next sc X[1] = sc.next() X[1] X 1 sc.next() sc.next sc X[2] = sc.next() X[2] X 2 sc.next() sc.next sc sc.close() sc.close sc int turn = 0; turn 0 int[] idx = new int[3]; idx new int[3] 3 char ans; ans while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		} true {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		} if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			} idx[turn] >= X[turn].length() idx[turn] idx turn X[turn].length() X[turn].length X[turn] X turn {
				ans = (char) ('A' + turn);
				break;
			} ans = (char) ('A' + turn) ans (char) ('A' + turn) 'A' turn break; char c = X[turn].charAt(idx[turn]++); c X[turn].charAt(idx[turn]++) X[turn].charAt X[turn] X turn idx[turn]++ idx[turn] idx turn turn = (char) (c - 'a') turn (char) (c - 'a') c 'a' out.println(ans) out.println out ans String[] args args public static void main(String[] args) {
		new Main()._main(args);
	} main {
		new Main()._main(args);
	} new Main()._main(args) new Main()._main new Main() args String[] args args public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
} public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String[] X = new String[3];
		X[0] = sc.next();
		X[1] = sc.next();
		X[2] = sc.next();

		sc.close();

		int turn = 0;
		int[] idx = new int[3];

		char ans;
		while (true) {
			if (idx[turn] >= X[turn].length()) {
				ans = (char) ('A' + turn);
				break;
			}

			char c = X[turn].charAt(idx[turn]++);
			turn = (char) (c - 'a');
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}
