include Math def depth(n,k) return n - 1 if k == 1 # (k^{d+1} - 1)/(k-1) >= n # d >= log(n * (k-1) + 1) / log(k) - 1 (log(n*(k-1) + 1) / log(k) - 1).ceil end Q = gets.to_i puts Q.times.map{ gets.split.map(&:to_i) } .map{|n,k| depth(n, k) }