import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    }
} import java.util.*; util.* java public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String aStr = sc.next(); aStr sc.next() sc.next sc String bStr = sc.next(); bStr sc.next() sc.next sc String cStr = sc.next(); cStr sc.next() sc.next sc char curChar = 'a'; curChar 'a' int i = 0 i 0 j = 0 j 0 k = 0; k 0 while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        } true {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        } if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          } curChar == 'a' curChar 'a' {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } if(i == aStr.length()) {
              System.out.println("A");
              return;
            } i == aStr.length() i aStr.length() aStr.length aStr {
              System.out.println("A");
              return;
            } System.out.println("A") System.out.println System.out System System.out "A" return; curChar = aStr.charAt(i++) curChar aStr.charAt(i++) aStr.charAt aStr i++ i if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          } curChar == 'b' curChar 'b' {
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } if(j == bStr.length()) {
              System.out.println("B");
              return;
            } j == bStr.length() j bStr.length() bStr.length bStr {
              System.out.println("B");
              return;
            } System.out.println("B") System.out.println System.out System System.out "B" return; curChar = bStr.charAt(j++) curChar bStr.charAt(j++) bStr.charAt bStr j++ j {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          } if(k == cStr.length()) {
              System.out.println("C");
              return;
            } k == cStr.length() k cStr.length() cStr.length cStr {
              System.out.println("C");
              return;
            } System.out.println("C") System.out.println System.out System System.out "C" return; curChar = cStr.charAt(k++) curChar cStr.charAt(k++) cStr.charAt cStr k++ k String[] args args public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    }
} public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    }
} Main
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();
        char curChar = 'a';
        int i = 0, j = 0, k = 0;
        while(true) {
          if(curChar == 'a') {
            if(i == aStr.length()) {
              System.out.println("A");
              return;
            }
            curChar = aStr.charAt(i++);
          } else if(curChar == 'b'){
            if(j == bStr.length()) {
              System.out.println("B");
              return;
            }
            curChar = bStr.charAt(j++);
          } else {
            if(k == cStr.length()) {
              System.out.println("C");
              return;
            }
            curChar = cStr.charAt(k++);
          }
        }
    }
}