--- /dev/null
+main :: IO ()
+main = do
+ line1 <- getLine
+ let numQuestions = read line1 :: Int
+ answers <- forM [1..numQuestions] $ \_ -> do
+ q <- getQuestion
+ return $ solve q
+ putStrLn $ unlines $ map show answers
+
+getQuestion :: IO (Int, Int)
+getQuestion = do
+ line <- getLine
+ let question = map read $ words line
+ return (question !! 0, question !! 1)
+
+
+solve :: (Int, Int) -> Int
+solve (row, col) = go oddTarget
+ where maxRC = max row col
+ oddTarget = (maxRC `mod` 2) == 1
+ target = maxRC * maxRC
+ go True
+ | col >= maxRC = target - (row - 1)
+ | otherwise = (target - (row - 1)) - (row - col)
+ go False
+ | row >= maxRC = target - (col - 1)
+ | otherwise = (target - (col - 1)) - (col - row)
+
+-- if target is odd and col >= maxRC:
+-- target - (row - 1)
+-- if target is odd and row < maxRC:
+-- (target - (row - 1)) - (row - col)
+
+-- if target is even and row >= maxRC
+-- target - (col - 1)
+-- if target is even and col < maxRC
+-- (target - (col - 1)) - (col - row)
+