import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	}

} Main public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	} main {
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder SA = new StringBuilder(); SA new StringBuilder() StringBuilder SB = new StringBuilder(); SB new StringBuilder() StringBuilder SC = new StringBuilder(); SC new StringBuilder() String A = scan.next(); A scan.next() scan.next scan String B = scan.next(); B scan.next() scan.next scan String C = scan.next(); C scan.next() scan.next scan SA.append(A) SA.append SA A SB.append(B) SB.append SB B SC.append(C) SC.append SC C String turn = "A"; turn "A" int end = 0; end 0 String Winner= "o"; Winner "o" do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0); end==0 end 0 {
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		} switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			} turn case "A": "A" case "A": if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				} SA.toString().equals("") SA.toString().equals SA.toString() SA.toString SA "" {
					Winner = "A";
					end=1;
					
				} Winner = "A" Winner "A" end=1 end 1 if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				} SA.toString().substring(0, 1).equals("a") SA.toString().substring(0, 1).equals SA.toString().substring(0, 1) SA.toString().substring SA.toString() SA.toString SA 0 1 "a" {//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				} turn = "A" turn "A" SA.delete(0, 1) SA.delete SA 0 1 if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				} SA.toString().substring(0, 1).equals("b") SA.toString().substring(0, 1).equals SA.toString().substring(0, 1) SA.toString().substring SA.toString() SA.toString SA 0 1 "b" {
					turn = "B";

					SA.delete(0, 1);

				} turn = "B" turn "B" SA.delete(0, 1) SA.delete SA 0 1 if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				} SA.toString().substring(0, 1).equals("c") SA.toString().substring(0, 1).equals SA.toString().substring(0, 1) SA.toString().substring SA.toString() SA.toString SA 0 1 "c" {
					turn = "C";

					SA.delete(0, 1);

				} turn = "C" turn "C" SA.delete(0, 1) SA.delete SA 0 1 break; case "B": "B" case "B": if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				} SB.toString().equals("") SB.toString().equals SB.toString() SB.toString SB "" {
					Winner = "B";
					end=1;
					
				} Winner = "B" Winner "B" end=1 end 1 if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				} SB.toString().substring(0, 1).equals("a") SB.toString().substring(0, 1).equals SB.toString().substring(0, 1) SB.toString().substring SB.toString() SB.toString SB 0 1 "a" {
					turn = "A";
					SB.delete(0, 1);
					
				} turn = "A" turn "A" SB.delete(0, 1) SB.delete SB 0 1 if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				} SB.toString().substring(0, 1).equals("b") SB.toString().substring(0, 1).equals SB.toString().substring(0, 1) SB.toString().substring SB.toString() SB.toString SB 0 1 "b" {
					turn = "B";

					SB.delete(0, 1);

				} turn = "B" turn "B" SB.delete(0, 1) SB.delete SB 0 1 if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				} SB.toString().substring(0, 1).equals("c") SB.toString().substring(0, 1).equals SB.toString().substring(0, 1) SB.toString().substring SB.toString() SB.toString SB 0 1 "c" {
					turn = "C";

					SB.delete(0, 1);

				} turn = "C" turn "C" SB.delete(0, 1) SB.delete SB 0 1 break; case "C": "C" case "C": if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				} SC.toString().equals("") SC.toString().equals SC.toString() SC.toString SC "" {
					Winner = "C";
					end=1;
					
				} Winner = "C" Winner "C" end=1 end 1 if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				} SC.toString().substring(0, 1).equals("a") SC.toString().substring(0, 1).equals SC.toString().substring(0, 1) SC.toString().substring SC.toString() SC.toString SC 0 1 "a" {
					turn = "A";
					SC.delete(0, 1);
					
				} turn = "A" turn "A" SC.delete(0, 1) SC.delete SC 0 1 if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				} SC.toString().substring(0, 1).equals("b") SC.toString().substring(0, 1).equals SC.toString().substring(0, 1) SC.toString().substring SC.toString() SC.toString SC 0 1 "b" {
					turn = "B";

					SC.delete(0, 1);

				} turn = "B" turn "B" SC.delete(0, 1) SC.delete SC 0 1 if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				} SC.toString().substring(0, 1).equals("c") SC.toString().substring(0, 1).equals SC.toString().substring(0, 1) SC.toString().substring SC.toString() SC.toString SC 0 1 "c" {
					turn = "C";

					SC.delete(0, 1);

				} turn = "C" turn "C" SC.delete(0, 1) SC.delete SC 0 1 break; System.out.println(Winner) System.out.println System.out System System.out Winner String[]args args public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	}

} public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		StringBuilder SA = new StringBuilder();
		StringBuilder SB = new StringBuilder();
		StringBuilder SC = new StringBuilder();
		
		String A = scan.next();
		String B = scan.next();
		String C = scan.next();
		
		
		SA.append(A);
		SB.append(B);
		SC.append(C);
		
		String turn = "A";
		int end = 0;
		String Winner= "o";
		
		
		do{
			switch(turn){
			case "A":
				
				if(SA.toString().equals("")){
					Winner = "A";
					end=1;
					
				}else
				if(SA.toString().substring(0, 1).equals("a")){//文字列一番目を切り取りそれがaか判別
					turn = "A";
					SA.delete(0, 1);
					
				}else if(SA.toString().substring(0, 1).equals("b")){
					turn = "B";

					SA.delete(0, 1);

				}else if(SA.toString().substring(0, 1).equals("c")){
					turn = "C";

					SA.delete(0, 1);

				}
				break;
				
			case "B":
				if(SB.toString().equals("")){
					Winner = "B";
					end=1;
					
				}else
				if(SB.toString().substring(0, 1).equals("a")){
					turn = "A";
					SB.delete(0, 1);
					
				}else if(SB.toString().substring(0, 1).equals("b")){
					turn = "B";

					SB.delete(0, 1);

				}else if(SB.toString().substring(0, 1).equals("c")){
					turn = "C";

					SB.delete(0, 1);

				}
				break;
			case "C":
				if(SC.toString().equals("")){
					Winner = "C";
					end=1;
					
				}else
				if(SC.toString().substring(0, 1).equals("a")){
					turn = "A";
					SC.delete(0, 1);
					
				}else if(SC.toString().substring(0, 1).equals("b")){
					turn = "B";

					SC.delete(0, 1);

				}else if(SC.toString().substring(0, 1).equals("c")){
					turn = "C";

					SC.delete(0, 1);

				}
				break;
			
			}
			
			
			
			
		}while(end==0);
		
		
		
		
		
		System.out.println(Winner);
		
		
		
		
		
		
	}

}