import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	}
} Main public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String A = br.readLine(); A br.readLine() br.readLine br String B = br.readLine(); B br.readLine() br.readLine br String C = br.readLine(); C br.readLine() br.readLine br int i=0 i 0 j=0 j 0 k=0; k 0 char turn = 'a'; turn 'a' while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		} i<=A.length() && j<=B.length() && k<=C.length() i<=A.length() && j<=B.length() && k<=C.length() i<=A.length() i A.length() A.length A j<=B.length() j B.length() B.length B k<=C.length() k C.length() C.length C {
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		} if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			} turn == 'a' turn 'a' {
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			} if(i == A.length())
				{
					System.out.println('A');
					return;
				} i == A.length() i A.length() A.length A {
					System.out.println('A');
					return;
				} System.out.println('A') System.out.println System.out System System.out 'A' return; turn = A.charAt(i++) turn A.charAt(i++) A.charAt A i++ i if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			} turn == 'b' turn 'b' {
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			} if(j == B.length())
				{
					System.out.println('B');
					return;
				} j == B.length() j B.length() B.length B {
					System.out.println('B');
					return;
				} System.out.println('B') System.out.println System.out System System.out 'B' return; turn = B.charAt(j++) turn B.charAt(j++) B.charAt B j++ j {
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			} if(k == C.length())
				{
					System.out.println('C');
					return;
				} k == C.length() k C.length() C.length C {
					System.out.println('C');
					return;
				} System.out.println('C') System.out.println System.out System System.out 'C' return; turn = C.charAt(k++) turn C.charAt(k++) C.charAt C k++ k String[] args args public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	}
} public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int i=0,j=0,k=0;
		char turn = 'a';
		while(i<=A.length() && j<=B.length() && k<=C.length())
		{
			if(turn == 'a')
			{
				if(i == A.length())
				{
					System.out.println('A');
					return;
				}
				turn = A.charAt(i++);
			}
				
			else if(turn == 'b')
			{
				if(j == B.length())
				{
					System.out.println('B');
					return;
				}
				turn = B.charAt(j++);
			}
				
			else
			{
				if(k == C.length())
				{
					System.out.println('C');
					return;
				}
				turn = C.charAt(k++);
			}
		}
	}
}
