The Computer Game

Time limit1sMemory limit128 MB

Summary
Given a diamond-shaped lattice grid with some cells blocked, count all nonempty subsets of free cells that form a single connected (4-adjacency) region.
Level

Medium6 of 10

Topics
Brute force, Graph, Bit manipulation, DFS
Solved
No attempts yet

Problem

John and Brus are playing a strategy game on a computer. The game takes place on a flat map. First Brus deploys his army; then John must choose strategic points for his own army according to the following rules:

  • Each strategic point must be a lattice point (x,y)(x, y) (a point with integer coordinates) such that ∣x∣+∣y∣<N|x| + |y| < N.
  • John may choose any positive number of strategic points.
  • All chosen strategic points must be distinct.
  • Each strategic point must be free, i.e. not occupied by Brus's army.
  • Every pair of chosen strategic points must be connected, where the connection may pass only through other chosen strategic points.

Two distinct lattice points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) are adjacent (directly connected) when ∣x1−x2∣+∣y1−y2∣=1|x_1 - x_2| + |y_1 - y_2| = 1. Connection is transitive through chosen points: if chosen points AA and BB are adjacent and BB and CC are adjacent, then AA and CC are connected. In other words, the set of chosen points must form a single connected region under this adjacency.

Count the number of ways for John to choose his strategic points.

Input

The first line contains a single integer TT, the number of test cases. Each test case begins with a line containing two integers NN and MM: NN is the value used in the first rule, and MM is the number of lattice points already occupied by Brus's army. Each of the next MM lines contains two integers XkX_k and YkY_k, the coordinates of one occupied point.

Constraints: 1≤T≤741 \le T \le 74, 1≤N≤71 \le N \le 7, 1≤M≤2251 \le M \le 225, −7≤Xk,Yk≤7-7 \le X_k, Y_k \le 7, and all (Xk,Yk)(X_k, Y_k) are distinct.

Output

For each test case, print a single line containing the number of ways for John to choose his strategic points.

Examples1

  1. Example 1

    Input
    2
    2 1
    7 7
    2 3
    0 0
    4 -7
    7 -4
    
    Expected output
    20
    4