#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  string A,B,C;
  cin>>A>>B>>C;
  
  deque<char> X;
  for(int i=0;i<A.size();i++){
    X.push_back(A[i]);
  }
  
  deque<char> Y;
  for(int i=0;i<B.size();i++){
    Y.push_back(B[i]);
  }
  
  deque<char> Z;
  for(int i=0;i<C.size();i++){
    Z.push_back(C[i]);
  }
  
  int check=1;
  
  string ans;
  
  
  while(true){
    if(check==1){
      if(X.empty()){
       ans="A";
       break;
      }
      if(X.front()=='a'){
        check=1;
        X.pop_front();
      }
      else if(X.front()=='b'){
        check=2;
        X.pop_front();
      }
      else if(X.front()=='c'){
        check=3;
        X.pop_front();
      }
    }
    else if(check==2){
            if(Y.empty()){
        ans="B";
        break;
    }
      if(Y.front()=='a'){
        check=1;
        Y.pop_front();
      }
      else if(Y.front()=='b'){
        check=2;
        Y.pop_front();
      }
      else if(Y.front()=='c'){
        check=3;
        Y.pop_front();
      }
    }
    else if(check==3){
       if(Z.empty()){
        ans="C";
        break;
      }
      if(Z.front()=='a'){
        check=1;
        Z.pop_front();
      }
      else if(Z.front()=='b'){
        check=2;
        Z.pop_front();
      }
      else if(Z.front()=='c'){
        check=3;
        Z.pop_front();
      }
    }
    }
  cout<<ans<<endl;
}
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

bool check(int w, int bit){
    bool ok = true;
    vector<int> a(w);
    rep(i, w){
        if(bit & (1<<i))a[i] = 1;
        else a[i] = 0;
    }
    REP(i, w-1)if(a[i] == a[i-1] && a[i] == 1)ok = false;
    return ok;
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<ll>> dp(h+1, vector<ll>(w, 0));
    dp[0][0] = 1;
    rep(i, h){
        for(int bit = 0; bit < (1<<(w-1)); bit++){
            if(!check(w-1, bit))continue;
            vector<int> to(w);
            rep(j, w)to[j] = j;
            rep(j, w-1){
                if(bit & (1<<j)){
                    to[j] = j+1;
                    to[j+1] = j;
                }
            }
            rep(j, w){
                dp[i+1][to[j]] += dp[i][j];
                dp[i+1][to[j]] %= mod;
            }
        }
    }
    cout << dp[h][k-1] << endl;
}