import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  } main {
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String str[] = new String[3]; str new String[3] 3 int count[] = new int[3]; count new int[3] 3 for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    } int i = 0 ; int i = 0 ; i 0 i < 3 i 3 ++i ++i i {
      str[i] = sc.next();
      count[i] = str[i].length();
    } {
      str[i] = sc.next();
      count[i] = str[i].length();
    } str[i] = sc.next() str[i] str i sc.next() sc.next sc count[i] = str[i].length() count[i] count i str[i].length() str[i].length str[i] str i int i = 0; i 0 while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    } true {    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    } if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      } count[i]==0&&i==0 count[i]==0 count[i] count i 0 i==0 i 0 {
        System.out.println("A");
        return;
      } System.out.println("A") System.out.println System.out System System.out "A" return; if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      } count[i]==0&&i==1 count[i]==0 count[i] count i 0 i==1 i 1 {
        System.out.println("B");
        return;
      } System.out.println("B") System.out.println System.out System System.out "B" return; if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      } count[i]==0&&i==2 count[i]==0 count[i] count i 0 i==2 i 2 {
        System.out.println("C");
        return;
      } System.out.println("C") System.out.println System.out System System.out "C" return; if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      } str[i].charAt(str[i].length()-count[i])=='a' str[i].charAt(str[i].length()-count[i]) str[i].charAt str[i] str i str[i].length()-count[i] str[i].length() str[i].length str[i] str i count[i] count i 'a' {
        count[i]--;
        i=0;
      } count[i]-- count[i] count i i=0 i 0 if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      } str[i].charAt(str[i].length()-count[i])=='b' str[i].charAt(str[i].length()-count[i]) str[i].charAt str[i] str i str[i].length()-count[i] str[i].length() str[i].length str[i] str i count[i] count i 'b' {
        count[i]--;
        i=1;
      } count[i]-- count[i] count i i=1 i 1 if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      } str[i].charAt(str[i].length()-count[i])=='c' str[i].charAt(str[i].length()-count[i]) str[i].charAt str[i] str i str[i].length()-count[i] str[i].length() str[i].length str[i] str i count[i] count i 'c' {
        count[i]--;
        i=2;
      } count[i]-- count[i] count i i=2 i 2 String[] args args public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  }
} public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  }
} Main
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    /*
    a = 0
    b = 1
    c = 2
    */
    
    String str[] = new String[3];
    int count[] = new int[3];
    for(int i = 0 ; i < 3 ; ++i){
      str[i] = sc.next();
      count[i] = str[i].length();
    }
	
    //最初はAさん
    int i = 0;
    
    while(true){    
 
      //あがりの人いるかな
      if(count[i]==0&&i==0){
        System.out.println("A");
        return;
      }else if(count[i]==0&&i==1){
        System.out.println("B");
        return;
      }else if(count[i]==0&&i==2){
        System.out.println("C");
        return;
      }

      //次の人誰かな
      if(str[i].charAt(str[i].length()-count[i])=='a'){
        count[i]--;
        i=0;
      }else if(str[i].charAt(str[i].length()-count[i])=='b'){
        count[i]--;
        i=1;
      }else if(str[i].charAt(str[i].length()-count[i])=='c'){
        count[i]--;
        i=2;
      }
      
      /*カードぽいっ
      count[i]--;*/
 
    }

  }
}