import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	}

	public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	}

	public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	} main {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String x = in.nextLine(); x in.nextLine() in.nextLine in String y = in.nextLine(); y in.nextLine() in.nextLine in String z = in.nextLine(); z in.nextLine() in.nextLine in String m = "A"; m "A" int flag = 1; flag 1 while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		} 1==1 1 1 {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		} if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			} flag == 1 flag 1 {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} int l = x.length(); l x.length() x.length x if (l == 0) {
					m = "A";
					break;
				} l == 0 l 0 {
					m = "A";
					break;
				} m = "A" m "A" break; char c = x.charAt(0); c x.charAt(0) x.charAt x 0 x = x.substring(1, l) x x.substring(1, l) x.substring x 1 l flag = getFlag(c) flag getFlag(c) getFlag c if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			} flag == 2 flag 2 {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} int l = y.length(); l y.length() y.length y if (l == 0) {
					m = "B";
					break;
				} l == 0 l 0 {
					m = "B";
					break;
				} m = "B" m "B" break; char c = y.charAt(0); c y.charAt(0) y.charAt y 0 y = y.substring(1, y.length()) y y.substring(1, y.length()) y.substring y 1 y.length() y.length y flag = getFlag(c) flag getFlag(c) getFlag c {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			} int l = z.length(); l z.length() z.length z if (l == 0) {
					m = "C";
					break;
				} l == 0 l 0 {
					m = "C";
					break;
				} m = "C" m "C" break; char c = z.charAt(0); c z.charAt(0) z.charAt z 0 z = z.substring(1, z.length()) z z.substring(1, z.length()) z.substring z 1 z.length() z.length z flag = getFlag(c) flag getFlag(c) getFlag c System.out.println(m) System.out.println System.out System System.out m String[] args args public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	} getFlag {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	} if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		} c == 'a' c 'a' {
			return 1;
		} return 1; 1 if (c == 'b') {
			return 2;
		} else {
			return 3;
		} c == 'b' c 'b' {
			return 2;
		} return 2; 2 {
			return 3;
		} return 3; 3 char c c public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	}

	public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	}

	public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	}

	public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	}
}
