Binary String
시간 제한3초메모리 제한256 MB
각 조건마다 앞 y비트에 1이 정확히 x개 있거나 뒤 x비트에 1이 정확히 y개 있어야 할 때, 길이 n인 이진 문자열의 개수를 구한다.
문제
Rikka has a binary string with bits.
We don't know the string. The thing we know for sure is, for each , at least one of the following is true: "there are exactly ones in the first bits" or "there are exactly ones in the last bits".
Find the number of possible binary strings modulo .
입력
The first line contains an integer which denotes the number of test cases ().
For each test case, the first line contains two integers and (, ).
The -th of the following lines contains two integers and (, or ).
출력
For each test case, print an integer which denotes the number of binary strings satisfying the constraints, modulo .