import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    }
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    }
} Main public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    } main {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    } BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) String [] letters = new String[3]; letters new String[3] 3 for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        } int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
            letters[i] = input.readLine();
        } {
            letters[i] = input.readLine();
        } letters[i] = input.readLine() letters[i] letters i input.readLine() input.readLine input int current = 0; current 0 int [] positions = new int[3]; positions new int[3] 3 while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        } true {
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        } if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            } positions[current] == letters[current].length() positions[current] positions current letters[current].length() letters[current].length letters[current] letters current {
                System.out.println((char)(current + 'A'));
                break;
            } System.out.println((char)(current + 'A')) System.out.println System.out System System.out (char)(current + 'A') current 'A' break; current = letters[current].charAt(positions[current]++) - 'a' current letters[current].charAt(positions[current]++) - 'a' letters[current].charAt(positions[current]++) letters[current].charAt letters[current] letters current positions[current]++ positions[current] positions current 'a' String[] args args public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    }
} public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] letters = new String[3];

        for (int i = 0; i < 3; i++) {
            letters[i] = input.readLine();
        }
        int current = 0;
        int [] positions = new int[3];
        while (true){
            if (positions[current] == letters[current].length()){
                System.out.println((char)(current + 'A'));
                break;
            }
            current = letters[current].charAt(positions[current]++) - 'a';

        }
    }
}

