import java.util.*;

class Main{
    public static void main(String[] arg){
      Scanner sc = new Scanner(System.in);
      String A = sc.nextLine();
      String B = sc.nextLine();
      String C = sc.nextLine();
      char[] listA = A.toCharArray();
      char[] listB = B.toCharArray();
      char[] listC = C.toCharArray();
      int a = 0;int b = 0;int c = 0;
      char now = listA[0];
      a = 1;
      while(true){
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      }

    }
} import java.util.*; util.* java class Main{
    public static void main(String[] arg){
      Scanner sc = new Scanner(System.in);
      String A = sc.nextLine();
      String B = sc.nextLine();
      String C = sc.nextLine();
      char[] listA = A.toCharArray();
      char[] listB = B.toCharArray();
      char[] listC = C.toCharArray();
      int a = 0;int b = 0;int c = 0;
      char now = listA[0];
      a = 1;
      while(true){
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      }

    }
} Main public static void main(String[] arg){
      Scanner sc = new Scanner(System.in);
      String A = sc.nextLine();
      String B = sc.nextLine();
      String C = sc.nextLine();
      char[] listA = A.toCharArray();
      char[] listB = B.toCharArray();
      char[] listC = C.toCharArray();
      int a = 0;int b = 0;int c = 0;
      char now = listA[0];
      a = 1;
      while(true){
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      }

    } main {
      Scanner sc = new Scanner(System.in);
      String A = sc.nextLine();
      String B = sc.nextLine();
      String C = sc.nextLine();
      char[] listA = A.toCharArray();
      char[] listB = B.toCharArray();
      char[] listC = C.toCharArray();
      int a = 0;int b = 0;int c = 0;
      char now = listA[0];
      a = 1;
      while(true){
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.nextLine(); A sc.nextLine() sc.nextLine sc String B = sc.nextLine(); B sc.nextLine() sc.nextLine sc String C = sc.nextLine(); C sc.nextLine() sc.nextLine sc char[] listA = A.toCharArray(); listA A.toCharArray() A.toCharArray A char[] listB = B.toCharArray(); listB B.toCharArray() B.toCharArray B char[] listC = C.toCharArray(); listC C.toCharArray() C.toCharArray C int a = 0; a 0 int b = 0; b 0 int c = 0; c 0 char now = listA[0]; now listA[0] listA 0 a = 1 a 1 while(true){
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      } true {
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      } switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        } now case 'a': 'a' case 'a': if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            } a == listA.length a listA.length listA listA.length {
              System.out.println("A");
              System.exit(0);
            } System.out.println("A") System.out.println System.out System System.out "A" System.exit(0) System.exit System 0 now = listA[a] now listA[a] listA a a++ a break; case 'b': 'b' case 'b': if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            } b == listB.length b listB.length listB listB.length {
              System.out.println("B");
              System.exit(0);
            } System.out.println("B") System.out.println System.out System System.out "B" System.exit(0) System.exit System 0 now = listB[b] now listB[b] listB b b++ b break; case 'c': 'c' case 'c': if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            } c == listC.length c listC.length listC listC.length {
              System.out.println("C");
              System.exit(0);
            } System.out.println("C") System.out.println System.out System System.out "C" System.exit(0) System.exit System 0 now = listC[c] now listC[c] listC c c++ c break; String[] arg arg
import java.util.*;

class Main{
    public static void main(String[] arg){
      Scanner sc = new Scanner(System.in);
      String A = sc.nextLine();
      String B = sc.nextLine();
      String C = sc.nextLine();
      char[] listA = A.toCharArray();
      char[] listB = B.toCharArray();
      char[] listC = C.toCharArray();
      int a = 0;int b = 0;int c = 0;
      char now = listA[0];
      a = 1;
      while(true){
        switch(now){
          case 'a':
            if(a == listA.length){
              System.out.println("A");
              System.exit(0);
            }
            now = listA[a];
            a++;
            break;
          case 'b':
            if(b == listB.length){
              System.out.println("B");
              System.exit(0);
            }
            now = listB[b];
            b++;
            break;
          case 'c':
            if(c == listC.length){
              System.out.println("C");
              System.exit(0);
            }
            now = listC[c];
            c++;
            break;
        }
      }

    }
}
