def f(a, b)
  result = 0
  until a == b
    result += (a & 1) + (b & 1)
    a = (a + 1) >> 1
    b = b >> 1
  end
  result
end
 
n = gets.to_i
n.times do
  s, d = gets.split.map!(&:to_i)
  puts f(s, d)
end