import java.io.*;
import java.util.*;
class Main{
public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	char[] a = in.next().toCharArray();
  	char[] b = in.next().toCharArray();
  	char[] c = in.next().toCharArray();
  	int i1=0,i2=0,i3=0;
  	char next='a';
  	char winner;
  	while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    }
  	
}
} import java.io.*; io.* java import java.util.*; util.* java class Main{
public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	char[] a = in.next().toCharArray();
  	char[] b = in.next().toCharArray();
  	char[] c = in.next().toCharArray();
  	int i1=0,i2=0,i3=0;
  	char next='a';
  	char winner;
  	while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    }
  	
}
} Main public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	char[] a = in.next().toCharArray();
  	char[] b = in.next().toCharArray();
  	char[] c = in.next().toCharArray();
  	int i1=0,i2=0,i3=0;
  	char next='a';
  	char winner;
  	while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    }
  	
} main {
	Scanner in = new Scanner(System.in);
	char[] a = in.next().toCharArray();
  	char[] b = in.next().toCharArray();
  	char[] c = in.next().toCharArray();
  	int i1=0,i2=0,i3=0;
  	char next='a';
  	char winner;
  	while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    }
  	
} Scanner in = new Scanner(System.in); in new Scanner(System.in) char[] a = in.next().toCharArray(); a in.next().toCharArray() in.next().toCharArray in.next() in.next in char[] b = in.next().toCharArray(); b in.next().toCharArray() in.next().toCharArray in.next() in.next in char[] c = in.next().toCharArray(); c in.next().toCharArray() in.next().toCharArray in.next() in.next in int i1=0 i1 0 i2=0 i2 0 i3=0; i3 0 char next='a'; next 'a' char winner; winner while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    } true {
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    } if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        } next=='a' next 'a' {
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        } if(i1==a.length){
            	System.out.println("A");
              	break;
            } i1==a.length i1 a.length a a.length {
            	System.out.println("A");
              	break;
            } System.out.println("A") System.out.println System.out System System.out "A" break; next = a[i1++] next a[i1++] a i1++ i1 if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        } next=='b' next 'b' {
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        } if(i2==b.length){
            	System.out.println("B");
              	break;
            } i2==b.length i2 b.length b b.length {
            	System.out.println("B");
              	break;
            } System.out.println("B") System.out.println System.out System System.out "B" break; next = b[i2++] next b[i2++] b i2++ i2 {
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        } if(i3==c.length){
            	System.out.println("C");
              	break;
            } i3==c.length i3 c.length c c.length {
            	System.out.println("C");
              	break;
            } System.out.println("C") System.out.println System.out System System.out "C" break; next = c[i3++] next c[i3++] c i3++ i3 String args[] args
import java.io.*;
import java.util.*;
class Main{
public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	char[] a = in.next().toCharArray();
  	char[] b = in.next().toCharArray();
  	char[] c = in.next().toCharArray();
  	int i1=0,i2=0,i3=0;
  	char next='a';
  	char winner;
  	while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    }
  	
}
}