import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    } main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a[] = sc.next().split(""); a sc.next().split("") sc.next().split sc.next() sc.next sc "" List<String> alist = new ArrayList<>(); alist new ArrayList<>() for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
         alist.add(a[i]);
        } {
         alist.add(a[i]);
        } alist.add(a[i]) alist.add alist a[i] a i String b[] = sc.next().split(""); b sc.next().split("") sc.next().split sc.next() sc.next sc "" List<String> blist = new ArrayList<>(); blist new ArrayList<>() for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        } int i = 0; int i = 0; i 0 i < b.length i b.length b b.length i++ i++ i {
         blist.add(b[i]);
        } {
         blist.add(b[i]);
        } blist.add(b[i]) blist.add blist b[i] b i String c[] = sc.next().split(""); c sc.next().split("") sc.next().split sc.next() sc.next sc "" List<String> clist = new ArrayList<>(); clist new ArrayList<>() for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        } int i = 0; int i = 0; i 0 i < c.length i c.length c c.length i++ i++ i {
         clist.add(c[i]);
        } {
         clist.add(c[i]);
        } clist.add(c[i]) clist.add clist c[i] c i String check = "a"; check "a" try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        } catch(Exception e){
          
          System.out.println(check.toUpperCase());
        } Exception e {
          
          System.out.println(check.toUpperCase());
        } System.out.println(check.toUpperCase()) System.out.println System.out System System.out check.toUpperCase() check.toUpperCase check {
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        } while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          } true {
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          } if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          } check.equals("a") check.equals check "a" {
            check = (String)alist.get(0);
            alist.remove(0);
          } check = (String)alist.get(0) check (String)alist.get(0) alist.get alist 0 alist.remove(0) alist.remove alist 0 if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          } check.equals("b") check.equals check "b" {
            check = (String)blist.get(0);
            blist.remove(0);
          } check = (String)blist.get(0) check (String)blist.get(0) blist.get blist 0 blist.remove(0) blist.remove blist 0 if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          } check.equals("c") check.equals check "c" {
            check = (String)clist.get(0);
            clist.remove(0);
          } check = (String)clist.get(0) check (String)clist.get(0) clist.get clist 0 clist.remove(0) clist.remove clist 0 String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    }
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    }
}