import java.util.*;

class Main {
  	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in); 
		char[] as = sc.next().toCharArray(), 
			   bs = sc.next().toCharArray(),
			   cs = sc.next().toCharArray();
      
      	int a = 0, b = 0, c = 0;
      	int w = 'a';
      
      	while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        }
    }
} import java.util.*; util.* java class Main {
  	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in); 
		char[] as = sc.next().toCharArray(), 
			   bs = sc.next().toCharArray(),
			   cs = sc.next().toCharArray();
      
      	int a = 0, b = 0, c = 0;
      	int w = 'a';
      
      	while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        }
    }
} Main static final int INF = Integer.MAX_VALUE; INF Integer.MAX_VALUE Integer Integer.MAX_VALUE public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in); 
		char[] as = sc.next().toCharArray(), 
			   bs = sc.next().toCharArray(),
			   cs = sc.next().toCharArray();
      
      	int a = 0, b = 0, c = 0;
      	int w = 'a';
      
      	while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        }
    } main {
    	Scanner sc = new Scanner(System.in); 
		char[] as = sc.next().toCharArray(), 
			   bs = sc.next().toCharArray(),
			   cs = sc.next().toCharArray();
      
      	int a = 0, b = 0, c = 0;
      	int w = 'a';
      
      	while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] as = sc.next().toCharArray() as sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc bs = sc.next().toCharArray() bs sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc cs = sc.next().toCharArray(); cs sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int a = 0 a 0 b = 0 b 0 c = 0; c 0 int w = 'a'; w 'a' while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        } true {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        } switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            } w case 'a': 'a' case 'a': if (a == as.length) { System.out.println("A"); return; } a == as.length a as.length as as.length { System.out.println("A"); return; } System.out.println("A") System.out.println System.out System System.out "A" return; w = as[a] w as[a] as a a++ a break; case 'b': 'b' case 'b': if (b == bs.length) { System.out.println("B"); return; } b == bs.length b bs.length bs bs.length { System.out.println("B"); return; } System.out.println("B") System.out.println System.out System System.out "B" return; w = bs[b] w bs[b] bs b b++ b break; case 'c': 'c' case 'c': if (c == cs.length) { System.out.println("C"); return; } c == cs.length c cs.length cs cs.length { System.out.println("C"); return; } System.out.println("C") System.out.println System.out System System.out "C" return; w = cs[c] w cs[c] cs c c++ c break; String[] args args
import java.util.*;

class Main {
  	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in); 
		char[] as = sc.next().toCharArray(), 
			   bs = sc.next().toCharArray(),
			   cs = sc.next().toCharArray();
      
      	int a = 0, b = 0, c = 0;
      	int w = 'a';
      
      	while (true) {
        	switch (w) {
              case 'a':
                if (a == as.length) { System.out.println("A"); return; }
                w = as[a];
                a++;
                break;
              case 'b':
                if (b == bs.length) { System.out.println("B"); return; }
                w = bs[b];
                b++;
                break;
              case 'c':
                if (c == cs.length) { System.out.println("C"); return; }
                w = cs[c];
               	c++;	
                break;
            }
        }
    }
}