program j01; const maxn=1000086; var f,l:array[0..maxn]of longint; time,x,k,t,i,head,tail:longint; begin readln(time); while time>0 do begin dec(time); readln(x,k,t); f[x]:=0; l[1]:=x; head:=1;tail:=1; for i:=x-1 downto 1 do begin while (l[head]-t>i)and(headi) then begin if f[i*k]=head)and(f[l[tail]]>f[i]) do dec(tail); inc(tail);l[tail]:=i; end; writeln(f[1]); end; end.