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();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  }
} 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();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  }
} 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();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  } 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 int numA = 0; numA 0 int numB = 0; numB 0 int numC = 0; numC 0 char present = 'a'; present 'a' String ans = ""; ans "" while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    } (numA <= a.length()) && (numB <= b.length()) && (numC <= c.length()) (numA <= a.length()) && (numB <= b.length()) && (numC <= c.length()) (numA <= a.length()) numA a.length() a.length a (numB <= b.length()) numB b.length() b.length b (numC <= c.length()) numC c.length() c.length c {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    } if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      } present == 'a' present 'a' {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } if(numA == a.length()) {
          ans = "A";
          break;
        } numA == a.length() numA a.length() a.length a {
          ans = "A";
          break;
        } ans = "A" ans "A" break; present = a.charAt(numA) present a.charAt(numA) a.charAt a numA numA++ numA if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      } present == 'b' present 'b' {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } if(numB == b.length()) {
            ans = "B";
            break;
          } numB == b.length() numB b.length() b.length b {
            ans = "B";
            break;
          } ans = "B" ans "B" break; present = b.charAt(numB) present b.charAt(numB) b.charAt b numB numB++ numB {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      } if(numC == c.length()) {
            ans = "C";
            break;
          } numC == c.length() numC c.length() c.length c {
            ans = "C";
            break;
          } ans = "C" ans "C" break; present = c.charAt(numC) present c.charAt(numC) c.charAt c numC numC++ numC 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);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  }
} 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();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  }
} 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();
    int numA = 0;
    int numB = 0;
    int numC = 0;
    char present = 'a';
    String ans = "";
    while((numA <= a.length()) && (numB <= b.length()) && (numC <= c.length())) {
      if(present == 'a') {
        if(numA == a.length()) {
          ans = "A";
          break;
        }
        present = a.charAt(numA);
        numA++;
      } else if(present == 'b') {
          if(numB == b.length()) {
            ans = "B";
            break;
          }
          present = b.charAt(numB);
          numB++;
      } else {
          if(numC == c.length()) {
            ans = "C";
            break;
          }
          present = c.charAt(numC);
          numC++;
      }
    }
    System.out.println(ans);
  }
}