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();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  }
} 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();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  }
} 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();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  } main {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  } 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 String[] abc = { a, b, c }; abc { a, b, c } a b c int turn = 0; turn 0 while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    } true {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    } if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      } abc[turn].length() == 0 abc[turn].length() abc[turn].length abc[turn] abc turn 0 {
        System.out.println((char) (turn + 'A'));
        return;
      } System.out.println((char) (turn + 'A')) System.out.println System.out System System.out (char) (turn + 'A') turn 'A' return; char next = abc[turn].charAt(0); next abc[turn].charAt(0) abc[turn].charAt abc[turn] abc turn 0 abc[turn] = abc[turn].substring(1, abc[turn].length()) abc[turn] abc turn abc[turn].substring(1, abc[turn].length()) abc[turn].substring abc[turn] abc turn 1 abc[turn].length() abc[turn].length abc[turn] abc turn turn = next - 'a' turn next - 'a' next 'a' 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();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  }
} 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();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  }
} 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();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  }
}