import java.util.*;

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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    
    String result = "";
    int a = 0;
    int b = 0;
    int c = 0;
    char next = 'a';
    while(true){
      if(next == 'a'){
        if(a == SA.length()){
          result = "A";
          break;
        }else{
          next = SA.charAt(a);
          a++;
        }
      }else if(next == 'b'){
        if(b == SB.length()){
          result = "B";
          break;
        }else{
          next = SB.charAt(b);
          b++;
        }
      }else{
        if(c == SC.length()){
          result = "C";
          break;
        }else{
          next = SC.charAt(c);
          c++;
        }
      }
    }
    System.out.println(result);
  }
}