import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	}
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	} main {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int i = 0; i 0 String sa = scan.nextLine(); sa scan.nextLine() scan.nextLine scan List<String> a_list = new ArrayList<String>(); a_list new ArrayList<String>() for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		} i = 0; i = 0 i 0 i < sa.length() i sa.length() sa.length sa i++ i++ i {
			a_list.add(sa.charAt(i) + "");
		} {
			a_list.add(sa.charAt(i) + "");
		} a_list.add(sa.charAt(i) + "") a_list.add a_list sa.charAt(i) + "" sa.charAt(i) sa.charAt sa i "" String sb = scan.nextLine(); sb scan.nextLine() scan.nextLine scan List<String> b_list = new ArrayList<String>(); b_list new ArrayList<String>() for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		} i = 0; i = 0 i 0 i < sb.length() i sb.length() sb.length sb i++ i++ i {
			b_list.add(sb.charAt(i) + "");
		} {
			b_list.add(sb.charAt(i) + "");
		} b_list.add(sb.charAt(i) + "") b_list.add b_list sb.charAt(i) + "" sb.charAt(i) sb.charAt sb i "" String sc = scan.nextLine(); sc scan.nextLine() scan.nextLine scan List<String> c_list = new ArrayList<String>(); c_list new ArrayList<String>() for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		} i = 0; i = 0 i 0 i < sc.length() i sc.length() sc.length sc i++ i++ i {
			c_list.add(sc.charAt(i) + "");
		} {
			c_list.add(sc.charAt(i) + "");
		} c_list.add(sc.charAt(i) + "") c_list.add c_list sc.charAt(i) + "" sc.charAt(i) sc.charAt sc i "" String card = a_list.get(0); card a_list.get(0) a_list.get a_list 0 a_list.remove(0) a_list.remove a_list 0 String winner = ""; winner "" if(a_list.size() == 0) {
			winner = "A";
		} a_list.size() == 0 a_list.size() a_list.size a_list 0 {
			winner = "A";
		} winner = "A" winner "A" for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		} ; {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		} {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		} if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			} card.equals("a") card.equals card "a" {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} if(a_list.size() == 0) {
					winner = "A";
					break;
				} a_list.size() == 0 a_list.size() a_list.size a_list 0 {
					winner = "A";
					break;
				} winner = "A" winner "A" break; card = a_list.get(0) card a_list.get(0) a_list.get a_list 0 a_list.remove(0) a_list.remove a_list 0 if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			} card.equals("b") card.equals card "b" {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} if(b_list.size() == 0) {
					winner = "B";
					break;
				} b_list.size() == 0 b_list.size() b_list.size b_list 0 {
					winner = "B";
					break;
				} winner = "B" winner "B" break; card = b_list.get(0) card b_list.get(0) b_list.get b_list 0 b_list.remove(0) b_list.remove b_list 0 if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			} card.equals("c") card.equals card "c" {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			} if(c_list.size() == 0) {
					winner = "C";
					break;
				} c_list.size() == 0 c_list.size() c_list.size c_list 0 {
					winner = "C";
					break;
				} winner = "C" winner "C" break; card = c_list.get(0) card c_list.get(0) c_list.get c_list 0 c_list.remove(0) c_list.remove c_list 0 System.out.println(winner) System.out.println System.out System System.out winner String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	}
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int i = 0;
		String sa = scan.nextLine();
		List<String> a_list = new ArrayList<String>();
		for(i = 0; i < sa.length(); i++) {
			a_list.add(sa.charAt(i) + "");
		}
		String sb = scan.nextLine();
		List<String> b_list = new ArrayList<String>();
		for(i = 0; i < sb.length(); i++) {
			b_list.add(sb.charAt(i) + "");
		}
		String sc = scan.nextLine();
		List<String> c_list = new ArrayList<String>();
		for(i = 0; i < sc.length(); i++) {
			c_list.add(sc.charAt(i) + "");
		}
		
		String card = a_list.get(0);
		a_list.remove(0);
		String winner = "";
		if(a_list.size() == 0) {
			winner = "A";
		}
		
		for(; ;) {
			if(card.equals("a")) {
				if(a_list.size() == 0) {
					winner = "A";
					break;
				}
				card = a_list.get(0);
				a_list.remove(0);
				
			} else if(card.equals("b")) {
				if(b_list.size() == 0) {
					winner = "B";
					break;
				}
				card = b_list.get(0);
				b_list.remove(0);
				
			} else if(card.equals("c")) {
				if(c_list.size() == 0) {
					winner = "C";
					break;
				}
				card = c_list.get(0);
				c_list.remove(0);
				
			}
		}
		
		System.out.println(winner);
	}
}