Under construction

Still being built. Things may change

Join The Future

Time limit5sMemory limit64 MB

Summary
Given parity constraints on subarray sums and a lower and upper bound for each element, count the arrays that satisfy them and print the lexicographically smallest one.
Level

Hard8 of 10

Topics
Union-find, Greedy, Combinatorics
Solved
No attempts yet

Problem

Professor Zhang has an array of nn integers. He writes down some observations about the array on paper. Each observation is described by three integers lil_i, rir_i, and sis_i, which means that the sum of elements modulo 2 on the interval [li,ri][l_i, r_i] of the array is equal to sis_i.

After that, he tries to recover the array using only these observations. Many arrays may satisfy them, so Professor Zhang limits the lower and upper bound of each integer in the array.

Given the observations, the lower bounds, and the upper bounds, find the number of possible arrays and the lexicographically smallest array.

Input

There are multiple test cases. The first line of input contains an integer TT, the number of test cases. For each test case:

The first line contains two integers nn and mm (1≤n≤401 \le n \le 40, 0≤m≤n(n+1)20 \le m \le \frac{n(n+1)}{2}): the length of the array and the number of observations.

Each of the next nn lines contains two integers xix_i and yiy_i (0≤xi≤yi≤1090 \le x_i \le y_i \le 10^9): the lower and upper bound of the ii-th integer.

Each of the next mm lines contains three integers lil_i, rir_i, and sis_i (1≤li≤ri≤n1 \le l_i \le r_i \le n, 0≤si≤10 \le s_i \le 1), denoting the ii-th observation.

There are at most 110110 test cases, and the total input size is at most 30 kibibytes.

Output

For each test case, output the number of possible arrays on the first line, modulo 109+710^9 + 7. On the second line, output the lexicographically smallest array. If no array is possible, output "-1" on the second line.

Examples1

  1. Example 1

    Input
    3
    3 3
    1 10
    0 21
    3 15
    2 2 1
    3 3 0
    2 3 1
    3 0
    0 1
    1 3
    3 4
    3 3
    1 10
    0 21
    3 3
    2 2 1
    3 3 0
    2 3 1
    
    Expected output
    660
    1 1 4
    12
    0 1 3
    0
    -1