import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  }  
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  }  
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  } main {
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.next(); A sc.next() sc.next sc String B = sc.next(); B sc.next() sc.next sc String C = sc.next(); C sc.next() sc.next sc char[] a = A.toCharArray(); a A.toCharArray() A.toCharArray A char[] b = B.toCharArray(); b B.toCharArray() B.toCharArray B char[] c = C.toCharArray(); c C.toCharArray() C.toCharArray C int aa = 0; aa 0 int bb = 0; bb 0 int cc = 0; cc 0 char next = a[0]; next a[0] a 0 while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    } true {
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    } if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      } next == 'a' next 'a' {
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      } aa++ aa if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        } aa == a.length aa a.length a a.length {
          System.out.println("A");
          return;
        } System.out.println("A") System.out.println System.out System System.out "A" return; {
          next = a[aa];
        } next = a[aa] next a[aa] a aa if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      } next == 'b' next 'b' {
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      } if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       } bb == 0 bb 0 {
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        } if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          } bb == b.length bb b.length b b.length {
            System.out.println("B");
            return;
          } System.out.println("B") System.out.println System.out System System.out "B" return; {
            next = b[0];
            bb++;
          } next = b[0] next b[0] b 0 bb++ bb {
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       } if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        } bb == b.length bb b.length b b.length {
             System.out.println("B");
             return;
          } System.out.println("B") System.out.println System.out System System.out "B" return; {
            next = b[bb];
            bb++;
        } next = b[bb] next b[bb] b bb bb++ bb if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      } next == 'c' next 'c' {
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      } if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       } cc == 0 cc 0 {
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        } if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          } cc == c.length cc c.length c c.length {
            System.out.println("C");
            return;
          } System.out.println("C") System.out.println System.out System System.out "C" return; {
            next = c[0];
            cc++;
          } next = c[0] next c[0] c 0 cc++ cc {
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       } if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        } cc == c.length cc c.length c c.length {
             System.out.println("C");
             return;
          } System.out.println("C") System.out.println System.out System System.out "C" return; {
            next = c[cc];
            cc++;
        } next = c[cc] next c[cc] c cc cc++ cc String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  }  
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  }  
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  }  
}