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