program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;
var T,N, k,a, i,count,flag:longint;

f1 : text;
M : array [1..9]of integer;
begin
Assign(f1, 'WEIGHING.IN');
reset(f1);
readln(f1,T);
M[1]:=0;
M[2]:=1;
M[3]:=1;
M[4]:=2;
M[5]:=2;
M[6]:=2;
M[7]:=2;
M[8]:=2;
M[9]:=2;

for i := 1 to T do begin readln(f1,N);
   k:=N;
   count:=0;
  while k>9 do begin
  flag:=0;
  if (k mod 3 =0) and (flag = 0)   then begin k:=k div 3; flag:=1; end;
  if (k mod 3 =1) and (flag = 0)  then begin k:=(k div 3)+1; flag:=1; end;
  if (k mod 3 =2) and (flag = 0)  then begin k:=ceil(k/3); flag:=1; end;
  count:=count+1;




   end;



  count:=count+M[k];
  writeln(count);





end;




end.
