program spojovy_seznam;
type
	plist=^list;
	list = record
		 value:integer;
		 next:plist;
		 end;

procedure list_new(var l:plist);
begin
	l:=NIL;
end;

procedure list_push(var l:plist; i:integer);
var lnew: plist;
begin
	new(lnew);
	lnew^.next := l;
	lnew^.value := i;
	l:= lnew;
end;

procedure list_pop(var l:plist);
var tmp:plist;
begin
	tmp:=l;
	l:=l^.next;
	dispose(tmp);
end;

function list_empty(l:plist): boolean;
begin
	list_empty:= l = nil;
end;

procedure list_dispose(var l:plist);
begin
	while not list_empty(l) do list_pop(l);
end;

function list_front(l:plist): integer;
begin
	list_front := l^.value;
end;

procedure list_move_head(var l1,l2:plist);
var temp:plist;
begin
	temp:=l2;
	l2:=l1;
	l1:=l2^.next;
	l2^.next:=temp;
end;

procedure list_reverse (var l:plist);
var temp : plist;
begin
	list_new(temp);
	
	while NOT list_empty(l) do
	begin
   		list_move_head(l, temp);
	end;

	l:=temp;
end;

procedure list_filter(var l:plist);
var p:plist;
begin
	while not list_empty(l) and
		( list_front(l) mod 2 = 1) do
		list_pop(l);
	
	if list_empty(l) then exit;
	list_filter(l^.next);
end;

procedure list_filter2(var l:plist);
var pom:plist;
begin

  list_new(pom);
  while not list_empty(l) do
  begin
    if list_front(l) mod 2=0 then
       list_move_head(l,pom)
    else list_pop(l);
  end;

  l:=pom;
  
end;


var zoznam : plist;
    cislo, chyba : integer;
    vstup: string;
begin

  while TRUE do
  begin

    readln(vstup);

    if vstup = 'q' then
      break;

    val(vstup, cislo, chyba);
    list_push (zoznam, cislo);

  end;

  list_filter2 (zoznam);

  while not list_empty(zoznam) do
  begin
    writeln(list_front(zoznam));
    list_pop(zoznam);
  end;

end.
