n = gets.to_i
n.times{
    s, d = gets.chomp.split.map(&:to_i)
    step = 0
    while s < d
        if s == 0
            q = 0
            q += 1 while (2 ** q) <= d
            s += (2 ** (q - 1))
        else
            q = 0
            q += 1 while s % (2 ** q) == 0
            (q - 1).downto(0){|q2|
                if s + (2 ** q2) <= d
                    s += (2 ** q2)
                    break
                end
            }
        end
        step += 1
    end
    puts step
}

