import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    }
} import java.io.InputStream; InputStream java.io import java.io.OutputStream; OutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) 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 int i = a.length(); i a.length() a.length a int j = b.length(); j b.length() b.length b int k = c.length(); k c.length() c.length c int i1=-1; i1 -1 1 int i2=-1; i2 -1 1 int i3 =-1; i3 -1 1 int next = 0; next 0 while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        } true {
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        } if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            } next==0 next 0 {
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            } i1++ i1 if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                } i1==i i1 i {
                    System.out.println("A");
                    break;
                } System.out.println("A") System.out.println System.out System System.out "A" break; {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                } if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    } a.charAt(i1)=='a' a.charAt(i1) a.charAt a i1 'a' {
                        next=0;
                    } next=0 next 0 if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    } a.charAt(i1)=='b' a.charAt(i1) a.charAt a i1 'b' {
                        next=1;
                    } next=1 next 1 {
                        next=2;
                    } next=2 next 2 if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            } next==1 next 1 {
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            } i2++ i2 if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                } i2==j i2 j {
                    System.out.println("B");
                    break;
                } System.out.println("B") System.out.println System.out System System.out "B" break; {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                } if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    } b.charAt(i2)=='a' b.charAt(i2) b.charAt b i2 'a' {
                        next=0;
                    } next=0 next 0 if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    } b.charAt(i2)=='b' b.charAt(i2) b.charAt b i2 'b' {
                        next=1;
                    } next=1 next 1 {
                        next=2;
                    } next=2 next 2 {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            } i3++ i3 if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                } i3==k i3 k {
                    System.out.println("C");
                    break;
                } System.out.println("C") System.out.println System.out System System.out "C" break; {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                } if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    } c.charAt(i3)=='a' c.charAt(i3) c.charAt c i3 'a' {
                        next=0;
                    } next=0 next 0 if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    } c.charAt(i3)=='b' c.charAt(i3) c.charAt c i3 'b' {
                        next=1;
                    } next=1 next 1 {
                        next=2;
                    } next=2 next 2 String[] args args public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    }
} Main
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int i = a.length();
        int j = b.length();
        int k = c.length();
        int i1=-1;int i2=-1;int i3 =-1;
        int next = 0;
        while (true){
            if (next==0){
                i1++;
                if(i1==i){
                    System.out.println("A");
                    break;
                }
                else {
                    if (a.charAt(i1)=='a'){
                        next=0;
                    }
                    else if (a.charAt(i1)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else if (next==1){
                i2++;
                if(i2==j){
                    System.out.println("B");
                    break;
                }
                else {
                    if (b.charAt(i2)=='a'){
                        next=0;
                    }
                    else if (b.charAt(i2)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            else {
                i3++;
                if(i3==k){
                    System.out.println("C");
                    break;
                }
                else {
                    if (c.charAt(i3)=='a'){
                        next=0;
                    }
                    else if (c.charAt(i3)=='b'){
                        next=1;
                    }
                    else {
                        next=2;
                    }
                }
            }
            
        }
    }
}
