import java.util.Scanner;

public class Main {
  public static String[] str = new String[3];

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

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  }

  public static int play(int n) {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static String[] str = new String[3];

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

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  }

  public static int play(int n) {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  }
} Main public static String[] str = new String[3]; str new String[3] 3 public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  } main {
    Scanner scn = new Scanner(System.in);

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) str[0] = scn.next() str[0] str 0 scn.next() scn.next scn str[1] = scn.next() str[1] str 1 scn.next() scn.next scn str[2] = scn.next() str[2] str 2 scn.next() scn.next scn int num = 0; num 0 while(num >= 0) {
      num = play(num);
    } num >= 0 num 0 {
      num = play(num);
    } num = play(num) num play(num) play num num += 3 num 3 switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    } num case 0: 0 case 0: System.out.println("A") System.out.println System.out System System.out "A" break; case 1: 1 case 1: System.out.println("B") System.out.println System.out System System.out "B" break; case 2: 2 case 2: System.out.println("C") System.out.println System.out System System.out "C" break; default: default: break; String[] args args public static int play(int n) {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  } play {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  } if (str[n].length() == 0) {
      return n-3;
    } str[n].length() == 0 str[n].length() str[n].length str[n] str n 0 {
      return n-3;
    } return n-3; n-3 n 3 char nextPlayer = str[n].charAt(0); nextPlayer str[n].charAt(0) str[n].charAt str[n] str n 0 str[n] = str[n].substring(1, str[n].length()) str[n] str n str[n].substring(1, str[n].length()) str[n].substring str[n] str n 1 str[n].length() str[n].length str[n] str n switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    } nextPlayer case 'a': 'a' case 'a': n = 0 n 0 break; case 'b': 'b' case 'b': n = 1 n 1 break; case 'c': 'c' case 'c': n = 2 n 2 break; default: default: break; return n; n int n n public class Main {
  public static String[] str = new String[3];

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

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  }

  public static int play(int n) {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  }
} public class Main {
  public static String[] str = new String[3];

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

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  }

  public static int play(int n) {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  }
} Main
import java.util.Scanner;

public class Main {
  public static String[] str = new String[3];

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

    str[0] = scn.next();
    str[1] = scn.next();
    str[2] = scn.next();

    int num = 0;

    while(num >= 0) {
      num = play(num);
    }

    num += 3;

    switch (num) {
      case 0:
        System.out.println("A");
        break;
      case 1:
        System.out.println("B");
        break;
      case 2:
        System.out.println("C");
        break;
      default:
        break;
    }
  }

  public static int play(int n) {
    if (str[n].length() == 0) {
      return n-3;
    }

    char nextPlayer = str[n].charAt(0);

    str[n] = str[n].substring(1, str[n].length());

    switch (nextPlayer) {
      case 'a':
        n = 0;
        break;
      case 'b':
        n = 1;
        break;
      case 'c':
        n = 2;
        break;
      default:
        break;
    }

    //System.out.printf("A:%s\tB:%s\tC:%s\t%c\t%d\n", str[0], str[1], str[2], nextPlayer, n);

    return n;
  }
}
