import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  }
} Main public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  } main {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  } final Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) final String[] s = new String[3]; s new String[3] 3 s[0] = scanner.nextLine() s[0] s 0 scanner.nextLine() scanner.nextLine scanner s[1] = scanner.nextLine() s[1] s 1 scanner.nextLine() scanner.nextLine scanner s[2] = scanner.nextLine() s[2] s 2 scanner.nextLine() scanner.nextLine scanner final int[] idx = new int[3]; idx new int[3] 3 int nextTurn = 0; nextTurn 0 while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    } idx[nextTurn] < s[nextTurn].length() idx[nextTurn] idx nextTurn s[nextTurn].length() s[nextTurn].length s[nextTurn] s nextTurn {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    } final char c = s[nextTurn].charAt(idx[nextTurn]); c s[nextTurn].charAt(idx[nextTurn]) s[nextTurn].charAt s[nextTurn] s nextTurn idx[nextTurn] idx nextTurn idx[nextTurn]++ idx[nextTurn] idx nextTurn nextTurn = c - 'a' nextTurn c - 'a' c 'a' System.out.println(Character.toUpperCase((char) (nextTurn + 'a'))) System.out.println System.out System System.out Character.toUpperCase((char) (nextTurn + 'a')) Character.toUpperCase Character (char) (nextTurn + 'a') nextTurn 'a' String[] args args public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  }
} public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final String[] s = new String[3];
    s[0] = scanner.nextLine();
    s[1] = scanner.nextLine();
    s[2] = scanner.nextLine();

    final int[] idx = new int[3];
    int nextTurn = 0;
    while (idx[nextTurn] < s[nextTurn].length()) {
      final char c = s[nextTurn].charAt(idx[nextTurn]);
      idx[nextTurn]++;

      nextTurn = c - 'a';
    }

    System.out.println(Character.toUpperCase((char) (nextTurn + 'a')));
  }
}