import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    }
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    }
} Main public static void main(String[] args){
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    } main {
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    } Scanner x = new Scanner(System.in); x new Scanner(System.in) String sa = x.next(); sa x.next() x.next x String sb = x.next(); sb x.next() x.next x String sc = x.next(); sc x.next() x.next x int ca = 0; ca 0 int cb = 0; cb 0 int cc = 0; cc 0 int turn = 0; turn 0 while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      } true {
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      } if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        } turn==0 turn 0 {
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        } if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2; sa.substring(ca,ca+1).equals("a") sa.substring(ca,ca+1).equals sa.substring(ca,ca+1) sa.substring sa ca ca+1 ca 1 "a" turn=0 turn 0 if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2; sa.substring(ca,ca+1).equals("b") sa.substring(ca,ca+1).equals sa.substring(ca,ca+1) sa.substring sa ca ca+1 ca 1 "b" turn=1 turn 1 turn = 2 turn 2 ca++ ca if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        } turn==1 turn 1 {
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        } if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2; sb.substring(cb,cb+1).equals("a") sb.substring(cb,cb+1).equals sb.substring(cb,cb+1) sb.substring sb cb cb+1 cb 1 "a" turn=0 turn 0 if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2; sb.substring(cb,cb+1).equals("b") sb.substring(cb,cb+1).equals sb.substring(cb,cb+1) sb.substring sb cb cb+1 cb 1 "b" turn=1 turn 1 turn = 2 turn 2 cb++ cb if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        } turn==2 turn 2 {
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        } if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2; sc.substring(cc,cc+1).equals("a") sc.substring(cc,cc+1).equals sc.substring(cc,cc+1) sc.substring sc cc cc+1 cc 1 "a" turn=0 turn 0 if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2; sc.substring(cc,cc+1).equals("b") sc.substring(cc,cc+1).equals sc.substring(cc,cc+1) sc.substring sc cc cc+1 cc 1 "b" turn=1 turn 1 turn = 2 turn 2 cc++ cc if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        } ca==sa.length()&&turn==0 ca==sa.length() ca sa.length() sa.length sa turn==0 turn 0 {
        	System.out.println("A");
          return;
        } System.out.println("A") System.out.println System.out System System.out "A" return; if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        } cb==sb.length()&&turn==1 cb==sb.length() cb sb.length() sb.length sb turn==1 turn 1 {
        	System.out.println("B");
          return;
        } System.out.println("B") System.out.println System.out System System.out "B" return; if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        } cc==sc.length()&&turn==2 cc==sc.length() cc sc.length() sc.length sc turn==2 turn 2 {
        	System.out.println("C");
          return;
        } System.out.println("C") System.out.println System.out System System.out "C" return; String[] args args public class Main{
	public static void main(String[] args){
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    }
} public class Main{
	public static void main(String[] args){
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    }
} Main
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner x = new Scanner(System.in);
      String sa = x.next();
      String sb = x.next();
      String sc = x.next();
      int ca = 0;
      int cb = 0;
      int cc = 0;
      int turn = 0;
      while(true){
      	if(turn==0){
          if(sa.substring(ca,ca+1).equals("a"))turn=0;
          else if(sa.substring(ca,ca+1).equals("b"))turn=1;
          else turn = 2;
          ca++;
        }
        else if(turn==1){
          if(sb.substring(cb,cb+1).equals("a"))turn=0;
          else if(sb.substring(cb,cb+1).equals("b"))turn=1;
          else turn = 2;
          cb++;
        }
        else if(turn==2){
          if(sc.substring(cc,cc+1).equals("a"))turn=0;
          else if(sc.substring(cc,cc+1).equals("b"))turn=1;
          else turn = 2;
          cc++;
        }
        if(ca==sa.length()&&turn==0){
        	System.out.println("A");
          return;
        }
        if(cb==sb.length()&&turn==1){
        	System.out.println("B");
          return;
        }
        if(cc==sc.length()&&turn==2){
        	System.out.println("C");
          return;
        }
      }
    }
}