import java.util.*;
public 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();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(ans));
	}
} import java.util.*; util.* java public 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();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(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();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(ans));
	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(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 char ans = 'a'; ans 'a' int inta = 0; inta 0 int intb = 0; intb 0 int intc = 0; intc 0 while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		} ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length() ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length() ans == 'a' && inta < a.length() ans == 'a' ans 'a' inta < a.length() inta a.length() a.length a ans == 'b' && intb < b.length() ans == 'b' ans 'b' intb < b.length() intb b.length() b.length b ans == 'c' && intc < c.length() ans == 'c' ans 'c' intc < c.length() intc c.length() c.length c {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		} switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			} ans case 'a': 'a' case 'a': ans = a.charAt(inta) ans a.charAt(inta) a.charAt a inta inta++ inta break; case 'b': 'b' case 'b': ans = b.charAt(intb) ans b.charAt(intb) b.charAt b intb intb++ intb break; case 'c': 'c' case 'c': ans = c.charAt(intc) ans c.charAt(intc) c.charAt c intc intc++ intc break; System.out.println(Character.toUpperCase(ans)) System.out.println System.out System System.out Character.toUpperCase(ans) Character.toUpperCase Character ans String args[] args public 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();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(ans));
	}
} public 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();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(ans));
	}
} Main
import java.util.*;
public 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();
		char ans = 'a';
		
		int inta = 0;
		int intb = 0;
		int intc = 0;
		
		while(ans == 'a' && inta < a.length() || ans == 'b' && intb < b.length() || ans == 'c' && intc < c.length()) {
			switch(ans) {
				case 'a':
					ans = a.charAt(inta);
					inta++;
					break;
				case 'b':
					ans = b.charAt(intb);
					intb++;
					break;
				case 'c':
					ans = c.charAt(intc);
					intc++;
					break;
 			}
		}
		System.out.println(Character.toUpperCase(ans));
	}
}
