import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  }
} Main public static void main(String[] args){
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  } main {
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  } Scanner sca = new Scanner(System.in); sca new Scanner(System.in) char[] sa = sca.next().toCharArray(); sa sca.next().toCharArray() sca.next().toCharArray sca.next() sca.next sca char[] sb = sca.next().toCharArray(); sb sca.next().toCharArray() sca.next().toCharArray sca.next() sca.next sca char[] sc = sca.next().toCharArray(); sc sca.next().toCharArray() sca.next().toCharArray sca.next() sca.next sca sca.close() sca.close sca int la = sa.length; la sa.length sa sa.length int lb = sb.length; lb sb.length sb sb.length int lc = sc.length; lc sc.length sc sc.length int na = 0; na 0 int nb = 0; nb 0 int nc = 0; nc 0 char nex = 'a'; nex 'a' while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    } true {
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    } if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      } nex =='a' nex 'a' {
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      } if (na==la){
          System.out.println("A");
          break;
        } na==la na la {
          System.out.println("A");
          break;
        } System.out.println("A") System.out.println System.out System System.out "A" break; nex = sa[na++] nex sa[na++] sa na++ na if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      } nex =='b' nex 'b' {
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      } if (nb==lb){
          System.out.println("B");
          break;
        } nb==lb nb lb {
          System.out.println("B");
          break;
        } System.out.println("B") System.out.println System.out System System.out "B" break; nex = sb[nb++] nex sb[nb++] sb nb++ nb {
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      } if (nc==lc){
          System.out.println("C");
          break;
        } nc==lc nc lc {
          System.out.println("C");
          break;
        } System.out.println("C") System.out.println System.out System System.out "C" break; nex = sc[nc++] nex sc[nc++] sc nc++ nc String[] args args public class Main{
  public static void main(String[] args){
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sca = new Scanner(System.in);
    char[] sa = sca.next().toCharArray();
    char[] sb = sca.next().toCharArray();
    char[] sc = sca.next().toCharArray();
    sca.close();
    int la = sa.length;
    int lb = sb.length;
    int lc = sc.length;
    int na = 0;
    int nb = 0;
    int nc = 0;
    char nex = 'a';
    while(true){
      if (nex =='a'){
        if (na==la){
          System.out.println("A");
          break;
        }
        nex = sa[na++];
      }else if (nex =='b'){
        if (nb==lb){
          System.out.println("B");
          break;
        }
        nex = sb[nb++];
      }else{
        if (nc==lc){
          System.out.println("C");
          break;
        }
        nex = sc[nc++];
      }
    }
  }
}