This page is still under construction.

Parts of this page are still being built. What you see may change.

Queen Game

Time limit1sMemory limit128 MB

Summary
Given N queens on an R by C board that move up, left, or up-left, decide if the first player wins with optimal play.
Level

Medium7 of 10

Topics
Game theory, Math, Bit manipulation
Solved
No attempts yet

Problem

Queen Game is a two-player game played on an R×CR \times C chessboard. Rows are numbered 11 to RR from top to bottom, and columns 11 to CC from left to right; the top-left cell is row 11, column 11.

NN queens are placed on the board. Several queens may occupy the same cell, and each cell can hold arbitrarily many queens.

The two players alternate turns. On your turn you choose one queen and move it in one of three directions:

  • up,
  • left, or
  • diagonally up-left.

You may move it by any number of cells, but a queen can never leave the board. When a queen reaches row 11, column 11, that queen is removed from the board. The player who removes the last queen wins.

Given the board size and the positions of the NN queens, and assuming both players play optimally, write a program that decides whether the first player has a winning strategy.

Input

The first line contains the number of test cases TT.

For each test case, the first line contains three integers RR, CC, and NN (1≤R≤251 \le R \le 25, 1≤C≤10151 \le C \le 10^{15}, 1≤N≤10001 \le N \le 1000).

Each of the next NN lines contains the position of one queen: the row number and the column number, separated by a space.

Output

For each test case, print YES on its own line if the first player has a winning strategy, and NO otherwise.

Examples3

  1. Example 1

    Input
    3
    5 5 1
    2 3
    5 5 2
    4 4
    4 4
    5 5 3
    1 2
    2 1
    2 2
    
    Expected output
    NO
    NO
    YES
    
  2. Example 2

    Input
    1
    1 1 1
    1 1
    
    Expected output
    NO
    
  3. Example 3

    Input
    1
    5 5 1
    2 2
    
    Expected output
    YES