n = int(input())

low=0
high=0

def get_low(s):
    s = s.replace('B', '8').replace('D', '0')
    if s == '0': return 0
    if s[0] == '0': s = 'D' + s[1:]
    return int(s, 16)

def get_high(s):
    s = s.replace('8', 'B').replace('0', 'D')
    return int(s, 16)

for _ in range(n):
    line = input()
    low += get_low(line)
    high += get_high(line)

ord='0123456789ABCDEF'
def conv(s):
    if not s: return '0'
    out = []
    while s:
        out += [ord[s%16]]
        s//=16
    return ''.join(out[::-1])

print(conv(high))
print(conv(low))