import java.util.Scanner;

public class Main {

    static String[] S = new String[3];
    static int[] cnt = new int[3];

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

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    }

    static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    static String[] S = new String[3];
    static int[] cnt = new int[3];

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

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    }

    static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    }
} Main static String[] S = new String[3]; S new String[3] 3 static int[] cnt = new int[3]; cnt new int[3] 3 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    } main {
        Scanner sc = new Scanner(System.in);

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) S[0] = sc.next() S[0] S 0 sc.next() sc.next sc S[1] = sc.next() S[1] S 1 sc.next() sc.next sc S[2] = sc.next() S[2] S 2 sc.next() sc.next sc cnt[0] = S[0].length() cnt[0] cnt 0 S[0].length() S[0].length S[0] S 0 cnt[1] = S[1].length() cnt[1] cnt 1 S[1].length() S[1].length S[1] S 1 cnt[2] = S[2].length() cnt[2] cnt 2 S[2].length() S[2].length S[2] S 2 int ans = serch(0); ans serch(0) serch 0 if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C'); ans == 0 ans 0 System.out.println('A') System.out.println System.out System System.out 'A' if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C'); ans == 1 ans 1 System.out.println('B') System.out.println System.out System System.out 'B' System.out.println('C') System.out.println System.out System System.out 'C' String[] args args static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    } serch {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    } if (cnt[thisTurn] <= 0)
            return thisTurn; cnt[thisTurn] <= 0 cnt[thisTurn] cnt thisTurn 0 return thisTurn; thisTurn int index =  S[thisTurn].length() - cnt[thisTurn]; index S[thisTurn].length() - cnt[thisTurn] S[thisTurn].length() S[thisTurn].length S[thisTurn] S thisTurn cnt[thisTurn] cnt thisTurn char c = S[thisTurn].charAt(index); c S[thisTurn].charAt(index) S[thisTurn].charAt S[thisTurn] S thisTurn index cnt[thisTurn]-- cnt[thisTurn] cnt thisTurn if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2); c == 'a' c 'a' return serch(0); serch(0) serch 0 if (c == 'b')
            return serch(1);
        else
            return serch(2); c == 'b' c 'b' return serch(1); serch(1) serch 1 return serch(2); serch(2) serch 2 int thisTurn thisTurn public class Main {

    static String[] S = new String[3];
    static int[] cnt = new int[3];

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

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    }

    static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    }
} public class Main {

    static String[] S = new String[3];
    static int[] cnt = new int[3];

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

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    }

    static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    }
} Main
import java.util.Scanner;

public class Main {

    static String[] S = new String[3];
    static int[] cnt = new int[3];

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

        S[0] = sc.next();
        S[1] = sc.next();
        S[2] = sc.next();

        cnt[0] = S[0].length();
        cnt[1] = S[1].length();
        cnt[2] = S[2].length();

        int ans = serch(0);
        if (ans == 0)
            System.out.println('A');
        else if (ans == 1)
            System.out.println('B');
        else
            System.out.println('C');
    }

    static int serch(int thisTurn) {
        if (cnt[thisTurn] <= 0)
            return thisTurn;

        int index =  S[thisTurn].length() - cnt[thisTurn];
        char c = S[thisTurn].charAt(index);
        cnt[thisTurn]--;

        if (c == 'a')
            return serch(0);
        else if (c == 'b')
            return serch(1);
        else
            return serch(2);
    }
}