import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String sa = sc.next();
    String sb = sc.next();
    String sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  }

  static String solve(char next, String a, String b, String c) {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  }
} import java.util.Scanner; Scanner 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 sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  }

  static String solve(char next, String a, String b, String c) {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String sa = sc.next();
    String sb = sc.next();
    String sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  } main {
    Scanner sc = new Scanner(System.in);
    String sa = sc.next();
    String sb = sc.next();
    String sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  } 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 sh = sc.next(); sh sc.next() sc.next sc System.out.println(solve('a', sa, sb, sh)) System.out.println System.out System System.out solve('a', sa, sb, sh) solve 'a' sa sb sh String[] args args static String solve(char next, String a, String b, String c) {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  } solve {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  } if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    } next == 'a' && a.isEmpty() next == 'a' next 'a' a.isEmpty() a.isEmpty a {
      return "A";
    } return "A"; "A" if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    } next == 'b' && b.isEmpty() next == 'b' next 'b' b.isEmpty() b.isEmpty b {
      return "B";
    } return "B"; "B" if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    } next == 'c' && c.isEmpty() next == 'c' next 'c' c.isEmpty() c.isEmpty c {
      return "C";
    } return "C"; "C" {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    } if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      } next == 'a' next 'a' {
        return solve(a.charAt(0), a.substring(1), b, c);
      } return solve(a.charAt(0), a.substring(1), b, c); solve(a.charAt(0), a.substring(1), b, c) solve a.charAt(0) a.charAt a 0 a.substring(1) a.substring a 1 b c if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      } next == 'b' next 'b' {
        return solve(b.charAt(0), a, b.substring(1), c);
      } return solve(b.charAt(0), a, b.substring(1), c); solve(b.charAt(0), a, b.substring(1), c) solve b.charAt(0) b.charAt b 0 a b.substring(1) b.substring b 1 c if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      } next == 'c' next 'c' {
        return solve(c.charAt(0), a, b, c.substring(1));
      } return solve(c.charAt(0), a, b, c.substring(1)); solve(c.charAt(0), a, b, c.substring(1)) solve c.charAt(0) c.charAt c 0 a b c.substring(1) c.substring c 1 {
        return "0";
      } return "0"; "0" char next next String a a String b b String c c public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String sa = sc.next();
    String sb = sc.next();
    String sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  }

  static String solve(char next, String a, String b, String c) {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String sa = sc.next();
    String sb = sc.next();
    String sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  }

  static String solve(char next, String a, String b, String c) {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String sa = sc.next();
    String sb = sc.next();
    String sh = sc.next();

    System.out.println(solve('a', sa, sb, sh));
  }

  static String solve(char next, String a, String b, String c) {
    if (next == 'a' && a.isEmpty()) {
      return "A";
    } else if (next == 'b' && b.isEmpty()) {
      return "B";
    } else if (next == 'c' && c.isEmpty()) {
      return "C";
    } else {
      if (next == 'a') {
        return solve(a.charAt(0), a.substring(1), b, c);
      } else if (next == 'b') {
        return solve(b.charAt(0), a, b.substring(1), c);
      } else if (next == 'c') {
        return solve(c.charAt(0), a, b, c.substring(1));
      } else {
        return "0";
      }
    }
  }
}
