const
N = 40;
type
Tmas = array[1..N] of integer;
procedure input(var m: Tmas);
var
i: longint;
begin
for i := 1 to N do
readln(m[i]);
end;
procedure change(var m: Tmas);
var
kol, i: longint;
begin
kol := 0;
for i := 1 to N do
if (m[i] mod 3 = 0) and (m[i] mod 10 = 1) then
inc(kol);
for i := 1 to N do
if (m[i] mod 3 = 0) and (m[i] mod 10 = 1) and (kol <> 0) then
m[i] := kol;
end;
procedure output(m: Tmas);
var
i: longint;
begin
for i := 1 to N do
write(m[i] + ' ');
end;
var
m: Tmas;
begin
input(m);
change(m);
output(m);
end.