import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    }
} Main static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768); br new BufferedReader(new InputStreamReader(System.in), 32768) static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) static StringTokenizer t; t static long mod = 998244353; mod 998244353 static long maxn = 200005; maxn 200005 static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    } sn {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    } while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        } t == null || !t.hasMoreTokens() t == null t null !t.hasMoreTokens() t.hasMoreTokens() t.hasMoreTokens t {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        } try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            } catch (IOException e) {
                throw new RuntimeException();
            } IOException e {
                throw new RuntimeException();
            } throw new RuntimeException(); new RuntimeException() {
                t = new StringTokenizer(br.readLine());
            } t = new StringTokenizer(br.readLine()) t new StringTokenizer(br.readLine()) return t.nextToken(); t.nextToken() t.nextToken t static int ni() {
        return Integer.parseInt(sn());
    } ni {
        return Integer.parseInt(sn());
    } return Integer.parseInt(sn()); Integer.parseInt(sn()) Integer.parseInt Integer sn() sn static long nlo() {
        return Long.parseLong(sn());
    } nlo {
        return Long.parseLong(sn());
    } return Long.parseLong(sn()); Long.parseLong(sn()) Long.parseLong Long sn() sn public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    } main {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    } int t = 1; t 1 while (t-- > 0) {
            solve();
        } t-- > 0 t-- t 0 {
            solve();
        } solve() solve out.close() out.close out String args[] args static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    } pro {
        return (a % mod * b % mod) % mod;
    } return (a % mod * b % mod) % mod; (a % mod * b % mod) % mod (a % mod * b % mod) a % mod * b a % mod a mod b mod mod long a a long b b static long add(long a, long b) {
        return (a + b) % mod;
    } add {
        return (a + b) % mod;
    } return (a + b) % mod; (a + b) % mod (a + b) a b mod long a a long b b static void solve() {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    } solve {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    } char a[] = sn().toCharArray(); a sn().toCharArray() sn().toCharArray sn() sn char b[] = sn().toCharArray(); b sn().toCharArray() sn().toCharArray sn() sn char c[] = sn().toCharArray(); c sn().toCharArray() sn().toCharArray sn() sn int n = a.length; n a.length a a.length int m = b.length; m b.length b b.length int k = c.length; k c.length c c.length Stack<Character> arr[] = new Stack[3]; arr new Stack[3] 3 for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        } int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
            arr[i] = new Stack<>();
        } {
            arr[i] = new Stack<>();
        } arr[i] = new Stack<>() arr[i] arr i new Stack<>() for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]); int i = n - 1; int i = n - 1; i n - 1 n 1 i >= 0 i 0 i-- i-- i arr[0].push(a[i]); arr[0].push(a[i]) arr[0].push arr[0] arr 0 a[i] a i for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]); int i = m - 1; int i = m - 1; i m - 1 m 1 i >= 0 i 0 i-- i-- i arr[1].push(b[i]); arr[1].push(b[i]) arr[1].push arr[1] arr 1 b[i] b i for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]); int i = k - 1; int i = k - 1; i k - 1 k 1 i >= 0 i 0 i-- i-- i arr[2].push(c[i]); arr[2].push(c[i]) arr[2].push arr[2] arr 2 c[i] c i int cur = 0; cur 0 char ans[] = {'A', 'B', 'C'}; ans {'A', 'B', 'C'} 'A' 'B' 'C' while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        } !arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty() !arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty() !arr[0].isEmpty() arr[0].isEmpty() arr[0].isEmpty arr[0] arr 0 !arr[1].isEmpty() arr[1].isEmpty() arr[1].isEmpty arr[1] arr 1 !arr[2].isEmpty() arr[2].isEmpty() arr[2].isEmpty arr[2] arr 2 {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        } if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            } arr[cur].isEmpty() arr[cur].isEmpty arr[cur] arr cur {
                out.println(ans[cur]);
                return;
            } out.println(ans[cur]) out.println out ans[cur] ans cur return; char ch = arr[cur].pop(); ch arr[cur].pop() arr[cur].pop arr[cur] arr cur cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2) cur (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2) (ch == 'a') ch 'a' 0 ((ch == 'b') ? 1 : 2) (ch == 'b') ch 'b' 1 2 public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    }
} public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        char a[] = sn().toCharArray();
        char b[] = sn().toCharArray();
        char c[] = sn().toCharArray();
        int n = a.length;
        int m = b.length;
        int k = c.length;
        Stack<Character> arr[] = new Stack[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = new Stack<>();
        }
        for (int i = n - 1; i >= 0; i--)
            arr[0].push(a[i]);
        for (int i = m - 1; i >= 0; i--)
            arr[1].push(b[i]);
        for (int i = k - 1; i >= 0; i--)
            arr[2].push(c[i]);
        int cur = 0;
        char ans[] = {'A', 'B', 'C'};
        while (!arr[0].isEmpty() || !arr[1].isEmpty() || !arr[2].isEmpty()) {
            if (arr[cur].isEmpty()) {
                out.println(ans[cur]);
                return;
            }
            char ch = arr[cur].pop();
            cur = (ch == 'a') ? 0 : ((ch == 'b') ? 1 : 2);
        }

    }
}