import java.util.Scanner;

public class Main {

  static String a = "";
  static String b = "";
  static String c = "";

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  }

  public static void judge(char ch) {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {

  static String a = "";
  static String b = "";
  static String c = "";

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  }

  public static void judge(char ch) {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  }
} Main static String a = ""; a "" static String b = ""; b "" static String c = ""; c "" public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  } main {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) a = sc.next() a sc.next() sc.next sc b = sc.next() b sc.next() sc.next sc c = sc.next() c sc.next() sc.next sc judge('a') judge 'a' String[] args args public static void judge(char ch) {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  } judge {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  } if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    } ch == 'a' ch 'a' {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    } if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      } a.length() == 0 a.length() a.length a 0 {
        System.out.println("A");
        return;
      } System.out.println("A") System.out.println System.out System System.out "A" return; {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      } char card = a.charAt(0); card a.charAt(0) a.charAt a 0 a = a.substring(1) a a.substring(1) a.substring a 1 judge(card) judge card if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    } ch == 'b' ch 'b' {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    } if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      } b.length() == 0 b.length() b.length b 0 {
        System.out.println("B");
        return;
      } System.out.println("B") System.out.println System.out System System.out "B" return; {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      } char card = b.charAt(0); card b.charAt(0) b.charAt b 0 b = b.substring(1) b b.substring(1) b.substring b 1 judge(card) judge card if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    } ch == 'c' ch 'c' {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    } if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      } c.length() == 0 c.length() c.length c 0 {
        System.out.println("C");
        return;
      } System.out.println("C") System.out.println System.out System System.out "C" return; {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      } char card = c.charAt(0); card c.charAt(0) c.charAt c 0 c = c.substring(1) c c.substring(1) c.substring c 1 judge(card) judge card char ch ch public class Main {

  static String a = "";
  static String b = "";
  static String c = "";

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  }

  public static void judge(char ch) {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  }
} public class Main {

  static String a = "";
  static String b = "";
  static String c = "";

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  }

  public static void judge(char ch) {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  }
} Main
import java.util.Scanner;

public class Main {

  static String a = "";
  static String b = "";
  static String c = "";

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    a = sc.next();
    b = sc.next();
    c = sc.next();

    judge('a');
  }

  public static void judge(char ch) {

    if (ch == 'a') {
      if (a.length() == 0) {
        System.out.println("A");
        return;
      } else {
        char card = a.charAt(0);
        a = a.substring(1);
        judge(card);
      }
    }

    if (ch == 'b') {
      if (b.length() == 0) {
        System.out.println("B");
        return;
      } else {
        char card = b.charAt(0);
        b = b.substring(1);
        judge(card);
      }
    }

    if (ch == 'c') {
      if (c.length() == 0) {
        System.out.println("C");
        return;
      } else {
        char card = c.charAt(0);
        c = c.substring(1);
        judge(card);
      }
    }
  }
}