computeMax :: Integral a => a -> a -> a
computeMax n d
    | odd n = 127 * (n - 1) + d
    | otherwise = 127 * n - d

main :: IO ()
main = do
    _ <- getLine
    putStr . unlines .
        fmap (show . (\[n, d] -> computeMax n d) .
            fmap (read :: String -> Int) . words) . lines =<< getContents
