#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int n;
int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}


void solve() {
   vector<string> a(3);
   cin >> a[0] >> a[1] >> a[2];
   int i = 0,j = 0,k = 0;
   int cur = 0;
   char ans = 'A';
   int c = 0;
   while(true){
       if(i == 0){
           if(a[cur][i] == 'a'){
               cur = 0;
           }else if(a[cur][i] == 'b'){
               cur = 1;
           }else{
               cur = 2;
           }
            i++;
            continue;
       }
       if(cur == 0){
        if(a[cur][i] ==  'a'){
            cur = 0;
        }else if(a[cur][i] == 'b'){
            cur = 1;
        }else{
            cur = 2;
        }
        i++;

       }else if(cur == 1){
           if(a[cur][j] == 'a'){
               cur = 0;
           }else if(a[cur][j] == 'b'){
               cur= 1;
           }else{
               cur = 2;
           }
           j++;

       }else{
            if(a[cur][k] == 'a'){
               cur = 0;
           }else if(a[cur][k] == 'b'){
               cur= 1;
           }else{
               cur = 2;
           }
           k++;
       }

       if(i == a[0].size()+1){
           break;
       }

       if(j == a[1].size()+1){
           ans = 'B';
           break;
       }

       if(k == a[2].size()+1){
           ans = 'C';
           break;
       }
       c++;
   }

   cout << ans << endl;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 256