import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  List<Deque<Integer>> a;
  int ans;
  int turn = 0;
  boolean win = false;
  static final int A = 0;
  static final int B = 1;
  static final int C = 2;
  static final int N = 3;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  }

  private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  }
  
  void solve() {
    while (!win) play();
  }

  void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  }

  void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  List<Deque<Integer>> a;
  int ans;
  int turn = 0;
  boolean win = false;
  static final int A = 0;
  static final int B = 1;
  static final int C = 2;
  static final int N = 3;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  }

  private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  }
  
  void solve() {
    while (!win) play();
  }

  void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  }

  void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  }
} Main List<Deque<Integer>> a; a int ans; ans int turn = 0; turn 0 boolean win = false; win false static final int A = 0; A 0 static final int B = 1; B 1 static final int C = 2; C 2 static final int N = 3; N 3 public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  } main {
    Main main = new Main();
    main.solve();
    main.show();
  } Main main = new Main(); main new Main() main.solve() main.solve main main.show() main.show main String[] args args public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  } Main {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    } {
      sc.close();
    } sc.close() sc.close sc {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } a = new ArrayList<Deque<Integer>>() a new ArrayList<Deque<Integer>>() a.add(read(sc)) a.add a read(sc) read sc a.add(read(sc)) a.add a read(sc) read sc a.add(read(sc)) a.add a read(sc) read sc private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  } read {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  } Deque<Integer> ans = new ArrayDeque<Integer>(); ans new ArrayDeque<Integer>() String s = sc.next(); s sc.next() sc.next sc int n = s.length(); n s.length() s.length s for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    } {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    } if (s.charAt(i) == 'a' ) ans.addLast(A); s.charAt(i) == 'a' s.charAt(i) s.charAt s i 'a' ans.addLast(A) ans.addLast ans A if (s.charAt(i) == 'b' ) ans.addLast(B); s.charAt(i) == 'b' s.charAt(i) s.charAt s i 'b' ans.addLast(B) ans.addLast ans B if (s.charAt(i) == 'c' ) ans.addLast(C); s.charAt(i) == 'c' s.charAt(i) s.charAt s i 'c' ans.addLast(C) ans.addLast ans C return ans; ans Scanner sc sc void solve() {
    while (!win) play();
  } solve {
    while (!win) play();
  } while (!win) play(); !win win play() play void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  } play {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  } if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    } a.get(turn).size() == 0 a.get(turn).size() a.get(turn).size a.get(turn) a.get a turn 0 {
      win = true;
      ans = turn;
      return;
    } win = true win true ans = turn ans turn return; turn = a.get(turn).pollFirst() turn a.get(turn).pollFirst() a.get(turn).pollFirst a.get(turn) a.get a turn void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  } show {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  } if (ans == A) System.out.println("A"); ans == A ans A System.out.println("A") System.out.println System.out System System.out "A" if (ans == B) System.out.println("B"); ans == B ans B System.out.println("B") System.out.println System.out System System.out "B" if (ans == C) System.out.println("C"); ans == C ans C System.out.println("C") System.out.println System.out System System.out "C" public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  List<Deque<Integer>> a;
  int ans;
  int turn = 0;
  boolean win = false;
  static final int A = 0;
  static final int B = 1;
  static final int C = 2;
  static final int N = 3;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  }

  private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  }
  
  void solve() {
    while (!win) play();
  }

  void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  }

  void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  }
} public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  List<Deque<Integer>> a;
  int ans;
  int turn = 0;
  boolean win = false;
  static final int A = 0;
  static final int B = 1;
  static final int C = 2;
  static final int N = 3;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  }

  private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  }
  
  void solve() {
    while (!win) play();
  }

  void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  }

  void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  List<Deque<Integer>> a;
  int ans;
  int turn = 0;
  boolean win = false;
  static final int A = 0;
  static final int B = 1;
  static final int C = 2;
  static final int N = 3;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  }

  private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  }
  
  void solve() {
    while (!win) play();
  }

  void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  }

  void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  }
}
