import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    } main {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) String sa = in.next(); sa in.next() in.next in String sb = in.next(); sb in.next() in.next in String sc = in.next(); sc in.next() in.next in Deque<Character> a = new ArrayDeque<Character>(); a new ArrayDeque<Character>() Deque<Character> b = new ArrayDeque<Character>(); b new ArrayDeque<Character>() Deque<Character> c = new ArrayDeque<Character>(); c new ArrayDeque<Character>() for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        } int i = 0; int i = 0; i 0 i < sa.length() i sa.length() sa.length sa i++ i++ i {
            a.addLast(sa.charAt(i));
        } {
            a.addLast(sa.charAt(i));
        } a.addLast(sa.charAt(i)) a.addLast a sa.charAt(i) sa.charAt sa i for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        } int i = 0; int i = 0; i 0 i < sb.length() i sb.length() sb.length sb i++ i++ i {
            b.addLast(sb.charAt(i));
        } {
            b.addLast(sb.charAt(i));
        } b.addLast(sb.charAt(i)) b.addLast b sb.charAt(i) sb.charAt sb i for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        } int i = 0; int i = 0; i 0 i < sc.length() i sc.length() sc.length sc i++ i++ i {
            c.addLast(sc.charAt(i));
        } {
            c.addLast(sc.charAt(i));
        } c.addLast(sc.charAt(i)) c.addLast c sc.charAt(i) sc.charAt sc i char turn = 'a'; turn 'a' char winner = 'A'; winner 'A' while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        } true {
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        } if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            } turn == 'a' turn 'a' {
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            } if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                } a.isEmpty() a.isEmpty a {
                    winner = 'A';
                    break;
                } winner = 'A' winner 'A' break; {
                    turn = a.removeFirst();
                } turn = a.removeFirst() turn a.removeFirst() a.removeFirst a if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            } turn == 'b' turn 'b' {
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            } if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                } b.isEmpty() b.isEmpty b {
                    winner = 'B';
                    break;
                } winner = 'B' winner 'B' break; {
                    turn = b.removeFirst();
                } turn = b.removeFirst() turn b.removeFirst() b.removeFirst b {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            } if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                } c.isEmpty() c.isEmpty c {
                    winner = 'C';
                    break;
                } winner = 'C' winner 'C' break; {
                    turn = c.removeFirst();
                } turn = c.removeFirst() turn c.removeFirst() c.removeFirst c System.out.println(winner) System.out.println System.out System System.out winner String[] args args public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    }
} public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String sa = in.next();
        String sb = in.next();
        String sc = in.next();
        Deque<Character> a = new ArrayDeque<Character>();
        Deque<Character> b = new ArrayDeque<Character>();
        Deque<Character> c = new ArrayDeque<Character>();
        
        for (int i = 0; i < sa.length(); i++) {
            a.addLast(sa.charAt(i));
        }
        for (int i = 0; i < sb.length(); i++) {
            b.addLast(sb.charAt(i));
        }
        for (int i = 0; i < sc.length(); i++) {
            c.addLast(sc.charAt(i));
        }
        
        char turn = 'a';
        char winner = 'A';
        
        while(true){
            if(turn == 'a'){
                if(a.isEmpty()){
                    winner = 'A';
                    break;
                }
                else{
                    turn = a.removeFirst();
                }
            }
            else if(turn == 'b'){
                if(b.isEmpty()){
                    winner = 'B';
                    break;
                }
                else{
                    turn = b.removeFirst();
                }
            }
            else {
                if(c.isEmpty()){
                    winner = 'C';
                    break;
                }
                else{
                    turn = c.removeFirst();
                }
            }
            
        }
        System.out.println(winner);
    }
}
