def write(a):
    f=open('output.txt','w')
    f.write(str(a)+'\n')

def read():
    line=raw_input(":")
    while line!='0 0 0':
        newList=''
        line=line.split(' ')
        change=line[1]
        to=line[2].strip()
        for item in line[0]:
            if item==change:
                newList+=to
            else:
                newList+=item
        line=raw_input(":")
        print(int(newList))
read()