import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	}

} import java.io.*; io.* java public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	}

} Main public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		} catch(IOException e) {
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} String sa = reader.readLine(); sa reader.readLine() reader.readLine reader String sb = reader.readLine(); sb reader.readLine() reader.readLine reader String sc = reader.readLine(); sc reader.readLine() reader.readLine reader char turn = 'a'; turn 'a' char nextPerson; nextPerson System.out.println(String.valueOf(turn).toUpperCase()) System.out.println System.out System System.out String.valueOf(turn).toUpperCase() String.valueOf(turn).toUpperCase String.valueOf(turn) String.valueOf String turn String[] args args public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	}

} public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	}

} Main
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String sa = reader.readLine();
			String sb = reader.readLine();
			String sc = reader.readLine();
			char turn = 'a';
			char nextPerson;
			outer:while(true) {
				switch (turn) {
				case 'a':
					if (sa.length() > 0) {
						nextPerson = sa.charAt(0);
						turn = nextPerson;
						sa = sa.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'b':
					if (sb.length() > 0) {
						nextPerson = sb.charAt(0);
						turn = nextPerson;
						sb = sb.substring(1);
					} else {
						break outer;
					}
					break;
					
				case 'c':
					if (sc.length() > 0) {
						nextPerson = sc.charAt(0);
						turn = nextPerson;
						sc = sc.substring(1);
					} else {
						break outer;
					}
					break;
				}
			}
			
			System.out.println(String.valueOf(turn).toUpperCase());
			

		} catch(IOException e) {
			System.out.println(e);
		}
	}

}
