import java.util.*;
// . >
class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		
		String a = in.nextLine(), b = in.nextLine(), c = in.nextLine();
		int ind1 = 0, ind2 = 0, ind3 = 0;
		int res = a.length() + b.length() + c.length();
		char t = 'a';
		for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		}
			
		System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C");
		
	}

} import java.util.*; util.* java class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		
		String a = in.nextLine(), b = in.nextLine(), c = in.nextLine();
		int ind1 = 0, ind2 = 0, ind3 = 0;
		int res = a.length() + b.length() + c.length();
		char t = 'a';
		for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		}
			
		System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C");
		
	}

} Main public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		
		String a = in.nextLine(), b = in.nextLine(), c = in.nextLine();
		int ind1 = 0, ind2 = 0, ind3 = 0;
		int res = a.length() + b.length() + c.length();
		char t = 'a';
		for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		}
			
		System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C");
		
	} main {
		Scanner in = new Scanner(System.in);
		
		String a = in.nextLine(), b = in.nextLine(), c = in.nextLine();
		int ind1 = 0, ind2 = 0, ind3 = 0;
		int res = a.length() + b.length() + c.length();
		char t = 'a';
		for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		}
			
		System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C");
		
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String a = in.nextLine() a in.nextLine() in.nextLine in b = in.nextLine() b in.nextLine() in.nextLine in c = in.nextLine(); c in.nextLine() in.nextLine in int ind1 = 0 ind1 0 ind2 = 0 ind2 0 ind3 = 0; ind3 0 int res = a.length() + b.length() + c.length(); res a.length() + b.length() + c.length() a.length() + b.length() + c.length() a.length() a.length a b.length() b.length b c.length() c.length c char t = 'a'; t 'a' for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		} int i = 0; int i = 0; i 0 i < res i res i++ i++ i {
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		} {
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		} if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			} t == 'a' && ind1 < a.length() t == 'a' t 'a' ind1 < a.length() ind1 a.length() a.length a {
				t = a.charAt(ind1);
				ind1++;
			} t = a.charAt(ind1) t a.charAt(ind1) a.charAt a ind1 ind1++ ind1 if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			} t == 'b' && ind2 < b.length() t == 'b' t 'b' ind2 < b.length() ind2 b.length() b.length b {
				t = b.charAt(ind2);
				ind2++;
			} t = b.charAt(ind2) t b.charAt(ind2) b.charAt b ind2 ind2++ ind2 if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			} t == 'c' && ind3 < c.length() t == 'c' t 'c' ind3 < c.length() ind3 c.length() c.length c {
				t = c.charAt(ind3);
				ind3++;
			} t = c.charAt(ind3) t c.charAt(ind3) c.charAt c ind3 ind3++ ind3 {
				break;
			} break; System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C") System.out.println System.out System System.out (t == 'a') ? "A" : (t == 'b') ? "B" : "C" (t == 'a') t 'a' "A" (t == 'b') ? "B" : "C" (t == 'b') t 'b' "B" "C" String args[] args
import java.util.*;
// . >
class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		
		String a = in.nextLine(), b = in.nextLine(), c = in.nextLine();
		int ind1 = 0, ind2 = 0, ind3 = 0;
		int res = a.length() + b.length() + c.length();
		char t = 'a';
		for(int i = 0; i < res; i++){
			if(t == 'a' && ind1 < a.length()){
				t = a.charAt(ind1);
				ind1++;
			}else if(t == 'b' && ind2 < b.length()){
				t = b.charAt(ind2);
				ind2++;
			}else if(t == 'c' && ind3 < c.length()){
				t = c.charAt(ind3);
				ind3++;
			}else{
				break;
			}
		}
			
		System.out.println((t == 'a') ? "A" : (t == 'b') ? "B" : "C");
		
	}

}
