import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        List<Character> list_a = new ArrayList<>();
        for(char i : Sa.toCharArray()) {
            list_a.add(i);
        }
        List<Character> list_b = new ArrayList<>();
        for(char i : Sb.toCharArray()) {
            list_b.add(i);
        }
        List<Character> list_c = new ArrayList<>();
        for(char i : Sc.toCharArray()) {
            list_c.add(i);
        }
        char turn = 'a';
        List<Character> current = list_a;
        while (!current.isEmpty()) {
            char x = current.remove(0);
            if (x == 'a') {
                turn = 'a';
                current = list_a;
            }
            if (x == 'b') {
                turn = 'b';
                current = list_b;
            }
            if (x == 'c') {
                turn = 'c';
                current = list_c;
            }
        }
        System.out.println((char) (turn-32));
    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz