import java.util.*;
public class Main{
	static String CardGame(String[] s){
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	}
} import java.util.*; util.* java public class Main{
	static String CardGame(String[] s){
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	}
} Main static String CardGame(String[] s){
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	} CardGame {
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	} int len = 0; len 0 for(int i=0; i<3; i++){
			len += s[i].length();
		} int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
			len += s[i].length();
		} {
			len += s[i].length();
		} len += s[i].length() len s[i].length() s[i].length s[i] s i int turn = 0; turn 0 int next = 0; next 0 for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		} int i=0; int i=0; i 0 i<len i len i++ i++ i {
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		} {
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		} if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			} s[turn].length()==0 s[turn].length() s[turn].length s[turn] s turn 0 {
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			} if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				} turn==0 turn 0 {
					return "A";
				} return "A"; "A" if(turn==1){
					return "B";
				}
				else {
					return "C";
				} turn==1 turn 1 {
					return "B";
				} return "B"; "B" {
					return "C";
				} return "C"; "C" {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			} if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				} s[turn].charAt(0)=='a' s[turn].charAt(0) s[turn].charAt s[turn] s turn 0 'a' {
					next=0;
				} next=0 next 0 if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				} s[turn].charAt(0)=='b' s[turn].charAt(0) s[turn].charAt s[turn] s turn 0 'b' {
					next=1;
				} next=1 next 1 {
					next=2;
				} next=2 next 2 s[turn] = s[turn].substring(1) s[turn] s turn s[turn].substring(1) s[turn].substring s[turn] s turn 1 turn = next turn next return ""; "" String[] s s public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	} main {
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] S = new String[3]; S new String[3] 3 for(int i=0; i<3; i++){
			S[i] = sc.next();
		} int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
			S[i] = sc.next();
		} {
			S[i] = sc.next();
		} S[i] = sc.next() S[i] S i sc.next() sc.next sc System.out.println(CardGame(S)) System.out.println System.out System System.out CardGame(S) CardGame S String[] args args public class Main{
	static String CardGame(String[] s){
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	}
} public class Main{
	static String CardGame(String[] s){
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	}
} Main
import java.util.*;
public class Main{
	static String CardGame(String[] s){
		int len = 0;
		for(int i=0; i<3; i++){
			len += s[i].length();
		}
		int turn = 0;
		int next = 0;
		for(int i=0; i<len; i++){
			if(s[turn].length()==0){
				if(turn==0){
					return "A";
				}
				else if(turn==1){
					return "B";
				}
				else {
					return "C";
				}
			}

			else {
				if(s[turn].charAt(0)=='a'){
					next=0;
				}
				else if(s[turn].charAt(0)=='b'){
					next=1;
				}
				else {
					next=2;
				}
				s[turn] = s[turn].substring(1);
				turn = next;
			}
		}
		return "";
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] S = new String[3];
		for(int i=0; i<3; i++){
			S[i] = sc.next();
		}
		System.out.println(CardGame(S));
	}
}