import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	}
} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	} main {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) char[] c1 = in.next().toCharArray(); c1 in.next().toCharArray() in.next().toCharArray in.next() in.next in char[] c2 = in.next().toCharArray(); c2 in.next().toCharArray() in.next().toCharArray in.next() in.next in char[] c3 = in.next().toCharArray(); c3 in.next().toCharArray() in.next().toCharArray in.next() in.next in char turn = 'a'; turn 'a' int ai = 0; ai 0 int bi = 0; bi 0 int ci = 0; ci 0 while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		} true {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		} if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			} turn == 'a' turn 'a' {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			} if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				} ai == c1.length ai c1.length c1 c1.length {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; {
					turn = c1[ai];
					ai++;
				} turn = c1[ai] turn c1[ai] c1 ai ai++ ai if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			} turn == 'b' turn 'b' {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			} if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				} bi == c2.length bi c2.length c2 c2.length {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; {
					turn = c2[bi];
					bi++;
				} turn = c2[bi] turn c2[bi] c2 bi bi++ bi if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			} turn == 'c' turn 'c' {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			} if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				} ci == c3.length ci c3.length c3 c3.length {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; {
					turn = c3[ci];
					ci++;
				} turn = c3[ci] turn c3[ci] c3 ci ci++ ci String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	}
} Main
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c1 = in.next().toCharArray();
		char[] c2 = in.next().toCharArray();
		char[] c3 = in.next().toCharArray();
		
		char turn = 'a';
		int ai = 0;
		int bi = 0;
		int ci = 0;

		while (true) {
			if (turn == 'a') {
				if (ai == c1.length) {
					System.out.println("A");
					break;
				} else {
					turn = c1[ai];
					ai++;
				}
			}
			if (turn == 'b') {
				if (bi == c2.length) {
					System.out.println("B");
					break;
				} else {
					turn = c2[bi];
					bi++;
				}
			}
			if (turn == 'c') {
				if (ci == c3.length) {
					System.out.println("C");
					break;
				} else {
					turn = c3[ci];
					ci++;
				}
			}
		}
	}
}