#include<bits/stdc++.h>
using namespace std;

// - - - - - - Data Types - - - - - - //

#define SF1(A)              scanf("%d", &A)
#define SF2(A,B)            SF1(A);SF1(B)
#define SF3(A,B,C)          SF2(A,B);SF1(C)

typedef long long int LLI;
#define SL1(A)              scanf("%lld", &A)
#define SL2(A,B)            SL1(A);SL1(B)
#define SL3(A,B,C)          SL2(A,B);SL1(C)

typedef long int LI;
typedef long long LL;

#define SD1(A)              scanf("%lf", &A)
#define SD2(A,B)            SD1(A);SD1(B)
#define SD3(A,B,C)          SD2(A,B);SD1(C)

// - - - - - - Vectors - - - - - - //
typedef vector<int> VI;
typedef vector<LLI> VLLI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef vector<VI> VVI;

#define scanVI(V, N)        for(int I=0; I<N; I++){ int X; SF1(X); V.PB(X); }
#define scanVLLI(V, N)      for(int I=0; i<N; I++){ LLI X; SL1(X); V.PB(X); }
#define scanVS(V, N)        for(int I=0; i<N; I++){ string X; cin >> X; V.PB(X); }
#define scanVD(V, N)        for(int I=0; i<N; I++){ double X; SD1(X); V.PB(X); }

// - - - - - - Maps - - - - - - //
typedef map<int, int> MII;
typedef map<int, string> MIS;
typedef map<int, char> MIC;
typedef map<string, int> MSI;
typedef map<char, int> MCI;
typedef map<int, VI> MIVI;

// - - - - - - Pairs - - - - - - //
typedef pair<int, int> PII;
typedef pair<string, string> PSS;
typedef pair<char, char> PCC;
typedef pair<int, string> PIS;
typedef pair<int, char> PIC;
typedef pair<string, char> PSC;

// - - - - - - Sets - - - - - - //
typedef set<int> SI;
typedef set<LLI> SLLI;
typedef set<string> SS;
typedef set<char> SC;
// - - - - - - - - - - - - - - - - - - //

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define PF                  printf
#define PB                  push_back
#define POP                 pop_back()
#define PP                  prev_permutation
#define NP                  next_permutation
#define MP                  make_pair
#define CLRN(a, b)          memset(a, b, sizeof(a))
#define CLR(a)              memset(a, 0, sizeof(a))
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define BSRCN(a, n, x)      binary_search(ALLN(a, n), x)
#define BSRC(a, z)          binary_search(ALL(a), z)
#define MAX                 10000007
#define MIN                 -10000007
#define PI                  acos(-1)
#define BR                  PF("\n")
#define FastIO              { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr); }
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define IO                  READ(); WRITE();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
/*----------------------Graph Moves----------------*/
int ROW[]={+1,-1,+0,+0};
int COL[]={+0,+0,+1,-1};

int X[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
int Y[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

int KX[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
int KY[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
int LCM(int a, int b) { return a * (b/GCD(a, b)); }
bool CMP(int a, int b) { return a>b; }
template<class T>inline bool fastread(T &x) {
        int c=getchar(); int sgn=1; while(~c&&c<'0'||c>'9'){ if(c=='-')sgn=-1; c=getchar(); }
        for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar()) x=x*10+c-'0'; x*=sgn; return ~c;
    }

//clock_t Start=clock(); void Time(){ printf("\n>>Runtime: %.10fs\n", (double) (clock() - Start) / CLOCKS_PER_SEC); }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - END - - - - - - - - - - - - - - - - - - - - - - - - - //

deque< char > a, b, c;

char alice();
char bob();
char charlie();

int main()
{
    while(1)
    {
        char ch; scanf("%c", &ch);

        if(ch >= 'a' and ch <= 'z') a.push_back(ch);
        else break;
    }

    while(1)
    {
        char ch; scanf("%c", &ch);

        if(ch >= 'a' and ch <= 'z') b.push_back(ch);
        else break;
    }

    while(1)
    {
        char ch; scanf("%c", &ch);

        if(ch >= 'a' and ch <= 'z') c.push_back(ch);
        else break;
    }

    cout << alice() << endl;

    return 0;
}

char alice()
{
    if(a.empty()) return 'A';

    if(a[0] == 'a')
    {
        a.pop_front();
        return alice();
    }

    else if(a[0] == 'b')
    {
        a.pop_front();
        return bob();
    }

    else if(a[0] == 'c')
    {
        a.pop_front();
        return charlie();
    }
}

char bob()
{
    if(b.empty()) return 'B';

    if(b[0] == 'a')
    {
        b.pop_front();
        return alice();
    }

    else if(b[0] == 'b')
    {
        b.pop_front();
        return bob();
    }

    else if(b[0] == 'c')
    {
        b.pop_front();
        return charlie();
    }
}

char charlie()
{
    if(c.empty()) return 'C';

    if(c[0] == 'a')
    {
        c.pop_front();
        return alice();
    }

    else if(c[0] == 'b')
    {
        c.pop_front();
        return bob();
    }

    else if(c[0] == 'c')
    {
        c.pop_front();
        return charlie();
    }
}



Measured memory_bytes: 256