
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		int cntA = 0;
		int cntB = -1;
		int cntC = -1;
		
		char next = a.charAt(0);
		String ans = "";
		outside: do {
			
			switch (next) {
			case 'a':
				cntA++;
				if (cntA == a.length()) {
					ans = "A";
					break outside;
				}
				next = a.charAt(cntA);
				break;
			case 'b':
				cntB++;
				if (cntB == b.length()) {
					ans = "B";
					break outside;
				}
				next = b.charAt(cntB);
				break;
			case 'c':
				cntC++;
				if (cntC == c.length()) {
					ans = "C";
					break outside;
				}
				next = c.charAt(cntC);
				break;
			
			}
		} while(true);

		System.out.println(ans);
		
	}
} import java.util.*; util.* java class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		int cntA = 0;
		int cntB = -1;
		int cntC = -1;
		
		char next = a.charAt(0);
		String ans = "";
		outside: do {
			
			switch (next) {
			case 'a':
				cntA++;
				if (cntA == a.length()) {
					ans = "A";
					break outside;
				}
				next = a.charAt(cntA);
				break;
			case 'b':
				cntB++;
				if (cntB == b.length()) {
					ans = "B";
					break outside;
				}
				next = b.charAt(cntB);
				break;
			case 'c':
				cntC++;
				if (cntC == c.length()) {
					ans = "C";
					break outside;
				}
				next = c.charAt(cntC);
				break;
			
			}
		} while(true);

		System.out.println(ans);
		
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		int cntA = 0;
		int cntB = -1;
		int cntC = -1;
		
		char next = a.charAt(0);
		String ans = "";
		outside: do {
			
			switch (next) {
			case 'a':
				cntA++;
				if (cntA == a.length()) {
					ans = "A";
					break outside;
				}
				next = a.charAt(cntA);
				break;
			case 'b':
				cntB++;
				if (cntB == b.length()) {
					ans = "B";
					break outside;
				}
				next = b.charAt(cntB);
				break;
			case 'c':
				cntC++;
				if (cntC == c.length()) {
					ans = "C";
					break outside;
				}
				next = c.charAt(cntC);
				break;
			
			}
		} while(true);

		System.out.println(ans);
		
	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		int cntA = 0;
		int cntB = -1;
		int cntC = -1;
		
		char next = a.charAt(0);
		String ans = "";
		outside: do {
			
			switch (next) {
			case 'a':
				cntA++;
				if (cntA == a.length()) {
					ans = "A";
					break outside;
				}
				next = a.charAt(cntA);
				break;
			case 'b':
				cntB++;
				if (cntB == b.length()) {
					ans = "B";
					break outside;
				}
				next = b.charAt(cntB);
				break;
			case 'c':
				cntC++;
				if (cntC == c.length()) {
					ans = "C";
					break outside;
				}
				next = c.charAt(cntC);
				break;
			
			}
		} while(true);

		System.out.println(ans);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc int cntA = 0; cntA 0 int cntB = -1; cntB -1 1 int cntC = -1; cntC -1 1 char next = a.charAt(0); next a.charAt(0) a.charAt a 0 String ans = ""; ans "" System.out.println(ans) System.out.println System.out System System.out ans String args[] args

import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		int cntA = 0;
		int cntB = -1;
		int cntC = -1;
		
		char next = a.charAt(0);
		String ans = "";
		outside: do {
			
			switch (next) {
			case 'a':
				cntA++;
				if (cntA == a.length()) {
					ans = "A";
					break outside;
				}
				next = a.charAt(cntA);
				break;
			case 'b':
				cntB++;
				if (cntB == b.length()) {
					ans = "B";
					break outside;
				}
				next = b.charAt(cntB);
				break;
			case 'c':
				cntC++;
				if (cntC == c.length()) {
					ans = "C";
					break outside;
				}
				next = c.charAt(cntC);
				break;
			
			}
		} while(true);

		System.out.println(ans);
		
	}
}