import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String alice = sc.next(); alice sc.next() sc.next sc String bob = sc.next(); bob sc.next() sc.next sc String charlie = sc.next(); charlie sc.next() sc.next sc int a a b b c; c a = b = c = 0 a b = c = 0 b c = 0 c 0 int turn = 1; turn 1 while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        } true {
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        } if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            } turn == 1 turn 1 {
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            } if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                } a == alice.length() a alice.length() alice.length alice {
                    System.out.println('A');
                    break;
                } System.out.println('A') System.out.println System.out System System.out 'A' break; {
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                } if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3; alice.charAt(a) == 'a' alice.charAt(a) alice.charAt alice a 'a' turn = 1 turn 1 if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3; alice.charAt(a) == 'b' alice.charAt(a) alice.charAt alice a 'b' turn = 2 turn 2 turn = 3 turn 3 a += 1 a 1 if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            } turn == 2 turn 2 {
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            } if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                } b == bob.length() b bob.length() bob.length bob {
                    System.out.println('B');
                    break;
                } System.out.println('B') System.out.println System.out System System.out 'B' break; {
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                } if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3; bob.charAt(b) == 'a' bob.charAt(b) bob.charAt bob b 'a' turn = 1 turn 1 if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3; bob.charAt(b) == 'b' bob.charAt(b) bob.charAt bob b 'b' turn = 2 turn 2 turn = 3 turn 3 b += 1 b 1 {
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            } if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                } c == charlie.length() c charlie.length() charlie.length charlie {
                    System.out.println('C');
                    break;
                } System.out.println('C') System.out.println System.out System System.out 'C' break; {
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                } if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3; charlie.charAt(c) == 'a' charlie.charAt(c) charlie.charAt charlie c 'a' turn = 1 turn 1 if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3; charlie.charAt(c) == 'b' charlie.charAt(c) charlie.charAt charlie c 'b' turn = 2 turn 2 turn = 3 turn 3 c += 1 c 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    }
}
