void main() {
    string[dchar] s;
    s['a'] = readln.chomp;
    s['b'] = readln.chomp;
    s['c'] = readln.chomp;
    dchar now = 'a';
    dchar ans;
    while (true) {
        dchar tmp = s[now][0];
        s[now] = s[now][1..$];
        now = tmp;
        if (s[now].length == 0) {
            ans = tmp;
            break;
        }
    }
    ans.toUpper.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;