
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

/**
 * Created by jaga on 9/22/16.
 */
public class Main {
    public static void solve(PrintWriter out, FastScanner in){
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    }

    static class Pair implements Comparable {
        int first, second;

        Pair(int a, int b) {
            first = a;
            second = b;
        }

        public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        }
    }

    /*以下はテンプレ*/
    public static void main(String args[]) {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    }

    public static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

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

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }

        public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        }

        public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }
    }
}
 import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.OutputStream; OutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.NoSuchElementException; NoSuchElementException java.util public class Main {
    public static void solve(PrintWriter out, FastScanner in){
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    }

    static class Pair implements Comparable {
        int first, second;

        Pair(int a, int b) {
            first = a;
            second = b;
        }

        public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        }
    }

    /*以下はテンプレ*/
    public static void main(String args[]) {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    }

    public static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

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

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }

        public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        }

        public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }
    }
} Main public static void solve(PrintWriter out, FastScanner in){
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    } solve {
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    } String a = in.next(); a in.next() in.next in String b = in.next(); b in.next() in.next in String c = in.next(); c in.next() in.next in int na = a.length(); na a.length() a.length a int nb = b.length(); nb b.length() b.length b int nc = c.length(); nc c.length() c.length c int ia = 1; ia 1 int ib = 0; ib 0 int ic = 0; ic 0 char prev = a.charAt(0); prev a.charAt(0) a.charAt a 0 PrintWriter out out FastScanner in in /*以下はテンプレ*/
    public static void main(String args[]) {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    } main {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    } OutputStream outputStream = System.out; outputStream System.out System System.out PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) FastScanner in = new FastScanner(); in new FastScanner() solve(out, in) solve out in out.close() out.close out String args[] args static class Pair implements Comparable {
        int first, second;

        Pair(int a, int b) {
            first = a;
            second = b;
        }

        public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        }
    } Pair int first first second; second Pair(int a, int b) {
            first = a;
            second = b;
        } Pair {
            first = a;
            second = b;
        } first = a first a second = b second b int a a int b b public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        } compareTo {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        } Pair p1 = (Pair) other; p1 (Pair) other return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合 this.first - ((Pair) other).first this.first this this.first ((Pair) other).first ((Pair) other) ((Pair) other).first Object other other Comparable public static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

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

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }

        public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        }

        public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }
    } FastScanner private final InputStream in = System.in; in System.in System System.in private final byte[] buffer = new byte[1024]; buffer new byte[1024] 1024 private int ptr = 0; ptr 0 private int bufferLength = 0; bufferLength 0 private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        } hasNextByte {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        } if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            } ptr < bufferLength ptr bufferLength {
                return true;
            } return true; true {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            } ptr = 0 ptr 0 try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    bufferLength = in.read(buffer);
                } bufferLength = in.read(buffer) bufferLength in.read(buffer) in.read in buffer if (bufferLength <= 0) {
                    return false;
                } bufferLength <= 0 bufferLength 0 {
                    return false;
                } return false; false return true; true private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        } readByte {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        } if (hasNextByte()) return buffer[ptr++];
            else return -1; hasNextByte() hasNextByte return buffer[ptr++]; buffer[ptr++] buffer ptr++ ptr return -1; -1 1 private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        } isPrintableChar {
            return 33 <= c && c <= 126;
        } return 33 <= c && c <= 126; 33 <= c && c <= 126 33 <= c 33 c c <= 126 c 126 int c c private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        } skipUnprintable {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        } while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; hasNextByte() && !isPrintableChar(buffer[ptr]) hasNextByte() hasNextByte !isPrintableChar(buffer[ptr]) isPrintableChar(buffer[ptr]) isPrintableChar buffer[ptr] buffer ptr ptr++ ptr boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        } hasNext {
            skipUnprintable();
            return hasNextByte();
        } skipUnprintable() skipUnprintable return hasNextByte(); hasNextByte() hasNextByte public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        } next {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb = new StringBuilder(); sb new StringBuilder() int b = readByte(); b readByte() readByte while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            } isPrintableChar(b) isPrintableChar b {
                sb.appendCodePoint(b);
                b = readByte();
            } sb.appendCodePoint(b) sb.appendCodePoint sb b b = readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        } nextLong {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        } if (!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() long n = 0; n 0 boolean minus = false; minus false int b = readByte(); b readByte() readByte if (b == '-') {
                minus = true;
                b = readByte();
            } b == '-' b '-' {
                minus = true;
                b = readByte();
            } minus = true minus true b = readByte() b readByte() readByte if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            } b < '0' || '9' < b b < '0' b '0' '9' < b '9' b {
                throw new NumberFormatException();
            } throw new NumberFormatException(); new NumberFormatException() while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            } true {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            } if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                } '0' <= b && b <= '9' '0' <= b '0' b b <= '9' b '9' {
                    n *= 10;
                    n += b - '0';
                } n *= 10 n 10 n += b - '0' n b - '0' b '0' if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                } b == -1 || !isPrintableChar(b) b == -1 b -1 1 !isPrintableChar(b) isPrintableChar(b) isPrintableChar b {
                    return minus ? -n : n;
                } return minus ? -n : n; minus ? -n : n minus -n n n {
                    throw new NumberFormatException();
                } throw new NumberFormatException(); new NumberFormatException() b = readByte() b readByte() readByte double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        } nextDoubleArray {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        } double[] array = new double[n]; array new double[n] n for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                array[i] = nextDouble();
            } {
                array[i] = nextDouble();
            } array[i] = nextDouble() array[i] array i nextDouble() nextDouble return array; array int n n double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        } nextDoubleMap {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        } double[][] map = new double[n][]; map new double[n][] n for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                map[i] = nextDoubleArray(m);
            } {
                map[i] = nextDoubleArray(m);
            } map[i] = nextDoubleArray(m) map[i] map i nextDoubleArray(m) nextDoubleArray m return map; map int n n int m m public int nextInt() {
            return (int) nextLong();
        } nextInt {
            return (int) nextLong();
        } return (int) nextLong(); (int) nextLong() nextLong public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        } nextIntArray {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        } int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) array[i] = nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = nextInt(); array[i] = nextInt() array[i] array i nextInt() nextInt return array; array int n n public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        } nextLongArray {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        } long[] array = new long[n]; array new long[n] n for (int i = 0; i < n; i++) array[i] = nextLong(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = nextLong(); array[i] = nextLong() array[i] array i nextLong() nextLong return array; array int n n public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        } nextStringArray {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        } String[] array = new String[n]; array new String[n] n for (int i = 0; i < n; i++) array[i] = next(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = next(); array[i] = next() array[i] array i next() next return array; array int n n public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        } nextCharMap {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        } char[][] array = new char[n][]; array new char[n][] n for (int i = 0; i < n; i++) array[i] = next().toCharArray(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = next().toCharArray(); array[i] = next().toCharArray() array[i] array i next().toCharArray() next().toCharArray next() next return array; array int n n public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        } nextIntMap {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        } int[][] map = new int[n][]; map new int[n][] n for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                map[i] = nextIntArray(m);
            } {
                map[i] = nextIntArray(m);
            } map[i] = nextIntArray(m) map[i] map i nextIntArray(m) nextIntArray m return map; map int n n int m m public class Main {
    public static void solve(PrintWriter out, FastScanner in){
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    }

    static class Pair implements Comparable {
        int first, second;

        Pair(int a, int b) {
            first = a;
            second = b;
        }

        public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        }
    }

    /*以下はテンプレ*/
    public static void main(String args[]) {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    }

    public static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

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

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }

        public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        }

        public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }
    }
} public class Main {
    public static void solve(PrintWriter out, FastScanner in){
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    }

    static class Pair implements Comparable {
        int first, second;

        Pair(int a, int b) {
            first = a;
            second = b;
        }

        public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        }
    }

    /*以下はテンプレ*/
    public static void main(String args[]) {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    }

    public static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

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

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }

        public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        }

        public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }
    }
} Main

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

/**
 * Created by jaga on 9/22/16.
 */
public class Main {
    public static void solve(PrintWriter out, FastScanner in){
        String a = in.next();
        String b = in.next();
        String c = in.next();

        int na = a.length();
        int nb = b.length();
        int nc = c.length();

        int ia = 1;
        int ib = 0;
        int ic = 0;

        char prev = a.charAt(0);

        loop:while (ia <= na   && ib <= nb  && ic <= nc ) {
            switch (prev){
                case 'a':
                    if (ia == na) {
                        System.out.println("A");
                        break loop;
                    }
                    prev = a.charAt(ia);
                    ia ++;
                    break;
                case 'b':
                    if (ib == nb) {
                        System.out.println("B");
                        break loop;
                    }
                    prev = b.charAt(ib);
                    ib++;
                    break;
                case 'c':
                    if (ic == nc) {
                        System.out.println("C");
                        break loop;
                    }
                    prev = c.charAt(ic);
                    ic ++;
                    break;
            }
        }
    }

    static class Pair implements Comparable {
        int first, second;

        Pair(int a, int b) {
            first = a;
            second = b;
        }

        public int compareTo(Object other) {
            Pair p1 = (Pair) other;
            return this.first - ((Pair) other).first; // IDの値に従い昇順で並び替えたい場合
//         return -(this.first - ((Pair) other).first); // IDの値に従い降順で並び替えたい場合
        }
    }

    /*以下はテンプレ*/
    public static void main(String args[]) {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastScanner in = new FastScanner();
        solve(out, in);
        out.close();
    }

    public static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bufferLength <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

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

        double[] nextDoubleArray(int n) {
            double[] array = new double[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextDouble();
            }
            return array;
        }

        double[][] nextDoubleMap(int n, int m) {
            double[][] map = new double[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextDoubleArray(m);
            }
            return map;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }

        public String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) array[i] = next();
            return array;
        }

        public char[][] nextCharMap(int n) {
            char[][] array = new char[n][];
            for (int i = 0; i < n; i++) array[i] = next().toCharArray();
            return array;
        }

        public int[][] nextIntMap(int n, int m) {
            int[][] map = new int[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextIntArray(m);
            }
            return map;
        }
    }
}

