import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String AA = sc.next();
		String BB = sc.next();
		String CC = sc.next();
		
		
		StringBuilder A = new StringBuilder(AA);
		StringBuilder B = new StringBuilder(BB);
		StringBuilder C = new StringBuilder(CC);

		
		String player = "A";
		while(true){
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		}
		
	}
} import java.util.Scanner; Scanner java.util class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String AA = sc.next();
		String BB = sc.next();
		String CC = sc.next();
		
		
		StringBuilder A = new StringBuilder(AA);
		StringBuilder B = new StringBuilder(BB);
		StringBuilder C = new StringBuilder(CC);

		
		String player = "A";
		while(true){
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		}
		
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String AA = sc.next();
		String BB = sc.next();
		String CC = sc.next();
		
		
		StringBuilder A = new StringBuilder(AA);
		StringBuilder B = new StringBuilder(BB);
		StringBuilder C = new StringBuilder(CC);

		
		String player = "A";
		while(true){
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		}
		
	} main {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String AA = sc.next();
		String BB = sc.next();
		String CC = sc.next();
		
		
		StringBuilder A = new StringBuilder(AA);
		StringBuilder B = new StringBuilder(BB);
		StringBuilder C = new StringBuilder(CC);

		
		String player = "A";
		while(true){
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		}
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String AA = sc.next(); AA sc.next() sc.next sc String BB = sc.next(); BB sc.next() sc.next sc String CC = sc.next(); CC sc.next() sc.next sc StringBuilder A = new StringBuilder(AA); A new StringBuilder(AA) StringBuilder B = new StringBuilder(BB); B new StringBuilder(BB) StringBuilder C = new StringBuilder(CC); C new StringBuilder(CC) String player = "A"; player "A" while(true){
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		} true {
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		} if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			} player == "A" player "A" {
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			} if(A.length() == 0){
					System.out.println("A");
					return;
				} A.length() == 0 A.length() A.length A 0 {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				} A.charAt(0) == 'a' A.charAt(0) A.charAt A 0 'a' {
					player = "A";
					A = A.deleteCharAt(0);
				} player = "A" player "A" A = A.deleteCharAt(0) A A.deleteCharAt(0) A.deleteCharAt A 0 if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				} A.charAt(0) == 'b' A.charAt(0) A.charAt A 0 'b' {
					player = "B";
					A = A.deleteCharAt(0);
				} player = "B" player "B" A = A.deleteCharAt(0) A A.deleteCharAt(0) A.deleteCharAt A 0 if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				} A.charAt(0) == 'c' A.charAt(0) A.charAt A 0 'c' {
					player = "C";
					A = A.deleteCharAt(0);
				} player = "C" player "C" A = A.deleteCharAt(0) A A.deleteCharAt(0) A.deleteCharAt A 0 if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			} player == "B" player "B" {
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			} if(B.length() == 0){
					System.out.println("B");
					return;
				} B.length() == 0 B.length() B.length B 0 {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				} B.charAt(0) == 'a' B.charAt(0) B.charAt B 0 'a' {
					player = "A";
					B = B.deleteCharAt(0);
				} player = "A" player "A" B = B.deleteCharAt(0) B B.deleteCharAt(0) B.deleteCharAt B 0 if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				} B.charAt(0) == 'b' B.charAt(0) B.charAt B 0 'b' {
					player = "B";
					B = B.deleteCharAt(0);
				} player = "B" player "B" B = B.deleteCharAt(0) B B.deleteCharAt(0) B.deleteCharAt B 0 if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				} B.charAt(0) == 'c' B.charAt(0) B.charAt B 0 'c' {
					player = "C";
					B = B.deleteCharAt(0);
				} player = "C" player "C" B = B.deleteCharAt(0) B B.deleteCharAt(0) B.deleteCharAt B 0 if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			} player == "C" player "C" {
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			} if(C.length() == 0){
					System.out.println("C");
					return;
				} C.length() == 0 C.length() C.length C 0 {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				} C.charAt(0) == 'a' C.charAt(0) C.charAt C 0 'a' {
					player = "A";
					C = C.deleteCharAt(0);
				} player = "A" player "A" C = C.deleteCharAt(0) C C.deleteCharAt(0) C.deleteCharAt C 0 if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				} C.charAt(0) == 'b' C.charAt(0) C.charAt C 0 'b' {
					player = "B";
					C = C.deleteCharAt(0);
				} player = "B" player "B" C = C.deleteCharAt(0) C C.deleteCharAt(0) C.deleteCharAt C 0 if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				} C.charAt(0) == 'c' C.charAt(0) C.charAt C 0 'c' {
					player = "C";
					C = C.deleteCharAt(0);
				} player = "C" player "C" C = C.deleteCharAt(0) C C.deleteCharAt(0) C.deleteCharAt C 0 String[] args args
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String AA = sc.next();
		String BB = sc.next();
		String CC = sc.next();
		
		
		StringBuilder A = new StringBuilder(AA);
		StringBuilder B = new StringBuilder(BB);
		StringBuilder C = new StringBuilder(CC);

		
		String player = "A";
		while(true){
			//System.out.println(player);
			
			if(player == "A"){
				if(A.length() == 0){
					System.out.println("A");
					return;
				}
				
				if(A.charAt(0) == 'a'){
					player = "A";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'b'){
					player = "B";
					A = A.deleteCharAt(0);
				}else if(A.charAt(0) == 'c'){
					player = "C";
					A = A.deleteCharAt(0);
				}
				
			}else if(player == "B"){
				if(B.length() == 0){
					System.out.println("B");
					return;
				}
				
				if(B.charAt(0) == 'a'){
					player = "A";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'b'){
					player = "B";
					B = B.deleteCharAt(0);
				}else if(B.charAt(0) == 'c'){
					player = "C";
					B = B.deleteCharAt(0);
				}
				
				
			}else if(player == "C"){
				if(C.length() == 0){
					System.out.println("C");
					return;
				}
				
				if(C.charAt(0) == 'a'){
					player = "A";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'b'){
					player = "B";
					C = C.deleteCharAt(0);
				}else if(C.charAt(0) == 'c'){
					player = "C";
					C = C.deleteCharAt(0);
				}
				
				
			}
			
		}
		
	}
}