import java.util.*;
	public class Main {

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

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			char[] c = sc.next().toCharArray();
			
			int an= a.length;
			int bn = b.length;
			int cn = c.length;
			char turn = 'a';
			
			while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			}		
		}
	} Main public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			char[] c = sc.next().toCharArray();
			
			int an= a.length;
			int bn = b.length;
			int cn = c.length;
			char turn = 'a';
			
			while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			}		
		} main {
			Scanner sc = new Scanner(System.in);
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			char[] c = sc.next().toCharArray();
			
			int an= a.length;
			int bn = b.length;
			int cn = c.length;
			char turn = 'a';
			
			while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			}		
		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] a = sc.next().toCharArray(); a sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] b = sc.next().toCharArray(); b sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int an= a.length; an a.length a a.length int bn = b.length; bn b.length b b.length int cn = c.length; cn c.length c c.length char turn = 'a'; turn 'a' while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			} true {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			} if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				} turn=='a' turn 'a' {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				} if(an==0) {
						System.out.println("A");
						return;
					} an==0 an 0 {
						System.out.println("A");
						return;
					} System.out.println("A") System.out.println System.out System System.out "A" return; turn = a[a.length-an] turn a[a.length-an] a a.length-an a.length a a.length an an-- an if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				} turn=='b' turn 'b' {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				} if(bn==0) {
						System.out.println("B");
						return;
					} bn==0 bn 0 {
						System.out.println("B");
						return;
					} System.out.println("B") System.out.println System.out System System.out "B" return; turn = b[b.length-bn] turn b[b.length-bn] b b.length-bn b.length b b.length bn bn-- bn if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				} turn=='c' turn 'c' {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				} if(cn==0) {
						System.out.println("C");
						return;
					} cn==0 cn 0 {
						System.out.println("C");
						return;
					} System.out.println("C") System.out.println System.out System System.out "C" return; turn = c[c.length-cn] turn c[c.length-cn] c c.length-cn c.length c c.length cn cn-- cn String[] args args public class Main {

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			char[] c = sc.next().toCharArray();
			
			int an= a.length;
			int bn = b.length;
			int cn = c.length;
			char turn = 'a';
			
			while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			}		
		}
	} public class Main {

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

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			char[] c = sc.next().toCharArray();
			
			int an= a.length;
			int bn = b.length;
			int cn = c.length;
			char turn = 'a';
			
			while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}	
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			}		
		}
	}