program Project1;

{$APPTYPE CONSOLE}
function schet(i:longint):longint;
var
 col:longint;
begin
   col:=0;
  if i = 1  then  begin
     col:=0;
    end else begin

  if i mod 3 = 0 then begin
    col:=col+schet(i div 3)+1;
   end else begin
    if i mod 2 = 0 then begin
      col:=col+schet(i div 2)+1;
     end else begin
       if i=1 then begin
         col:=0;
        end else begin
         col:=col+schet((i-1) div 2)+1;
        end;
     end;
   end;
    end;
   result:=col;
end;

var
f:textfile;
jj,t:integer;
n:longint;

begin
assign(f, 'WEIGHING.IN');
reset(f);
readln(f,t);
for jj := 1 to t do begin
readln(f,n);
writeln(schet(n));


end;
close(f);
end.

