import java.io.*;
import java.util.*;
import java.math.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;

public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    long MOD = 1_000_000_007;
    int inf = 10000000;

    void solve()
    {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } 
    
    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }
    
    public static void main(String[] args) throws Exception { new Main().run(); }
    
    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;
    
    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    
    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    
    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    
    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    
    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

    static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }
 
        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } 
    }
} import java.io.*; io.* java import java.util.*; util.* java import java.math.*; math.* java import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.util.Comparator; Comparator java.util import java.util.Arrays; Arrays java.util public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    long MOD = 1_000_000_007;
    int inf = 10000000;

    void solve()
    {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } 
    
    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }
    
    public static void main(String[] args) throws Exception { new Main().run(); }
    
    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;
    
    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    
    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    
    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    
    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    
    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

    static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }
 
        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } 
    }
} Main InputStream is; is PrintWriter out; out String INPUT = ""; INPUT "" long MOD = 1_000_000_007; MOD 1_000_000_007 int inf = 10000000; inf 10000000 private byte[] inbuf = new byte[1024]; inbuf new byte[1024] 1024 private int lenbuf = 0 lenbuf 0 ptrbuf = 0; ptrbuf 0 void solve()
    {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } solve {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } char[] A = ns().toCharArray(); A ns().toCharArray() ns().toCharArray ns() ns char[] B = ns().toCharArray(); B ns().toCharArray() ns().toCharArray ns() ns char[] C = ns().toCharArray(); C ns().toCharArray() ns().toCharArray ns() ns int a = 0; a 0 int b = 0; b 0 int c = 0; c 0 int cur = 1; cur 1 char next = 'a'; next 'a' while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        } true {
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        } if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            } cur==1 cur 1 {
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            } if(a>=A.length){
                    out.println("A");
                    break;
                } a>=A.length a A.length A A.length {
                    out.println("A");
                    break;
                } out.println("A") out.println out "A" break; next = A[a] next A[a] A a a++ a if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            } cur==2 cur 2 {
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            } if(b>=B.length){
                    out.println("B");
                    break;
                } b>=B.length b B.length B B.length {
                    out.println("B");
                    break;
                } out.println("B") out.println out "B" break; next = B[b] next B[b] B b b++ b if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            } cur==3 cur 3 {
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            } if(c>=C.length){
                    out.println("C");
                    break;
                } c>=C.length c C.length C C.length {
                    out.println("C");
                    break;
                } out.println("C") out.println out "C" break; next = C[c] next C[c] C c c++ c if(next == 'a') cur = 1; next == 'a' next 'a' cur = 1 cur 1 if(next == 'b') cur = 2; next == 'b' next 'b' cur = 2 cur 2 if(next == 'c') cur = 3; next == 'c' next 'c' cur = 3 cur 3 return; void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    } run {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    } is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()) is INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()) INPUT.isEmpty() INPUT.isEmpty INPUT System.in System System.in new ByteArrayInputStream(INPUT.getBytes()) out = new PrintWriter(System.out) out new PrintWriter(System.out) long s = System.currentTimeMillis(); s System.currentTimeMillis() System.currentTimeMillis System solve() solve out.flush() out.flush out if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); !INPUT.isEmpty() INPUT.isEmpty() INPUT.isEmpty INPUT tr(System.currentTimeMillis()-s+"ms") tr System.currentTimeMillis()-s+"ms" System.currentTimeMillis()-s System.currentTimeMillis() System.currentTimeMillis System s "ms" public static void main(String[] args) throws Exception { new Main().run(); } main { new Main().run(); } new Main().run() new Main().run new Main() String[] args args private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    } readByte {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    } if(lenbuf == -1)throw new InputMismatchException(); lenbuf == -1 lenbuf -1 1 throw new InputMismatchException(); new InputMismatchException() if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        } ptrbuf >= lenbuf ptrbuf lenbuf {
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        } ptrbuf = 0 ptrbuf 0 try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } catch (IOException e) { throw new InputMismatchException(); } IOException e { throw new InputMismatchException(); } throw new InputMismatchException(); new InputMismatchException() { lenbuf = is.read(inbuf); } lenbuf = is.read(inbuf) lenbuf is.read(inbuf) is.read is inbuf if(lenbuf <= 0)return -1; lenbuf <= 0 lenbuf 0 return -1; -1 1 return inbuf[ptrbuf++]; inbuf[ptrbuf++] inbuf ptrbuf++ ptrbuf private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } isSpaceChar { return !(c >= 33 && c <= 126); } return !(c >= 33 && c <= 126); !(c >= 33 && c <= 126) (c >= 33 && c <= 126) c >= 33 c 33 c <= 126 c 126 int c c private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } skip { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } int b; b while((b = readByte()) != -1 && isSpaceChar(b)); (b = readByte()) != -1 && isSpaceChar(b) (b = readByte()) != -1 (b = readByte()) b readByte() readByte -1 1 isSpaceChar(b) isSpaceChar b return b; b private double nd() { return Double.parseDouble(ns()); } nd { return Double.parseDouble(ns()); } return Double.parseDouble(ns()); Double.parseDouble(ns()) Double.parseDouble Double ns() ns private char nc() { return (char)skip(); } nc { return (char)skip(); } return (char)skip(); (char)skip() skip private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    } ns {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    } int b = skip(); b skip() skip StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        } !(isSpaceChar(b) && b != ' ') (isSpaceChar(b) && b != ' ') isSpaceChar(b) isSpaceChar b b != ' ' 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 private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    } ns {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    } char[] buf = new char[n]; buf new char[n] n int b = skip() b skip() skip p = 0; p 0 while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        } p < n && !(isSpaceChar(b)) p < n p n !(isSpaceChar(b)) (isSpaceChar(b)) isSpaceChar b {
            buf[p++] = (char)b;
            b = readByte();
        } buf[p++] = (char)b buf[p++] buf p++ p (char)b b = readByte() b readByte() readByte return n == p ? buf : Arrays.copyOf(buf, p); n == p ? buf : Arrays.copyOf(buf, p) n == p n p buf Arrays.copyOf(buf, p) Arrays.copyOf Arrays buf p int n n private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    } nm {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    } char[][] map = new char[n][]; map new char[n][] n for(int i = 0;i < n;i++)map[i] = ns(m); int i = 0; int i = 0; i 0 i < n i n i++ i++ i map[i] = ns(m); map[i] = ns(m) map[i] map i ns(m) ns m return map; map int n n int m m private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    } na {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    } int[] a = new int[n]; a new int[n] n for(int i = 0;i < n;i++)a[i] = ni(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = ni(); a[i] = ni() a[i] a i ni() ni return a; a int n n private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    } ni {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    } int num = 0 num 0 b; b boolean minus = false; minus false while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); (b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-') (b = readByte()) != -1 (b = readByte()) b readByte() readByte -1 1 !((b >= '0' && b <= '9') || b == '-') ((b >= '0' && b <= '9') || b == '-') (b >= '0' && b <= '9') b >= '0' b '0' b <= '9' b '9' b == '-' b '-' if(b == '-'){
            minus = true;
            b = readByte();
        } b == '-' b '-' {
            minus = true;
            b = readByte();
        } minus = true minus true b = readByte() b readByte() readByte while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        } true {
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        } if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            } b >= '0' && b <= '9' b >= '0' b '0' b <= '9' b '9' {
                num = num * 10 + (b - '0');
            } num = num * 10 + (b - '0') num num * 10 + (b - '0') num * 10 num 10 (b - '0') b '0' {
                return minus ? -num : num;
            } return minus ? -num : num; minus ? -num : num minus -num num num b = readByte() b readByte() readByte private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    } nl {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    } long num = 0; num 0 int b; b boolean minus = false; minus false while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); (b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-') (b = readByte()) != -1 (b = readByte()) b readByte() readByte -1 1 !((b >= '0' && b <= '9') || b == '-') ((b >= '0' && b <= '9') || b == '-') (b >= '0' && b <= '9') b >= '0' b '0' b <= '9' b '9' b == '-' b '-' if(b == '-'){
            minus = true;
            b = readByte();
        } b == '-' b '-' {
            minus = true;
            b = readByte();
        } minus = true minus true b = readByte() b readByte() readByte while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        } true {
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        } if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            } b >= '0' && b <= '9' b >= '0' b '0' b <= '9' b '9' {
                num = num * 10 + (b - '0');
            } num = num * 10 + (b - '0') num num * 10 + (b - '0') num * 10 num 10 (b - '0') b '0' {
                return minus ? -num : num;
            } return minus ? -num : num; minus ? -num : num minus -num num num b = readByte() b readByte() readByte private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } tr { System.out.println(Arrays.deepToString(o)); } System.out.println(Arrays.deepToString(o)) System.out.println System.out System System.out Arrays.deepToString(o) Arrays.deepToString Arrays o Object... o o static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }
 
        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } 
    } ArrayUtils public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        } fill {
            for (double[] a : array) Arrays.fill(a, value);
        } for (double[] a : array) Arrays.fill(a, value); double[] a array Arrays.fill(a, value); Arrays.fill(a, value) Arrays.fill Arrays a value double[][] array array double value value public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } fill {
            for (double[][] l : array) fill(l, value);
        } for (double[][] l : array) fill(l, value); double[][] l array fill(l, value); fill(l, value) fill l value double[][][] array array double value value public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    long MOD = 1_000_000_007;
    int inf = 10000000;

    void solve()
    {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } 
    
    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }
    
    public static void main(String[] args) throws Exception { new Main().run(); }
    
    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;
    
    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    
    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    
    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    
    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    
    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

    static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }
 
        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } 
    }
} public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    long MOD = 1_000_000_007;
    int inf = 10000000;

    void solve()
    {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } 
    
    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }
    
    public static void main(String[] args) throws Exception { new Main().run(); }
    
    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;
    
    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    
    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    
    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    
    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    
    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

    static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }
 
        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } 
    }
} Main
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;

public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    long MOD = 1_000_000_007;
    int inf = 10000000;

    void solve()
    {
        char[] A = ns().toCharArray();
        char[] B = ns().toCharArray();
        char[] C = ns().toCharArray();
        int a = 0;
        int b = 0;
        int c = 0;
        int cur = 1;
        char next = 'a';
        while(true){
            if(cur==1){
                if(a>=A.length){
                    out.println("A");
                    break;
                }
                next = A[a];
                a++;
            }
            else if(cur==2){
                if(b>=B.length){
                    out.println("B");
                    break;
                }
                next = B[b];
                b++;
            }
            else if(cur==3){
                if(c>=C.length){
                    out.println("C");
                    break;
                }
                next = C[c];
                c++;
            }
            if(next == 'a') cur = 1;
            if(next == 'b') cur = 2;
            if(next == 'c') cur = 3;
        }
        return;
    } 
    
    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }
    
    public static void main(String[] args) throws Exception { new Main().run(); }
    
    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;
    
    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    
    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    
    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    
    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    
    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    
    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

    static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }
 
        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        } 
    }
}
