import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  }
} import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  } main {
    Scanner scanner = new Scanner(System.in);

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Queue<Character>[] queues = new Queue[3]; queues new Queue[3] 3 for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    } int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    } {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    } queues[i] = new LinkedList<>() queues[i] queues i new LinkedList<>() for (char ch : scanner.next().toCharArray()) queues[i].add(ch); char ch scanner.next().toCharArray() scanner.next().toCharArray scanner.next() scanner.next scanner queues[i].add(ch); queues[i].add(ch) queues[i].add queues[i] queues i ch int c = 0; c 0 while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    } true {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    } if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      } queues[c].isEmpty() queues[c].isEmpty queues[c] queues c {
        System.out.println((char)('A' + c));
        return;
      } System.out.println((char)('A' + c)) System.out.println System.out System System.out (char)('A' + c) 'A' c return; char ch = queues[c].remove(); ch queues[c].remove() queues[c].remove queues[c] queues c c = ch - 'a' c ch - 'a' ch 'a' String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  }
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

    Queue<Character>[] queues = new Queue[3];
    for (int i = 0; i < 3; i++) {
      queues[i] = new LinkedList<>();
      for (char ch : scanner.next().toCharArray()) queues[i].add(ch);
    }

    int c = 0;
    while (true) {
      if (queues[c].isEmpty()) {
        System.out.println((char)('A' + c));
        return;
      }
      char ch = queues[c].remove();
      c = ch - 'a';
    }
  }
}
