
def f(a, b)
  k = Math::log2(b - a).to_i
  mask = ~((1 << k) - 1)

  c = b & mask
  if b == c
    a, b = -b, -a 
    c = b & mask
  end
  b == c ? 1 : f(a, c) + f(c, b)
end

n = STDIN.gets.to_i
n.times do
  s, d = STDIN.gets.split.map(&:to_i)
  puts f(s, d)
end