import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    }

    private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    }
} import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    }

    private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    } main {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Map<Character, char[]> cardMap = new HashMap<Character, char[]>(); cardMap new HashMap<Character, char[]>() cardMap.put('a', scanner.nextLine().toCharArray()) cardMap.put cardMap 'a' scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner cardMap.put('b', scanner.nextLine().toCharArray()) cardMap.put cardMap 'b' scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner cardMap.put('c', scanner.nextLine().toCharArray()) cardMap.put cardMap 'c' scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner Map<Character, Integer> indexMap = new HashMap<Character, Integer>(); indexMap new HashMap<Character, Integer>() indexMap.put('a', 0) indexMap.put indexMap 'a' 0 indexMap.put('b', 0) indexMap.put indexMap 'b' 0 indexMap.put('c', 0) indexMap.put indexMap 'c' 0 System.out.print(play('a', cardMap, indexMap)) System.out.print System.out System System.out play('a', cardMap, indexMap) play 'a' cardMap indexMap String[] args args private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    } play {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    } char card[] = cardMap.get(now); card cardMap.get(now) cardMap.get cardMap now int index = indexMap.get(now); index indexMap.get(now) indexMap.get indexMap now if (index >= card.length )
            return Character.toUpperCase(now); index >= card.length index card.length card card.length return Character.toUpperCase(now); Character.toUpperCase(now) Character.toUpperCase Character now char next = card[index]; next card[index] card index indexMap.put(now, index+1) indexMap.put indexMap now index+1 index 1 return play(next, cardMap, indexMap); play(next, cardMap, indexMap) play next cardMap indexMap char now now Map<Character, char[]> cardMap cardMap Map<Character, Integer> indexMap indexMap public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    }

    private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    }

    private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    }
} Main
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<Character, char[]> cardMap = new HashMap<Character, char[]>();
        cardMap.put('a', scanner.nextLine().toCharArray());
        cardMap.put('b', scanner.nextLine().toCharArray());
        cardMap.put('c', scanner.nextLine().toCharArray());
        Map<Character, Integer> indexMap = new HashMap<Character, Integer>();
        indexMap.put('a', 0);
        indexMap.put('b', 0);
        indexMap.put('c', 0);

        System.out.print(play('a', cardMap, indexMap));


    }

    private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
        char card[] = cardMap.get(now);
        int index = indexMap.get(now);

        if (index >= card.length )
            return Character.toUpperCase(now);

        char next = card[index];
        indexMap.put(now, index+1);
        return play(next, cardMap, indexMap);
    }
}
