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 A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	}
} 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 A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	}
} Main public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String A = br.readLine(); A br.readLine() br.readLine br String B = br.readLine(); B br.readLine() br.readLine br String C = br.readLine(); C br.readLine() br.readLine br int Ai = 0; Ai 0 int Bi = 0; Bi 0 int Ci = 0; Ci 0 int Al = A.length(); Al A.length() A.length A int Bl = B.length(); Bl B.length() B.length B int Cl = C.length(); Cl C.length() C.length C char turn = A.charAt(Ai++); turn A.charAt(Ai++) A.charAt A Ai++ Ai while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		} true {
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		} if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			} turn == 'a' turn 'a' {
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} if(Ai == Al){
					System.out.println('A');
					break;
				} Ai == Al Ai Al {
					System.out.println('A');
					break;
				} System.out.println('A') System.out.println System.out System System.out 'A' break; turn = A.charAt(Ai++) turn A.charAt(Ai++) A.charAt A Ai++ Ai if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			} turn == 'b' turn 'b' {
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} if(Bi == Bl){
					System.out.println('B');
					break;
				} Bi == Bl Bi Bl {
					System.out.println('B');
					break;
				} System.out.println('B') System.out.println System.out System System.out 'B' break; turn = B.charAt(Bi++) turn B.charAt(Bi++) B.charAt B Bi++ Bi if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			} turn == 'c' turn 'c' {
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			} if(Ci == Cl){
					System.out.println('C');
					break;
				} Ci == Cl Ci Cl {
					System.out.println('C');
					break;
				} System.out.println('C') System.out.println System.out System System.out 'C' break; turn = C.charAt(Ci++) turn C.charAt(Ci++) C.charAt C Ci++ Ci String[] args args public class Main {
	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	}
} public class Main {
	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	}
} 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 A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	}
}
