import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        String t = A;
        while (true) {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.Iterator; Iterator java.util import java.util.Map.Entry; Entry java.util.Map import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        String t = A;
        while (true) {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        }
    }
} Main static final int MOD = 1000000007; MOD 1000000007 static final int INF = 1 << 30; INF 1 << 30 1 30 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        String t = A;
        while (true) {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        String t = A;
        while (true) {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.next(); A sc.next() sc.next sc String B = sc.next(); B sc.next() sc.next sc String C = sc.next(); C sc.next() sc.next sc String t = A; t A while (true) {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        } true {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        } if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            } t == A t A {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } if (t.length() == 0) {
                    System.out.println("A");
                    return;
                } t.length() == 0 t.length() t.length t 0 {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; A = A.substring(1) A A.substring(1) A.substring A 1 if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            } t == B t B {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } if (t.length() == 0) {
                    System.out.println("B");
                    return;
                } t.length() == 0 t.length() t.length t 0 {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; B = B.substring(1) B B.substring(1) B.substring B 1 {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            } if (t.length() == 0) {
                    System.out.println("C");
                    return;
                } t.length() == 0 t.length() t.length t 0 {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; C = C.substring(1) C C.substring(1) C.substring C 1 t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C) t (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C) (t.charAt(0) == 'a') t.charAt(0) t.charAt t 0 'a' A ((t.charAt(0) == 'b') ? B : C) (t.charAt(0) == 'b') t.charAt(0) t.charAt t 0 'b' B C String[] args args
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        String t = A;
        while (true) {
            if (t == A) {
                if (t.length() == 0) {
                    System.out.println("A");
                    return;
                }
                A = A.substring(1);
            } else if (t == B) {
                if (t.length() == 0) {
                    System.out.println("B");
                    return;
                }
                B = B.substring(1);
            } else {
                if (t.length() == 0) {
                    System.out.println("C");
                    return;
                }
                C = C.substring(1);
            }
            // System.out.println(A+" "+B+" "+C);
            // System.out.println(t.charAt(0));
            t = (t.charAt(0) == 'a') ? A : ((t.charAt(0) == 'b') ? B : C);
        }
    }
}
