#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
    map<char, string> str_map;
    cin >> str_map['a'];
    cin >> str_map['b'];
    cin >> str_map['c'];

    char index = 'a';
    char tmp_char;

    while (true) {
        tmp_char = str_map[index][0];
        str_map[index].erase(str_map[index].begin());
        index = tmp_char;
        if (str_map['a'].empty() || str_map['b'].empty() || str_map['c'].empty()) {
            break;
        }

    }

    while (true) {
        if (str_map[index].empty()) {
            cout << char(index - 32) << endl;
            break;
        }
        tmp_char = str_map[index][0];
        str_map[index].erase(str_map[index].begin());
        index = tmp_char;
    }

    return 0;
}