import java.util.*;
public class Main {
  
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();
    public static List<String> c = new ArrayList<>();
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
    public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    }
} import java.util.*; util.* java public class Main {
  
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();
    public static List<String> c = new ArrayList<>();
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
    public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    }
} Main public static List<String> a = new ArrayList<>(); a new ArrayList<>() public static List<String> b = new ArrayList<>(); b new ArrayList<>() public static List<String> c = new ArrayList<>(); c new ArrayList<>() public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) a.addAll(Arrays.asList(sc.next().split(""))) a.addAll a Arrays.asList(sc.next().split("")) Arrays.asList Arrays sc.next().split("") sc.next().split sc.next() sc.next sc "" b.addAll(Arrays.asList(sc.next().split(""))) b.addAll b Arrays.asList(sc.next().split("")) Arrays.asList Arrays sc.next().split("") sc.next().split sc.next() sc.next sc "" c.addAll(Arrays.asList(sc.next().split(""))) c.addAll c Arrays.asList(sc.next().split("")) Arrays.asList Arrays sc.next().split("") sc.next().split sc.next() sc.next sc "" String lastValue = "a"; lastValue "a" String ans = ""; ans "" while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        } true {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        } lastValue = syori(lastValue) lastValue syori(lastValue) syori lastValue if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          } Character.isUpperCase(lastValue.charAt(0)) Character.isUpperCase Character lastValue.charAt(0) lastValue.charAt lastValue 0 {
            ans = lastValue;
            break;
          } ans = lastValue ans lastValue break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    } syori {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    } String next = ""; next "" switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      } value case "a" : "a" case "a" : if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          } a.size() == 0 a.size() a.size a 0 {
            next = "A";
          } next = "A" next "A" {
            next = a.get(0);
            a.remove(0);
          } next = a.get(0) next a.get(0) a.get a 0 a.remove(0) a.remove a 0 break; case "b" : "b" case "b" : if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          } b.size() == 0 b.size() b.size b 0 {
            next = "B";
          } next = "B" next "B" {
            next = b.get(0);
            b.remove(0);
          } next = b.get(0) next b.get(0) b.get b 0 b.remove(0) b.remove b 0 break; case "c" : "c" case "c" : if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          } c.size() == 0 c.size() c.size c 0 {
            next = "C";
          } next = "C" next "C" {
            next = c.get(0);
            c.remove(0);
          } next = c.get(0) next c.get(0) c.get c 0 c.remove(0) c.remove c 0 break; return next; next String value value public class Main {
  
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();
    public static List<String> c = new ArrayList<>();
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
    public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    }
} public class Main {
  
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();
    public static List<String> c = new ArrayList<>();
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
    public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    }
} Main
import java.util.*;
public class Main {
  
    public static List<String> a = new ArrayList<>();
    public static List<String> b = new ArrayList<>();
    public static List<String> c = new ArrayList<>();
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		a.addAll(Arrays.asList(sc.next().split("")));
        b.addAll(Arrays.asList(sc.next().split("")));
        c.addAll(Arrays.asList(sc.next().split("")));
       
        String lastValue = "a";
        String ans = "";
        while(true) {
          lastValue = syori(lastValue);
          if(Character.isUpperCase(lastValue.charAt(0))) {
            ans = lastValue;
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
    public static String syori(String value) {
      String next = "";
      switch (value) {
        case "a" :
          if (a.size() == 0) {
            next = "A";
          } else {
            next = a.get(0);
            a.remove(0);
          }
          break;
        case "b" :
          if (b.size() == 0) {
            next = "B";
          } else {
            next = b.get(0);
            b.remove(0);
          }
          break;
        case "c" :
          if (c.size() == 0) {
            next = "C";
          } else {
            next = c.get(0);
            c.remove(0);
          }
          break;
      }
      return next;
    }
}