import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    3.rep!(() => readln.chomp.map!(c => c-'a').pipe!(str => DList!int(str))).pipe!((ary) {
        int now = 0;
        while(!ary[now].empty) {
            int tmp = ary[now].front;
            ary[now].removeFront;
            now = tmp;
        }
        return now;
    }).pipe!(i => "ABC"[i]).writeln;
}
