import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	}
	static char keisan(List a,List b,List c, Iterator ai, Iterator bi, Iterator ci, String next) {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	}
	static char keisan(List a,List b,List c, Iterator ai, Iterator bi, Iterator ci, String next) {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	}
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	} main {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) String a = s.next(); a s.next() s.next s String[] ac = a.split(""); ac a.split("") a.split a "" List<String> Ac = Arrays.asList(ac); Ac Arrays.asList(ac) Arrays.asList Arrays ac String b = s.next(); b s.next() s.next s String[] bc = b.split(""); bc b.split("") b.split b "" List<String> Bc = Arrays.asList(bc); Bc Arrays.asList(bc) Arrays.asList Arrays bc String c = s.next(); c s.next() s.next s String[] cc = c.split(""); cc c.split("") c.split c "" List<String> Cc = Arrays.asList(cc); Cc Arrays.asList(cc) Arrays.asList Arrays cc Iterator ai = Ac.iterator(); ai Ac.iterator() Ac.iterator Ac Iterator bi =Bc.iterator(); bi Bc.iterator() Bc.iterator Bc Iterator ci = Cc.iterator(); ci Cc.iterator() Cc.iterator Cc System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a")) System.out.println System.out System System.out keisan(Ac, Bc, Cc, ai, bi, ci, "a") keisan Ac Bc Cc ai bi ci "a" String[] args args static char keisan(List a,List b,List c, Iterator ai, Iterator bi, Iterator ci, String next) {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	} keisan {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	} String n = null; n null switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		} next case "a": "a" case "a": if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			} ai.hasNext() == false ai.hasNext() ai.hasNext ai false {
				return 'A';
			} return 'A'; 'A' {
				n = (String)ai.next();
			} n = (String)ai.next() n (String)ai.next() ai.next ai break; case "b": "b" case "b": if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			} bi.hasNext() == false bi.hasNext() bi.hasNext bi false {
				return 'B';
			} return 'B'; 'B' {
				n = (String)bi.next();
			} n = (String)bi.next() n (String)bi.next() bi.next bi break; case "c": "c" case "c": if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			} ci.hasNext() == false ci.hasNext() ci.hasNext ci false {
				return 'C';
			} return 'C'; 'C' {
				n = (String)ci.next();
			} n = (String)ci.next() n (String)ci.next() ci.next ci break; return keisan(a,b,c,ai,bi,ci,n); keisan(a,b,c,ai,bi,ci,n) keisan a b c ai bi ci n List a a List b b List c c Iterator ai ai Iterator bi bi Iterator ci ci String next next public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	}
	static char keisan(List a,List b,List c, Iterator ai, Iterator bi, Iterator ci, String next) {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	}
	static char keisan(List a,List b,List c, Iterator ai, Iterator bi, Iterator ci, String next) {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String[] ac = a.split("");
		List<String> Ac = Arrays.asList(ac);
		String b = s.next();
		String[] bc = b.split("");
		List<String> Bc = Arrays.asList(bc);
		String c = s.next();
		String[] cc = c.split("");
		List<String> Cc = Arrays.asList(cc);
		Iterator ai = Ac.iterator();
		Iterator bi =Bc.iterator();
		Iterator ci = Cc.iterator();
		
		System.out.println(keisan(Ac, Bc, Cc, ai, bi, ci, "a"));
	}
	static char keisan(List a,List b,List c, Iterator ai, Iterator bi, Iterator ci, String next) {
		String n = null;
		switch(next) {
		case "a":
			if(ai.hasNext() == false) {
				return 'A';
			} else {
				n = (String)ai.next();
			}
			break;
		case "b":
			if(bi.hasNext() == false) {
				return 'B';
			} else {
				n = (String)bi.next();
			}
			break;
		case "c":
			if(ci.hasNext() == false) {
				return 'C';
			} else {
				n = (String)ci.next();
			}
			break;
		}
		return keisan(a,b,c,ai,bi,ci,n);
	}
}