import java.util.*;

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

  int n;
  Deque<Integer> a = new ArrayDeque<Integer>();
  Deque<Integer> b = new ArrayDeque<Integer>();
  Deque<Integer> c = new ArrayDeque<Integer>();
  int ans;
  int turn = 0;
  boolean win = false;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  }

  private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  }
  
  void solve() {
    while (!win) {
      play();
    }
  }

  void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  }

  void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  }
  
  void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  }

  void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  }

  void show() {
    if (ans == 0) System.out.println("A");
    if (ans == 1) System.out.println("B");
    if (ans == 2) 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();
  }

  int n;
  Deque<Integer> a = new ArrayDeque<Integer>();
  Deque<Integer> b = new ArrayDeque<Integer>();
  Deque<Integer> c = new ArrayDeque<Integer>();
  int ans;
  int turn = 0;
  boolean win = false;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  }

  private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  }
  
  void solve() {
    while (!win) {
      play();
    }
  }

  void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  }

  void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  }
  
  void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  }

  void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  }

  void show() {
    if (ans == 0) System.out.println("A");
    if (ans == 1) System.out.println("B");
    if (ans == 2) System.out.println("C");
  }
} Main int n; n Deque<Integer> a = new ArrayDeque<Integer>(); a new ArrayDeque<Integer>() Deque<Integer> b = new ArrayDeque<Integer>(); b new ArrayDeque<Integer>() Deque<Integer> c = new ArrayDeque<Integer>(); c new ArrayDeque<Integer>() int ans; ans int turn = 0; turn 0 boolean win = false; win false 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 {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  } Main {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    } {
      sc.close();
    } sc.close() sc.close sc {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } read(sc, a) read sc a read(sc, b) read sc b read(sc, c) read sc c private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  } read {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  } 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' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    } {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    } if (s.charAt(i) == 'a' ) a.addLast(0); s.charAt(i) == 'a' s.charAt(i) s.charAt s i 'a' a.addLast(0) a.addLast a 0 if (s.charAt(i) == 'b' ) a.addLast(1); s.charAt(i) == 'b' s.charAt(i) s.charAt s i 'b' a.addLast(1) a.addLast a 1 if (s.charAt(i) == 'c' ) a.addLast(2); s.charAt(i) == 'c' s.charAt(i) s.charAt s i 'c' a.addLast(2) a.addLast a 2 Scanner sc sc Deque<Integer> a a void solve() {
    while (!win) {
      play();
    }
  } solve {
    while (!win) {
      play();
    }
  } while (!win) {
      play();
    } !win win {
      play();
    } play() play void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  } play {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  } if (turn == 0) play_a(); turn == 0 turn 0 play_a() play_a if (turn == 1) play_b(); turn == 1 turn 1 play_b() play_b if (turn == 2) play_c(); turn == 2 turn 2 play_c() play_c void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  } play_a {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  } if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    } a.size() == 0 a.size() a.size a 0 {
      win = true;
      ans = 0;
      return;
    } win = true win true ans = 0 ans 0 return; turn = a.pollFirst() turn a.pollFirst() a.pollFirst a void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  } play_b {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  } if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    } b.size() == 0 b.size() b.size b 0 {
      win = true;
      ans = 1;
      return;
    } win = true win true ans = 1 ans 1 return; turn = b.pollFirst() turn b.pollFirst() b.pollFirst b void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  } play_c {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  } if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    } c.size() == 0 c.size() c.size c 0 {
      win = true;
      ans = 2;
      return;
    } win = true win true ans = 2 ans 2 return; turn = c.pollFirst() turn c.pollFirst() c.pollFirst c void show() {
    if (ans == 0) System.out.println("A");
    if (ans == 1) System.out.println("B");
    if (ans == 2) System.out.println("C");
  } show {
    if (ans == 0) System.out.println("A");
    if (ans == 1) System.out.println("B");
    if (ans == 2) System.out.println("C");
  } if (ans == 0) System.out.println("A"); ans == 0 ans 0 System.out.println("A") System.out.println System.out System System.out "A" if (ans == 1) System.out.println("B"); ans == 1 ans 1 System.out.println("B") System.out.println System.out System System.out "B" if (ans == 2) System.out.println("C"); ans == 2 ans 2 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();
  }

  int n;
  Deque<Integer> a = new ArrayDeque<Integer>();
  Deque<Integer> b = new ArrayDeque<Integer>();
  Deque<Integer> c = new ArrayDeque<Integer>();
  int ans;
  int turn = 0;
  boolean win = false;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  }

  private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  }
  
  void solve() {
    while (!win) {
      play();
    }
  }

  void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  }

  void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  }
  
  void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  }

  void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  }

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

  int n;
  Deque<Integer> a = new ArrayDeque<Integer>();
  Deque<Integer> b = new ArrayDeque<Integer>();
  Deque<Integer> c = new ArrayDeque<Integer>();
  int ans;
  int turn = 0;
  boolean win = false;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  }

  private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  }
  
  void solve() {
    while (!win) {
      play();
    }
  }

  void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  }

  void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  }
  
  void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  }

  void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  }

  void show() {
    if (ans == 0) System.out.println("A");
    if (ans == 1) System.out.println("B");
    if (ans == 2) 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();
  }

  int n;
  Deque<Integer> a = new ArrayDeque<Integer>();
  Deque<Integer> b = new ArrayDeque<Integer>();
  Deque<Integer> c = new ArrayDeque<Integer>();
  int ans;
  int turn = 0;
  boolean win = false;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  }

  private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  }
  
  void solve() {
    while (!win) {
      play();
    }
  }

  void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  }

  void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  }
  
  void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  }

  void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  }

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