#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map>
#include<stdio.h>
#include<queue>
#include<tuple>

#define ALL(a)  (a).begin(),(a).end()
const long long MOD = 1e9+7;

//いろんなstlの使い方　https://qiita.com/tukejonny/items/f4013547df761a0b3523
//http://y-mazun.hatenablog.com/entry/20111202/1322840281



using namespace std;


long long gcd(long long a, long long b) {
    if (a > b) {
        return gcd(b, a);
    }
    return a == 0 ? b : gcd(b % a, a);
}

int lcm(int m, int n) {
    // 引数に０がある場合は０を返す
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int moji(char in) {
    int ans = (int) in - (int) 'a';
    if ((ans < 0) || (ans > 25)) {
        ans = 26;
    }
    return ans;
}


int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int *) a - *(int *) b;
}



template<class T>
void chmin(T &a, T b) {
    if (a > b) {
        a = b;
    }
}

//formerは前方のindex(自分自身を含んで良い)
template<class T>
int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}

//latterは後方のindex(自分自身を含んで良い)
template<class T>
int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}



//indexを用いてvectorから要素削除
template<typename T>
void remove(std::vector<T> &vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}

typedef long long ll;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[i*2+1],node[i*2+2]);
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] = max(lazy[k],node[k]);
            if(r - l > 1) {
                lazy[2*k+1] = max(lazy[k],lazy[2*k+1]);
                lazy[2*k+2] = max(lazy[k],lazy[2*k+2]);
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = max(node[2*k+1],node[2*k+2]);
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
    ll getpoint(int a){
        return node[n-1+a];


    }
    void kaiji(){
        for(int i=0;i<node.size();i++){
            cout<<node[i]<<endl;
        }
    }


};

int main() {
    string Sa,Sb,Sc;
    cin>>Sa>>Sb>>Sc;
    int a=0;
    int b=0;
    int c=0;
    a++;
    char now=Sa[0];
    while(a<=Sa.size()&&b<=Sb.size()&&c<=Sc.size()){
        if(now=='a'){
            now=Sa[a];
            a++;
        }else if(now=='b'){
            now=Sb[b];
            b++;

        }else{
            now=Sc[c];
            c++;
        }


    }
    if(a==Sa.size()+1){
        cout<<'A'<<endl;
    }else if(b==Sb.size()+1){
        cout<<'B'<<endl;
    }else{
        cout<<'C'<<endl;
    }




    }
















Measured memory_bytes: 256