import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7



def ctoi(c):

	return ord(c) - ord('a')



SA = list(input()[::-1])

SB = list(input()[::-1])

SC = list(input()[::-1])

S = [SA, SB, SC]



turn = 0

while S[turn]:

	turn = ctoi(S[turn].pop())

print((ascii_lowercase[turn].upper()))

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7



A = deque(eval(input()))

B = deque(eval(input()))

C = deque(eval(input()))



def DFS(N):

	if not eval(N):

		print(N)

	else:

		p = eval("{}.popleft()".format(N))

		DFS(p.upper())



DFS("A")

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import (
    accumulate,
    permutations,
    combinations,
    product,
    groupby,
    combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7


def ctoi(c):
    return ord(c) - ord("a")


SA = list(input()[::-1])
SB = list(input()[::-1])
SC = list(input()[::-1])
S = [SA, SB, SC]
turn = 0
while S[turn]:
    turn = ctoi(S[turn].pop())
print((ascii_lowercase[turn].upper()))

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import (
    accumulate,
    permutations,
    combinations,
    product,
    groupby,
    combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
A = deque(eval(input()))
B = deque(eval(input()))
C = deque(eval(input()))


def DFS(N):
    if not eval(N):
        print(N)
    else:
        p = eval("{}.popleft()".format(N))
        DFS(p.upper())


DFS("A")

+A = deque(eval(input())) +B = deque(eval(input())) +C = deque(eval(input())) -def ctoi(c): -    return ord(c) - ord("a") +def DFS(N): +    if not eval(N): +        print(N) +    else: +        p = eval("{}.popleft()".format(N)) +        DFS(p.upper()) -SA = list(input()[::-1]) -SB = list(input()[::-1]) -SC = list(input()[::-1]) -S = [SA, SB, SC] -turn = 0 -while S[turn]: -    turn = ctoi(S[turn].pop()) -print((ascii_lowercase[turn].upper())) +DFS("A")