import Data.Maybe
import Data.List
import Debug.Trace
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict as M

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
    toLiner (i,(x,y))
      | y == 0 = x
      | x == w = w + y
      | y == h = w + h + w - x
      | otherwise = w + h + w + h - y
    b' = filter (\(x1:y1:x2:y2:_) -> edge x1 y1 && edge x2 y2) b
    ps = concatMap (\(i, x1:y1:x2:y2:_) -> [(i,(x1,y1)), (i,(x2,y2))]) $ zip [1..] b'
    t = M.fromList $ map (\(i,(x,y)) -> (toLiner (i,(x,y)), i)) ps
    stack = M.foldl' (\(z:zs) i -> if i /= z then i : z : zs else zs) [0] t

readInt = fst . fromJust . B.readInt
parse = map (map readInt . B.words)
main = B.getContents >>= putStrLn.solve.parse.B.lines
