Koishi is playing a game with Satori.
There is an array of length 1018. 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 n sub-segments of this array that are special. Specifically, the i-th sub-segment is described by three integers (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], she will win immediately if z_i=1 or lose immediately if z_i=0.
If there is a special sub-segment (x,x,1) given for some x, a player will immediately win when the remaining array is \[x,x] at the start of their turn. Importantly, if there is no special sub-segment (x,x,1) given for some x, it is assumed that \[x,x] is an immediate loss, as in the original rules.
There will be q games. At the beginning of the i-th game, Utuoho will give two players the sub-segment \[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], not on the whole array. All the q 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 T (1≤T≤2000), the number of test cases. Then T test cases follow.
The first line of each test case contains two integers n and q (1≤n,q≤105), the number of sub-segments and the number of games.
Then n lines follow. Each of them contains three integers: l_i, r_i, z_i (1≤l_i≤r_i≤109, 0≤z_i≤1). You may assume that, for any i=j, (l_i,r_i)=(l_j,r_j) holds.
After that, q lines follow. Each of them contains two integers a_i and b_i (1≤a_i≤b_i≤109) describing the initial sub-segment of the i-th game.
It is guaranteed that ∑(n+q)≤9⋅105.
For each test case, output one line with q integers v_i (0≤v_i≤1) without spaces: v_i=0 if Koishi loses the i-th game and v_i=1 if she wins the i-th game, respectively.