Under construction

Still being built. Things may change

Number of good permutations

Time limit2sMemory limit512 MB

Summary
Count permutations of 1..N that respect given fixed positions and contain at least one pair i<j with P[i]>j and P[j]>i, modulo 2000000011.
Level

Hard8 of 10

Topics
Combinatorics, Math, Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

You are given two arrays XX and VV of size MM and an integer NN. Write a program that counts the permutations PP of length NN that satisfy all three conditions below. Arrays and permutations are numbered from 1.

  • PP is a sequence in which each of the numbers 1 through NN appears exactly once.
  • At least one pair (i,j)(i, j) satisfies i<ji < j, P[i]>jP[i] > j and P[j]>iP[j] > i.
  • P[X[i]]=V[i]P[X[i]] = V[i] holds for every 1≤i≤M1 \le i \le M.

The same value appears in XX more than once in some inputs. If no permutation meets all three conditions, the answer is 0.

Input

The first line contains the number of test cases TT (1≤T≤101 \le T \le 10).

The first line of each test case contains NN and MM (1≤N≤1091 \le N \le 10^9, 0≤M≤1040 \le M \le 10^4). The ii-th of the next MM lines contains X[i]X[i] and V[i]V[i] (1≤X[i],V[i]≤N1 \le X[i], V[i] \le N).

Output

For each test case, print the number of permutations PP that satisfy the conditions, modulo 20000000112000000011, on its own line.

Hint

For N=3N = 3 with no fixed value, (3,2,1)(3, 2, 1) is the only permutation that satisfies the conditions.

Examples2

  1. Example 1

    Input
    2
    3 0
    3 2
    3 1
    1 2
    
    Expected output
    1
    0
    
  2. Example 2

    Input
    6
    1 0
    2 0
    3 0
    4 0
    5 0
    6 0
    
    Expected output
    0
    0
    1
    12
    91
    650