const
  NMAX = 12;

var
  K,N: LongInt;
  al,a: String;
  p,t: array[1..NMAX] of LongInt;
  q: array[1..NMAX] of boolean;
  l,s,i,j,MaxNum: LongInt;

begin
//  assign(input,'input.txt');
  reset(input);
//  assign(output,'output.txt');
  rewrite(output);
  readln(al);
  readln(a);
  readln(k);

  N := Length(a);
  MaxNum:=1;
  for i:=1 to N do MaxNum := MaxNum*i;
  dec(MaxNum);
  if k>MaxNum then
  begin
    writeln('IMPOSSIBLE');
    exit;
  end;

  for i:=1 to N do p[i] := Pos(a[i],al);

  t[N]:=0;
  for i:=1 to N-1 do
  begin
    l := 0;
    for j:=i+1 to N do if p[j]<p[i] then inc(l);
    t[i] := l;
  end;

  l:=1; s:=0;
  for i:=N-1 downto 1 do
  begin
    l := l * (N - i);
    s := s + t[i] * l;
  end;

  if MaxNum-k<s then
  begin
    writeln('IMPOSSIBLE');
    exit;
  end;

  s := s + k;

  l := 1;
  for i:=1 to N-1 do l:=l*i;
  for i:=1 to N-1 do
  begin
    t[i] := s div l;
    s := s mod l;
    l := l div (N-i);
  end;

  for i:=1 to N do q[i]:=true;
  for i:=1 to N do
  begin
    l:=0; j:=0;
    while j<t[i] do
    begin
      inc(l);
      if q[l] then inc(j);
    end;
    inc(l);
    while not q[l] do inc(l);
    q[l] := false;
    p[i] := l;
  end;

  for i:=1 to n do write(al[p[i]]);
  writeln;

end.
