import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
    new Main().run();
  } main {
    new Main().run();
  } new Main().run() new Main().run new Main() String[] args args void run() {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  } run {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  } 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 String[] abc = new String[]{a, b, c}; abc new String[]{a, b, c} int t = 0; t 0 for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    } ; {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    } {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    } String e = abc[t]; e abc[t] abc t if (e.length() == 0) {
        break;
      } e.length() == 0 e.length() e.length e 0 {
        break;
      } break; int next = abc[t].charAt(0) - 'a'; next abc[t].charAt(0) - 'a' abc[t].charAt(0) abc[t].charAt abc[t] abc t 0 'a' abc[t] = abc[t].substring(1) abc[t] abc t abc[t].substring(1) abc[t].substring abc[t] abc t 1 t = next t next System.out.println(new String[]{"A", "B", "C"}[t]) System.out.println System.out System System.out new String[]{"A", "B", "C"}[t] new String[]{"A", "B", "C"} t int ni() {
    return Integer.parseInt(sc.next());
  } ni {
    return Integer.parseInt(sc.next());
  } return Integer.parseInt(sc.next()); Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  } debug {
    System.err.println(Arrays.deepToString(os));
  } System.err.println(Arrays.deepToString(os)) System.err.println System.err System System.err Arrays.deepToString(os) Arrays.deepToString Arrays os Object... os os public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
} public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = new String[]{a, b, c};

    int t = 0;
    for (; ; ) {
      String e = abc[t];
      if (e.length() == 0) {
        break;
      }
      int next = abc[t].charAt(0) - 'a';
      abc[t] = abc[t].substring(1);
      t = next;
    }
    System.out.println(new String[]{"A", "B", "C"}[t]);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}