import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String saa = sc.next() saa sc.next() sc.next sc sbb = sc.next() sbb sc.next() sc.next sc scc = sc.next(); scc sc.next() sc.next sc int na = saa.length() na saa.length() saa.length saa nb = sbb.length() nb sbb.length() sbb.length sbb nc = scc.length(); nc scc.length() scc.length scc int a = 0 a 0 b = 0 b 0 c = 0 c 0 turn = 0; turn 0 while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		} true {
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		} if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			} turn == 0 turn 0 {
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			} if(a == na){
					System.out.println('A');
					break;
				} a == na a na {
					System.out.println('A');
					break;
				} System.out.println('A') System.out.println System.out System System.out 'A' break; turn = saa.charAt(a) - 'a' turn saa.charAt(a) - 'a' saa.charAt(a) saa.charAt saa a 'a' a++ a if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			} turn == 1 turn 1 {
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			} if(b == nb){
					System.out.println('B');
					break;
				} b == nb b nb {
					System.out.println('B');
					break;
				} System.out.println('B') System.out.println System.out System System.out 'B' break; turn = sbb.charAt(b) - 'a' turn sbb.charAt(b) - 'a' sbb.charAt(b) sbb.charAt sbb b 'a' b++ b {
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			} if(c == nc){
					System.out.println('C');
					break;
				} c == nc c nc {
					System.out.println('C');
					break;
				} System.out.println('C') System.out.println System.out System System.out 'C' break; turn = scc.charAt(c) - 'a' turn scc.charAt(c) - 'a' scc.charAt(c) scc.charAt scc c 'a' c++ c sc.close() sc.close sc String[] args args public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	}
} public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	}
} Main
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	}
}
