import sys



x = [1,0,0]

L = "ABC"

for s in sys.stdin:

    a = L.index(s[0])

    b = L.index(s[2])

    x[a],x[b]=x[b],x[a]

print(L[x.index(1)])
import sys

 

p="A"

for s in sys.stdin:

    if p==s[0]: p=s[2]

    elif p==s[2]: p=s[0]

print(p)
import sys

x = [1, 0, 0]
L = "ABC"
for s in sys.stdin:
    a = L.index(s[0])
    b = L.index(s[2])
    x[a], x[b] = x[b], x[a]
print(L[x.index(1)])

import sys

p = "A"
for s in sys.stdin:
    if p == s[0]:
        p = s[2]
    elif p == s[2]:
        p = s[0]
print(p)

-x = [1, 0, 0] -L = "ABC" +p = "A" -    a = L.index(s[0]) -    b = L.index(s[2]) -    x[a], x[b] = x[b], x[a] -print(L[x.index(1)]) +    if p == s[0]: +        p = s[2] +    elif p == s[2]: +        p = s[0] +print(p)