import qualified Data.Map as M
import Data.List

solve :: [[Int]] -> String
solve ((w:h:n:_):b)
  | stack == [0] = "YES"
  | otherwise = "NO"
  where
    edge x y = x == 0 || x == w || y == 0 || y == h
    clockwise a b = compare (toLiner a) (toLiner b)
      where toLiner (i,(x,y))
              | y == 0 = x
              | x == w = w + y
              | y == h = w + h + w - x
              | otherwise = w + h + w + h - y

    sortIndices l = map fst $ sortBy clockwise ps
      where ps = concatMap (\(i, x1:y1:x2:y2:_) -> [(i,(x1,y1)), (i,(x2,y2))]) $ zip [1..] l

    b' = sortIndices $ filter (\(x1:y1:x2:y2:_) -> edge x1 y1 && edge x2 y2) b
    stack = foldl' (\(z:zs) i -> if i /= z then i : z : zs else zs) [0] b'

main = getContents >>= putStrLn.solve.map (map read . words).lines
