import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	}
} Main public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	} main {
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) String s1 = scn.next(); s1 scn.next() scn.next scn String s2 = scn.next(); s2 scn.next() scn.next scn String s3 = scn.next(); s3 scn.next() scn.next scn String[] a = s1.split(""); a s1.split("") s1.split s1 "" String[] b = s2.split(""); b s2.split("") s2.split s2 "" String[] c = s3.split(""); c s3.split("") s3.split s3 "" int aa = s1.length(); aa s1.length() s1.length s1 int bb = s2.length(); bb s2.length() s2.length s2 int cc = s3.length(); cc s3.length() s3.length s3 String next = "a"; next "a" while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        } true {
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        } if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          } next.equals("a") next.equals next "a" {
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          } if(aa==0){
            	System.out.println("A");
				return;
            } aa==0 aa 0 {
            	System.out.println("A");
				return;
            } System.out.println("A") System.out.println System.out System System.out "A" return; next = a[s1.length()-aa] next a[s1.length()-aa] a s1.length()-aa s1.length() s1.length s1 aa aa-- aa if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          } next.equals("b") next.equals next "b" {
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          } if(bb==0){
            	System.out.println("B");
				return;
            } bb==0 bb 0 {
            	System.out.println("B");
				return;
            } System.out.println("B") System.out.println System.out System System.out "B" return; next = b[s2.length()-bb] next b[s2.length()-bb] b s2.length()-bb s2.length() s2.length s2 bb bb-- bb if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          } next.equals("c") next.equals next "c" {
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          } if(cc==0){
            	System.out.println("C");
				return;
            } cc==0 cc 0 {
            	System.out.println("C");
				return;
            } System.out.println("C") System.out.println System.out System System.out "C" return; next = c[s3.length()-cc] next c[s3.length()-cc] c s3.length()-cc s3.length() s3.length s3 cc cc-- cc String[] args args public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	}
} public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	}
}
