COD1 - Save the cows!


There is a green square grid of size n×m with k cows in it.

The objective of the cows is to escape the field. If any one of the cows escape all cows are set free.

There is a farmer who tries to restrict the field by putting up fences along the border. Initially the grid is not fenced.

Cows coordinate and think of a plan to escape. Cows get the first move. Cows and farmer move alternatively. At any move any one of the k cows can move to their neighboring cell (the cell that shares an edge with it). If the cow is already at the edge of the field and the edge is not fenced then it can escape it and hence all cows are set free. After every move of the cows the farmer can fence some edge at the border of the field of length 1 so that no cow is able to escape from that edge anymore.

The question is: "Will the innocent cows manage to escape?"

Input

First line contains T-number of test cases (0 < T <= 100.)

Each test case contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the field and 0 ≤ k ≤ 100 — the number of cows. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding cow. There could be more than one cow at a cell.

Output

Output one word: "YES" — if cows escape, "NO" — otherwise.

Example

Input:
1
2 2 1
1 2

Output:
YES

hide comments
akshay_2000: 2021-03-30 11:04:23

Easy one. Just think of all possibilities when the cow can't escape from the field.

Last edit: 2021-04-01 14:40:07
dmorgans: 2019-06-14 21:11:03

good one easy but tricky........
take care for k=0 too

Liquid_Science: 2016-02-08 15:05:04

This seems to give WA with print writer in JAVA. You have been warned .

Jacob Plachta: 2013-10-19 01:39:49

If there are no cows (K=0), they do not escape.


Added by:CSI
Date:2013-09-27
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64