#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)

string a26(ll n) {
  string res = "";
  while (n) {
    --n;
    res += (char)('a' + (n % 26));
    n /= 26;
  }
  reverse(res.begin(), res.end());
  return res;
}

ll N;
void input() { cin >> N; }
void solve() { cout << a26(N) << endl; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
}
#include <bits/stdc++.h>
using namespace std;

queue<char> que[3];

int rec(int i){
    if(que[i].empty()) return i;
    char q = que[i].front();
    que[i].pop();
    return rec(q - 'a');
}

int main(){
    for(int i = 0; i < 3; i++){
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            que[i].push(s[j]);
        }
    }
    cout << (char)(rec(0) + 'A') << endl;
    return 0;
}
