import Control.Monad
import Control.Applicative

solve :: Int -> Int -> Int
solve s d
    | s == d = 0
    | odd s && odd d = 2 + solve ((s+1)`div`2) ((d-1)`div`2)
    | odd s = 1 + solve ((s+1)`div`2) (d`div`2)
    | odd d = 1 + solve (s`div`2) ((d-1)`div`2)
    | otherwise = solve (s`div`2) (d`div`2)

main :: IO ()
main = do
    n <- readLn
    replicateM_ n $ do
        [s,d] <- map read . words <$> getLine
        print $ solve s d