import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    char[] as, bs, cs;

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

    void run() {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    char[] as, bs, cs;

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

    void run() {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
} Main char[] as as bs bs cs; cs public static void main(String args[]) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String args[] args void run() {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    } run {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    } FastReader sc = new FastReader(); sc new FastReader() as = sc.next().toCharArray() as sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc bs = sc.next().toCharArray() bs sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc cs = sc.next().toCharArray() cs sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc solve() solve void solve() {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    } solve {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    } int turn = 0; turn 0 int ap = 0 ap 0 bp = 0 bp 0 cp = 0; cp 0 while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        } true {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        } if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            } turn == 0 turn 0 {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } if (ap == as.length) {
                    System.out.println('A');
                    return;
                } ap == as.length ap as.length as as.length {
                    System.out.println('A');
                    return;
                } System.out.println('A') System.out.println System.out System System.out 'A' return; turn = as[ap++] - 'a' turn as[ap++] - 'a' as[ap++] as ap++ ap 'a' if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            } turn == 1 turn 1 {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } if (bp == bs.length) {
                    System.out.println('B');
                    return;
                } bp == bs.length bp bs.length bs bs.length {
                    System.out.println('B');
                    return;
                } System.out.println('B') System.out.println System.out System System.out 'B' return; turn = bs[bp++] - 'a' turn bs[bp++] - 'a' bs[bp++] bs bp++ bp 'a' {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            } if (cp == cs.length) {
                    System.out.println('C');
                    return;
                } cp == cs.length cp cs.length cs cs.length {
                    System.out.println('C');
                    return;
                } System.out.println('C') System.out.println System.out System System.out 'C' return; turn = cs[cp++] - 'a' turn cs[cp++] - 'a' cs[cp++] cs cp++ cp 'a' static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        } FastReader {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        } br = new BufferedReader(new
                    InputStreamReader(System.in)) br new BufferedReader(new
                    InputStreamReader(System.in)) String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            } try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                } catch (IOException e)
                {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt()
        {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong()
        {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble()
        {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        } nextLine {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        } String str = ""; str "" try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            } catch (IOException e)
            {
                e.printStackTrace();
            } IOException e {
                e.printStackTrace();
            } e.printStackTrace() e.printStackTrace e {
                str = br.readLine();
            } str = br.readLine() str br.readLine() br.readLine br return str; str public class Main {
    char[] as, bs, cs;

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

    void run() {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
} public class Main {
    char[] as, bs, cs;

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

    void run() {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    char[] as, bs, cs;

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

    void run() {
        FastReader sc = new FastReader();
        as = sc.next().toCharArray();
        bs = sc.next().toCharArray();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int turn = 0;
        int ap = 0, bp = 0, cp = 0;
        while(true) {
            if (turn == 0) {
                if (ap == as.length) {
                    System.out.println('A');
                    return;
                }
                turn = as[ap++] - 'a';
            } else if (turn == 1) {
                if (bp == bs.length) {
                    System.out.println('B');
                    return;
                }
                turn = bs[bp++] - 'a';
            } else {
                if (cp == cs.length) {
                    System.out.println('C');
                    return;
                }
                turn = cs[cp++] - 'a';
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}
