import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    } main {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    } Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int a_count = 0 a_count 0 b_count = 0 b_count 0 c_count = 0; c_count 0 String a = in.next(); a in.next() in.next in String b = in.next(); b in.next() in.next in String c = in.next(); c in.next() in.next in char next = a.charAt(a_count); next a.charAt(a_count) a.charAt a a_count a_count++ a_count boolean notEmpty = true; notEmpty true while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        } notEmpty {
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        } if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            } next == 'a' next 'a' {
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            } if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                } a_count == a.length() a_count a.length() a.length a {
                    System.out.println('A');
                    return;
                } System.out.println('A') System.out.println System.out System System.out 'A' return; {
                    next = a.charAt(a_count);
                    a_count++;
                } next = a.charAt(a_count) next a.charAt(a_count) a.charAt a a_count a_count++ a_count if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            } next == 'b' next 'b' {
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            } if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                } b_count == b.length() b_count b.length() b.length b {
                    System.out.println('B');
                    return;
                } System.out.println('B') System.out.println System.out System System.out 'B' return; {
                    next = b.charAt(b_count);
                    b_count++;
                } next = b.charAt(b_count) next b.charAt(b_count) b.charAt b b_count b_count++ b_count {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            } if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                } c_count == c.length() c_count c.length() c.length c {
                    System.out.println('C');
                    return;
                } System.out.println('C') System.out.println System.out System System.out 'C' return; {
                    next = c.charAt(c_count);
                    c_count++;
                } next = c.charAt(c_count) next c.charAt(c_count) c.charAt c c_count c_count++ c_count String[] args args public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a_count = 0, b_count = 0, c_count = 0;
        String a = in.next();
        String b = in.next();
        String c = in.next();
        char next = a.charAt(a_count);
        a_count++;
        boolean notEmpty = true;
        while (notEmpty){
            if (next == 'a'){
                if (a_count == a.length()){
                    System.out.println('A');
                    return;
                }
                else{
                    next = a.charAt(a_count);
                    a_count++;
                }
            }
            else if (next == 'b'){
                if (b_count == b.length()){
                    System.out.println('B');
                    return;
                }
                else{
                    next = b.charAt(b_count);
                    b_count++;
                }
            }
            else {
                if (c_count == c.length()){
                    System.out.println('C');
                    return;
                }
                else{
                    next = c.charAt(c_count);
                    c_count++;
                }
            }
        }
    }
}