a=input()
b=""
for i in range(1,len(a)+1):
if a[-i] not in b:
b+=a[-i]
else:
continue
if b[0] == 0:
print(b[1:])
else:
print(b)
a=input()
b=""
for i in range(1,len(a)+1):
if a[-i] not in b:
b+=a[-i]
else:
continue
if b[0] == 0:
print(b[1:])
else:
print(b)