puts gets.to_i.times.map { n, k = gets.split.map(&:to_i); n % (k + 1) == 1 ? 0 : 1 }.sum