/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
  
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    }
} import java.io.*; io.* java import java.util.*; util.* java import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    }
} Main public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    } main {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    } FastReader ob = new FastReader(); ob new FastReader() String s1 = ob.next() s1 ob.next() ob.next ob s2=ob.next() s2 ob.next() ob.next ob s3=ob.next(); s3 ob.next() ob.next ob int i=0 i 0 j=0 j 0 k=0; k 0 int n1=s1.length() n1 s1.length() s1.length s1 n2=s2.length() n2 s2.length() s2.length s2 n3=s3.length(); n3 s3.length() s3.length s3 char check=s1.charAt(i); check s1.charAt(i) s1.charAt s1 i i++ i while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       } true {
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       } if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           } check=='a' check 'a' {
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           } if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               } i<n1 i n1 {
                   check=s1.charAt(i);
                   i++;
               } check=s1.charAt(i) check s1.charAt(i) s1.charAt s1 i i++ i {
                   System.out.println("A");
                   break;
               } System.out.println("A") System.out.println System.out System System.out "A" break; if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           } check=='b' check 'b' {
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           } if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               } j<n2 j n2 {
                   check=s2.charAt(j);
                   j++;
               } check=s2.charAt(j) check s2.charAt(j) s2.charAt s2 j j++ j {
                   System.out.println("B");
                   break;
               } System.out.println("B") System.out.println System.out System System.out "B" break; if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           } check=='c' check 'c' {
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           } if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               } k<n3 k n3 {
                   check=s3.charAt(k);
                   k++;
               } check=s3.charAt(k) check s3.charAt(k) s3.charAt s3 k k++ k {
                   System.out.println("C");
                   break;
               } System.out.println("C") System.out.println System.out System System.out "C" break; String[] args args static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } FastReader { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } br = new BufferedReader(new
                     InputStreamReader(System.in)) br new BufferedReader(new
                     InputStreamReader(System.in)) String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } next { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } IOException  e { 
                    e.printStackTrace(); 
                } e.printStackTrace() e.printStackTrace e { 
                    st = new StringTokenizer(br.readLine()); 
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } nextInt { 
            return Integer.parseInt(next()); 
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() 
        { 
            return Long.parseLong(next()); 
        } nextLong { 
            return Long.parseLong(next()); 
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } nextDouble { 
            return Double.parseDouble(next()); 
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } nextLine { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } String str = ""; str "" try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } catch (IOException e) 
            { 
                e.printStackTrace(); 
            } IOException e { 
                e.printStackTrace(); 
            } e.printStackTrace() e.printStackTrace e { 
                str = br.readLine(); 
            } str = br.readLine() str br.readLine() br.readLine br return str; str public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    }
} public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    }
} Main
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
  
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       String s1 = ob.next(),s2=ob.next(),s3=ob.next();
       int i=0,j=0,k=0;
       int n1=s1.length(),n2=s2.length(),n3=s3.length();
       char check=s1.charAt(i);
       i++;
       while(true){
           if(check=='a'){
               if(i<n1){
                   check=s1.charAt(i);
                   i++;
               }
               else{
                   System.out.println("A");
                   break;
               }
           }
           else if(check=='b'){
               if(j<n2){
                   check=s2.charAt(j);
                   j++;
               }
               else{
                   System.out.println("B");
                   break;
               }
           }
           else if(check=='c'){
               if(k<n3){
                   check=s3.charAt(k);
                   k++;
               }
               else{
                   System.out.println("C");
                   break;
               }
           }
       }
        
    }
}