import java.io.*;
import java.util.*;
 
public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
} Main private static boolean debug = false; debug false private static boolean elapsed = false; elapsed false private static PrintWriter _err = new PrintWriter(System.err); _err new PrintWriter(System.err) private void solve(Scanner sc, PrintWriter out) {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  } solve {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  } StringBuilder sA = new StringBuilder(sc.nextLine()); sA new StringBuilder(sc.nextLine()) StringBuilder sB = new StringBuilder(sc.nextLine()); sB new StringBuilder(sc.nextLine()) StringBuilder sC = new StringBuilder(sc.nextLine()); sC new StringBuilder(sc.nextLine()) Map<Character, StringBuilder> map = new HashMap<>(); map new HashMap<>() map.put('a', sA) map.put map 'a' sA map.put('b', sB) map.put map 'b' sB map.put('c', sC) map.put map 'c' sC char ch = 'a'; ch 'a' while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    } true {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    } StringBuilder sb = map.get(ch); sb map.get(ch) map.get map ch if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      } sb == null sb null {
        throw new RuntimeException(ch + ": Invalid input");
      } throw new RuntimeException(ch + ": Invalid input"); new RuntimeException(ch + ": Invalid input") if (sb.length() == 0) {
        break;
      } sb.length() == 0 sb.length() sb.length sb 0 {
        break;
      } break; ch = sb.charAt(0) ch sb.charAt(0) sb.charAt sb 0 sb.deleteCharAt(0) sb.deleteCharAt sb 0 out.println(Character.toUpperCase(ch)) out.println out Character.toUpperCase(ch) Character.toUpperCase Character ch Scanner sc sc PrintWriter out out private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  } C {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  } long res = 1; res 1 for (long i = n; i > n - r; --i) {
      res *= i;
    } long i = n; long i = n; i n i > n - r i n - r n r --i --i i {
      res *= i;
    } {
      res *= i;
    } res *= i res i for (long i = r; i > 1; --i) {
      res /= i;
    } long i = r; long i = r; i r i > 1 i 1 --i --i i {
      res /= i;
    } {
      res /= i;
    } res /= i res i return res; res long n n long r r private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  } P {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  } long res = 1; res 1 for (long i = n; i > n - r; --i) {
      res *= i;
    } long i = n; long i = n; i n i > n - r i n - r n r --i --i i {
      res *= i;
    } {
      res *= i;
    } res *= i res i return res; res long n n long r r /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  } main {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  } long S = System.currentTimeMillis(); S System.currentTimeMillis() System.currentTimeMillis System Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) new Main().solve(sc, out) new Main().solve new Main() sc out out.flush() out.flush out long G = System.currentTimeMillis(); G System.currentTimeMillis() System.currentTimeMillis System if (elapsed) {
      _err.println((G - S) + "ms");
    } elapsed {
      _err.println((G - S) + "ms");
    } _err.println((G - S) + "ms") _err.println _err (G - S) + "ms" (G - S) G S "ms" _err.flush() _err.flush _err String[] args args public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
} public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
} Main
import java.io.*;
import java.util.*;
 
public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    StringBuilder sA = new StringBuilder(sc.nextLine());
    StringBuilder sB = new StringBuilder(sc.nextLine());
    StringBuilder sC = new StringBuilder(sc.nextLine());
 
    Map<Character, StringBuilder> map = new HashMap<>();
    map.put('a', sA);
    map.put('b', sB);
    map.put('c', sC);
 
    char ch = 'a';
    while (true) {
      StringBuilder sb = map.get(ch);
      if (sb == null) {
        throw new RuntimeException(ch + ": Invalid input");
      }
      if (sb.length() == 0) {
        break;
      }
      ch = sb.charAt(0);
      sb.deleteCharAt(0);
    }
    out.println(Character.toUpperCase(ch));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}