var
a,b:array[1..20] of string;
n,k,i,l,p:byte;
begin
readln(n);
for i:=1 to n do
readln(a[i]);
readln(k);
for i:=1 to n do
if length(a[i])=k then l:=l+1;
repeat
if p=0 then
for i:=1 to n do
if length(a[i])=k then
begin
p:=p+1;
b[p]:=a[i];
end;
if p=l then
for i:=1 to n do
if length(a[i])<>k then
begin
p:=p+1;
b[p]:=a[i];
end;
until p=n;
for i:=1 to p do
write(b[i],' ');
end.