Game
시간 제한8초메모리 제한512 MB
특정 구간에서 즉시 승리 또는 패배가 정해질 때, 각 질의 구간에서 선공이 최적으로 두어 이기는지 판정한다.
문제
Koishi is playing a game with Satori.
There is an array of length . 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 sub-segments of this array that are special. Specifically, the -th sub-segment is described by three integers . They mean that, at the start of a player's turn, if the remaining array is the sub-segment , she will win immediately if or lose immediately if .
If there is a special sub-segment given for some , a player will immediately win when the remaining array is at the start of their turn. Importantly, if there is no special sub-segment given for some , it is assumed that is an immediate loss, as in the original rules.
There will be games. At the beginning of the -th game, Utuoho will give two players the sub-segment and take away all other parts of the array. That means Koishi and Satori only play on sub-segment , not on the whole array. All the 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 (), the number of test cases. Then test cases follow.
The first line of each test case contains two integers and (), the number of sub-segments and the number of games.
Then lines follow. Each of them contains three integers: , , (, ). You may assume that, for any , holds.
After that, lines follow. Each of them contains two integers and () describing the initial sub-segment of the -th game.
It is guaranteed that .
출력
For each test case, output one line with integers () without spaces: if Koishi loses the -th game and if she wins the -th game, respectively.