import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 }
} import java.util.*; util.* java public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 }
} Main public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 } main {
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] a = sc.next().toCharArray(); a sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] b = sc.next().toCharArray(); b sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int an = a.length; an a.length a a.length int bn = b.length; bn b.length b b.length int cn = c.length; cn c.length c c.length int acount=0; acount 0 int bcount=0; bcount 0 int ccount=0; ccount 0 char tmp = 'a'; tmp 'a' char ans = 'A'; ans 'A' for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   } int i=0; int i=0; i 0 i<=an+bn+cn i an+bn+cn an+bn+cn an bn cn i++ i++ i {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   } {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   } if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     } i==0 i 0 {
       tmp = a[acount];
       acount++;
     } tmp = a[acount] tmp a[acount] a acount acount++ acount {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     } if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       } tmp=='a' tmp 'a' {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       } if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         } acount==an acount an {
           ans='A';
           break;
         } ans='A' ans 'A' break; {
         tmp = a[acount];
         acount++;
         } tmp = a[acount] tmp a[acount] a acount acount++ acount if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       } tmp =='b' tmp 'b' {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       } if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         } bcount==bn bcount bn {
           ans='B';
           break;
         } ans='B' ans 'B' break; {
         tmp = b[bcount];
         bcount++;
         } tmp = b[bcount] tmp b[bcount] b bcount bcount++ bcount {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       } if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         } ccount==cn ccount cn {
           ans='C';
           break;
         } ans='C' ans 'C' break; {
         tmp = c[ccount];
         ccount++;
         } tmp = c[ccount] tmp c[ccount] c ccount ccount++ ccount System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 }
} public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 }
} Main
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] a = sc.next().toCharArray();
   char[] b = sc.next().toCharArray();
   char[] c = sc.next().toCharArray();
   
   int an = a.length;
   int bn = b.length;
   int cn = c.length;
   
   int acount=0;
   int bcount=0;
   int ccount=0;
 
   char tmp = 'a';
   char ans = 'A';
   for(int i=0;i<=an+bn+cn;i++) 
   {
     if(i==0)
     {
       tmp = a[acount];
       acount++;
     }
     else
     {
       if(tmp=='a')
       {
         if(acount==an)
         {
           ans='A';
           break;
         }
         else
         {
         tmp = a[acount];
         acount++;
         }
       }
       else if(tmp =='b')
       {
         if(bcount==bn)
         {
           ans='B';
           break;
         }
         else
         {
         tmp = b[bcount];
         bcount++;
         }
       }
       else
       {
         if(ccount==cn)
         {
           ans='C';
           break;
         }
         else
         {
         tmp = c[ccount];
         ccount++;
         }
       }
     }
   }
   System.out.println(ans);
 }
}