import java.util.*;
import static java.lang.System.*;
import java.io.*;
public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	}
}
 import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; import java.io.*; io.* java public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder a = new StringBuilder(sc.next()); a new StringBuilder(sc.next()) StringBuilder b = new StringBuilder(sc.next()); b new StringBuilder(sc.next()) StringBuilder c = new StringBuilder(sc.next()); c new StringBuilder(sc.next()) char turn = 'A'; turn 'A' while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		} true {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		} StringBuilder sb = new StringBuilder(); sb new StringBuilder() if( turn == 'A')  sb = a; turn == 'A' turn 'A' sb = a sb a if (turn == 'B') sb = b; turn == 'B' turn 'B' sb = b sb b if(turn == 'C') sb = c; turn == 'C' turn 'C' sb = c sb c if (sb.length() == 0) break; sb.length() == 0 sb.length() sb.length sb 0 break; char ch = sb.charAt(0); ch sb.charAt(0) sb.charAt sb 0 ch -= 32 ch 32 turn = ch turn ch sb.deleteCharAt(0) sb.deleteCharAt sb 0 out.println(turn) out.println out turn String[] args args public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	}
} public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	}
} Main
import java.util.*;
import static java.lang.System.*;
import java.io.*;
public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(sc.next());
		char turn = 'A';
		while(true) {
			StringBuilder sb = new StringBuilder();
			if( turn == 'A')  sb = a;
			if (turn == 'B') sb = b;
			if(turn == 'C') sb = c;
			if (sb.length() == 0) break;
			char ch = sb.charAt(0);
			ch -= 32;
			turn = ch;
			sb.deleteCharAt(0);
		}
		out.println(turn);
	}
}

