import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.Bits (xor) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isSpace) import Data.IntSet (IntSet) import qualified Data.IntSet as ISet import Data.List (foldl', unfoldr, nub) getL :: (ByteString -> [Int]) -> IO [Int] getL f = f <$> B.getLine readIL :: (ByteString -> Maybe (Int, ByteString)) -> (ByteString -> [Int]) readIL f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') main :: IO () main = do w <- readLn :: IO Int h <- readLn :: IO Int n <- readLn :: IO Int xss <- replicateM n $ getL (readIL B.readInt) print $ solve w h n xss solve :: Int -> Int -> Int -> [[Int]] -> Int solve w h n xss = xs * h + ys * w - xs * ys - n where xs = length $ nub $ map head xss ys = length $ nub $ map (head.tail) xss