import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String lineA = br.readLine(); lineA br.readLine() br.readLine br String lineB = br.readLine(); lineB br.readLine() br.readLine br String lineC = br.readLine(); lineC br.readLine() br.readLine br int indexA = 0; indexA 0 int indexB = 0; indexB 0 int indexC = 0; indexC 0 char ch = lineA.charAt(indexA++); ch lineA.charAt(indexA++) lineA.charAt lineA indexA++ indexA while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		} true {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		} if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			} ch == 'a' ch 'a' {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			} if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				} indexA == lineA.length() indexA lineA.length() lineA.length lineA {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; ch = lineA.charAt(indexA++) ch lineA.charAt(indexA++) lineA.charAt lineA indexA++ indexA if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			} ch == 'b' ch 'b' {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			} if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				} indexB == lineB.length() indexB lineB.length() lineB.length lineB {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; ch = lineB.charAt(indexB++) ch lineB.charAt(indexB++) lineB.charAt lineB indexB++ indexB if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			} ch == 'c' ch 'c' {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			} if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				} indexC == lineC.length() indexC lineC.length() lineC.length lineC {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; ch = lineC.charAt(indexC++) ch lineC.charAt(indexC++) lineC.charAt lineC indexC++ indexC String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	}
} public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	}
}
