import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    char[] sa= s.next().toCharArray();
    char[] sb= s.next().toCharArray();
    char[] sc= s.next().toCharArray();

    int i1=0;
    int i2=0;
    int i3=0;
    char next='a';
    while(true) {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    }

  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    char[] sa= s.next().toCharArray();
    char[] sb= s.next().toCharArray();
    char[] sc= s.next().toCharArray();

    int i1=0;
    int i2=0;
    int i3=0;
    char next='a';
    while(true) {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    }

  }
} Main public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    char[] sa= s.next().toCharArray();
    char[] sb= s.next().toCharArray();
    char[] sc= s.next().toCharArray();

    int i1=0;
    int i2=0;
    int i3=0;
    char next='a';
    while(true) {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    }

  } main {
    Scanner s=new Scanner(System.in);
    char[] sa= s.next().toCharArray();
    char[] sb= s.next().toCharArray();
    char[] sc= s.next().toCharArray();

    int i1=0;
    int i2=0;
    int i3=0;
    char next='a';
    while(true) {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    }

  } Scanner s=new Scanner(System.in); s new Scanner(System.in) char[] sa= s.next().toCharArray(); sa s.next().toCharArray() s.next().toCharArray s.next() s.next s char[] sb= s.next().toCharArray(); sb s.next().toCharArray() s.next().toCharArray s.next() s.next s char[] sc= s.next().toCharArray(); sc s.next().toCharArray() s.next().toCharArray s.next() s.next s int i1=0; i1 0 int i2=0; i2 0 int i3=0; i3 0 char next='a'; next 'a' while(true) {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    } true {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    } if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      } next=='a' next 'a' {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      } if(i1==sa.length) {
          System.out.println("A");
          break;
        } i1==sa.length i1 sa.length sa sa.length {
          System.out.println("A");
          break;
        } System.out.println("A") System.out.println System.out System System.out "A" break; next=sa[i1++] next sa[i1++] sa i1++ i1 if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      } next=='b' next 'b' {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      } if(i2==sb.length) {
          System.out.println("B");
          break;
        } i2==sb.length i2 sb.length sb sb.length {
          System.out.println("B");
          break;
        } System.out.println("B") System.out.println System.out System System.out "B" break; next=sb[i2++] next sb[i2++] sb i2++ i2 if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      } next=='c' next 'c' {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      } if(i3==sc.length) {
          System.out.println("C");
          break;
        } i3==sc.length i3 sc.length sc sc.length {
          System.out.println("C");
          break;
        } System.out.println("C") System.out.println System.out System System.out "C" break; next=sc[i3++] next sc[i3++] sc i3++ i3 String[] args args
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner s=new Scanner(System.in);
    char[] sa= s.next().toCharArray();
    char[] sb= s.next().toCharArray();
    char[] sc= s.next().toCharArray();

    int i1=0;
    int i2=0;
    int i3=0;
    char next='a';
    while(true) {
      if(next=='a') {
        if(i1==sa.length) {
          System.out.println("A");
          break;
        }
        next=sa[i1++];
      }

      if(next=='b') {
        if(i2==sb.length) {
          System.out.println("B");
          break;
        }
        next=sb[i2++];
      }

      if(next=='c') {
        if(i3==sc.length) {
          System.out.println("C");
          break;
        }
        next=sc[i3++];
      }
    
      
    }

  }
}