import java.util.*;
	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	} import java.util.*; util.* java public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	} Main public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		} main {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] Sa = sc.next().toCharArray(); Sa sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] Sb = sc.next().toCharArray(); Sb sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] Sc = sc.next().toCharArray(); Sc sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int a = Sa.length; a Sa.length Sa Sa.length int b = Sb.length; b Sb.length Sb Sb.length int c = Sc.length; c Sc.length Sc Sc.length char card = 'a'; card 'a' while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			} true {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			} if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				} card=='a' card 'a' {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				} if(a==0) {
						System.out.println("A");
						return;
					} a==0 a 0 {
						System.out.println("A");
						return;
					} System.out.println("A") System.out.println System.out System System.out "A" return; card = Sa[Sa.length-a] card Sa[Sa.length-a] Sa Sa.length-a Sa.length Sa Sa.length a a-- a if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				} card=='b' card 'b' {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				} if(b==0) {
						System.out.println("B");
						return;
					} b==0 b 0 {
						System.out.println("B");
						return;
					} System.out.println("B") System.out.println System.out System System.out "B" return; card = Sb[Sb.length-b] card Sb[Sb.length-b] Sb Sb.length-b Sb.length Sb Sb.length b b-- b if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				} card=='c' card 'c' {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				} if(c==0) {
						System.out.println("C");
						return;
					} c==0 c 0 {
						System.out.println("C");
						return;
					} System.out.println("C") System.out.println System.out System System.out "C" return; card = Sc[Sc.length-c] card Sc[Sc.length-c] Sc Sc.length-c Sc.length Sc Sc.length c c-- c String[] args args public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	} public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	} Main
import java.util.*;
	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	}