import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Control.Monad

main = do
  BS.getLine
  co <- BS.getContents
  let qs = map readQ $ BS.lines co
  compute qs

data Q = U Int Int | Q

readQ :: BS.ByteString -> Q
readQ li = case ns of
    [1,a,b] -> U a b
    [2] -> Q
  where
    ns = unfoldr (BS.readInt . BS.dropWhile isSpace) li

compute :: [Q] -> IO ()
compute qs = foldM_ step ([],0) qs

step (bas,b) (U a1 b1) = return (ins (b1,a1) bas, b+b1)
step st@(bas,b) Q = do
  let (_,x) = head bas
  let fx = b + sum [ abs (x-a) | a <- map snd bas ]
  putStrLn $ unwords [show x, show fx]
  return st

ins v [] = [v]
ins v aas@(a:as)
  | v < a = v:aas
  | True  = a:v:as