import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.math.BigDecimal; BigDecimal java.math import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset import java.util.*; util.* java public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) throws IOException {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args void run() {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    } run {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] A = sc.next().toCharArray(); A sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] B = sc.next().toCharArray(); B sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] C = sc.next().toCharArray(); C sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc List<String> aArray = new ArrayList<>(); aArray new ArrayList<>() List<String> bArray = new ArrayList<>(); bArray new ArrayList<>() List<String> cArray = new ArrayList<>(); cArray new ArrayList<>() for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        } char c A {
            String s = String.valueOf(c);
            aArray.add(s);
        } {
            String s = String.valueOf(c);
            aArray.add(s);
        } String s = String.valueOf(c); s String.valueOf(c) String.valueOf String c aArray.add(s) aArray.add aArray s for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        } char c B {
            String s = String.valueOf(c);
            bArray.add(s);
        } {
            String s = String.valueOf(c);
            bArray.add(s);
        } String s = String.valueOf(c); s String.valueOf(c) String.valueOf String c bArray.add(s) bArray.add bArray s for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        } char c C {
            String s = String.valueOf(c);
            cArray.add(s);
        } {
            String s = String.valueOf(c);
            cArray.add(s);
        } String s = String.valueOf(c); s String.valueOf(c) String.valueOf String c cArray.add(s) cArray.add cArray s String next = aArray.get(0); next aArray.get(0) aArray.get aArray 0 aArray.remove(0) aArray.remove aArray 0 String ans = ""; ans "" while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        } true {
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        } if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            } next.equals("a") next.equals next "a" {
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } if(aArray.size() == 0){
                    ans = "A";
                    break;
                } aArray.size() == 0 aArray.size() aArray.size aArray 0 {
                    ans = "A";
                    break;
                } ans = "A" ans "A" break; next = aArray.get(0) next aArray.get(0) aArray.get aArray 0 aArray.remove(0) aArray.remove aArray 0 if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            } next.equals("b") next.equals next "b" {
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } if(bArray.size() == 0){
                    ans = "B";
                    break;
                } bArray.size() == 0 bArray.size() bArray.size bArray 0 {
                    ans = "B";
                    break;
                } ans = "B" ans "B" break; next = bArray.get(0) next bArray.get(0) bArray.get bArray 0 bArray.remove(0) bArray.remove bArray 0 {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            } if(cArray.size() == 0){
                    ans = "C";
                    break;
                } cArray.size() == 0 cArray.size() cArray.size cArray 0 {
                    ans = "C";
                    break;
                } ans = "C" ans "C" break; next = cArray.get(0) next cArray.get(0) cArray.get cArray 0 cArray.remove(0) cArray.remove cArray 0 System.out.println(ans) System.out.println System.out System System.out ans public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    }
} public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] A = sc.next().toCharArray();
        char[] B = sc.next().toCharArray();
        char[] C = sc.next().toCharArray();

        List<String> aArray = new ArrayList<>();
        List<String> bArray = new ArrayList<>();
        List<String> cArray = new ArrayList<>();

        for(char c: A){
            String s = String.valueOf(c);
            aArray.add(s);
        }
        for(char c: B){
            String s = String.valueOf(c);
            bArray.add(s);
        }
        for(char c: C){
            String s = String.valueOf(c);
            cArray.add(s);
        }

        String next = aArray.get(0);
        aArray.remove(0);

        String ans = "";

        while(true){
            if(next.equals("a")){
                if(aArray.size() == 0){
                    ans = "A";
                    break;
                }
                next = aArray.get(0);
                aArray.remove(0);
            } else if(next.equals("b")){
                if(bArray.size() == 0){
                    ans = "B";
                    break;
                }
                next = bArray.get(0);
                bArray.remove(0);
            } else {
                if(cArray.size() == 0){
                    ans = "C";
                    break;
                }
                next = cArray.get(0);
                cArray.remove(0);
            }
        }

        System.out.println(ans);
    }
}
