var s1,s2,s3,s:string;
    c1,c2:char;
    i,j,k,l,n,m,kk:longint;

begin
kk:=1;
repeat
s1:='';
readln(s);
i:=0;
if (s[1]='0') and (s[3]='0') and (s[5]='0') then kk:=0
else
begin
while s[i+1]<>' ' do
  begin
  inc(i);
  s1:=s1+s[i];
  end;
c1:=s[i+2];
c2:=s[i+4];
for i:=1 to length(s1) do
  if s1[i]=c1 then s1[i]:=c2;
i:=1;
while s1[i]='0' do
 inc(i);
if i>length(s1) then write('0')
                else
  for j:=i to length(s1) do
    write(s1[j]);

  writeln;
end;
until kk=0;
end.