Game

아직 제출이 없습니다시간 제한8초메모리 제한512 MB

문제

Koishi is playing a game with Satori.

There is an array of length 101810^{18}. In the game, Koishi and Satori take turns operating on this array, and Koishi goes first. At the start of a player's turn, if there is only one element left in the array, she loses the game immediately. Otherwise, she needs to delete either the leftmost number or the rightmost number of the remaining array.

The game is too boring for Koishi, so she came up with the following modified rules.

There are nn sub-segments of this array that are special. Specifically, the ii-th sub-segment is described by three integers (l_i,r_i,z_i)(l\_i, r\_i, z\_i). They mean that, at the start of a player's turn, if the remaining array is the sub-segment \[l_i,r_i]\[l\_i, r\_i], she will win immediately if z_i=1z\_i = 1 or lose immediately if z_i=0z\_i = 0.

If there is a special sub-segment (x,x,1)(x, x, 1) given for some xx, a player will immediately win when the remaining array is \[x,x]\[x, x] at the start of their turn. Importantly, if there is no special sub-segment (x,x,1)(x, x, 1) given for some xx, it is assumed that \[x,x]\[x, x] is an immediate loss, as in the original rules.

There will be qq games. At the beginning of the ii-th game, Utuoho will give two players the sub-segment \[a_i,b_i]\[a\_i, b\_i] and take away all other parts of the array. That means Koishi and Satori only play on sub-segment \[a_i,b_i]\[a\_i, b\_i], not on the whole array. All the qq games are independent.

Two players always use the optimal strategy. Please tell them who will win in each game.

입력

The first line contains an integer TT (1T20001 \leq T \leq 2000), the number of test cases. Then TT test cases follow.

The first line of each test case contains two integers nn and qq (1n,q1051 \leq n, q \leq 10^5), the number of sub-segments and the number of games.

Then nn lines follow. Each of them contains three integers: l_il\_i, r_ir\_i, z_iz\_i (1l_ir_i1091 \leq l\_i \leq r\_i \leq 10^9, 0z_i10 \leq z\_i \leq 1). You may assume that, for any iji \neq j, (l_i,r_i)(l_j,r_j)(l\_i, r\_i) \neq (l\_j, r\_j) holds.

After that, qq lines follow. Each of them contains two integers a_ia\_i and b_ib\_i (1a_ib_i1091 \leq a\_i \leq b\_i \leq 10^9) describing the initial sub-segment of the ii-th game.

It is guaranteed that (n+q)9105\sum (n + q) \leq 9 \cdot 10^5.

출력

For each test case, output one line with qq integers v_iv\_i (0v_i10 \leq v\_i \leq 1) without spaces: v_i=0v\_i = 0 if Koishi loses the ii-th game and v_i=1v\_i = 1 if she wins the ii-th game, respectively.