import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    String[] p = new String[3];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.println(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.Map; Map java.util import java.util.HashMap; HashMap java.util public class Main
{
    String[] p = new String[3];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.println(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
} Main String[] p = new String[3]; p new String[3] 3 public static void main(String args[])
    {
	new Main().solve();
    } main {
	new Main().solve();
    } new Main().solve() new Main().solve new Main() String args[] args void solve()
    {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    } solve {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    } in() in char[] abc = {'A', 'B', 'C'}; abc {'A', 'B', 'C'} 'A' 'B' 'C' int t = 0; t 0 while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	} p[t].length() > 0 p[t].length() p[t].length p[t] p t 0 {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	} char c = p[t].charAt(0); c p[t].charAt(0) p[t].charAt p[t] p t 0 p[t] = p[t].substring(1, p[t].length()) p[t] p t p[t].substring(1, p[t].length()) p[t].substring p[t] p t 1 p[t].length() p[t].length p[t] p t if(c == 'a') t = 0; c == 'a' c 'a' t = 0 t 0 if(c == 'b') t = 1; c == 'b' c 'b' t = 1 t 1 if(c == 'c') t = 2; c == 'c' c 'c' t = 2 t 2 out(abc[t]) out abc[t] abc t void in()
    {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    } in {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) p[0] = sc.next() p[0] p 0 sc.next() sc.next sc p[1] = sc.next() p[1] p 1 sc.next() sc.next sc p[2] = sc.next() p[2] p 2 sc.next() sc.next sc void out()
    {
	
    } out {
	
    } void out(int n)
    {
	System.out.println(n);
    } out {
	System.out.println(n);
    } System.out.println(n) System.out.println System.out System System.out n int n n void out(double n)
    {
	System.out.println(n);
    } out {
	System.out.println(n);
    } System.out.println(n) System.out.println System.out System System.out n double n n void out(long n)
    {
	System.out.println(n);
    } out {
	System.out.println(n);
    } System.out.println(n) System.out.println System.out System System.out n long n n void out(char c)
    {
	System.out.println(c);
    } out {
	System.out.println(c);
    } System.out.println(c) System.out.println System.out System System.out c char c c void out(String s)
    {
	System.out.println(s);
    } out {
	System.out.println(s);
    } System.out.println(s) System.out.println System.out System System.out s String s s public class Main
{
    String[] p = new String[3];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.println(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
} public class Main
{
    String[] p = new String[3];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.println(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
} Main
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    String[] p = new String[3];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	char[] abc = {'A', 'B', 'C'};

	int t = 0;
	while(p[t].length() > 0) {
	    char c = p[t].charAt(0);
	    p[t] = p[t].substring(1, p[t].length());
	    if(c == 'a') t = 0;
	    if(c == 'b') t = 1;
	    if(c == 'c') t = 2;
	}

	out(abc[t]);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	p[0] = sc.next();
	p[1] = sc.next();
	p[2] = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.println(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}
