Mashup
시간 제한2초메모리 제한256 MB
N개의 대회를 순열로 재배열해 난이도가 비증가하는 대회를 만드는 경우의 수를 2로 나눈 나머지를 구한다.
문제
Nike Nirzayanov, the founder of the popular competitive typing platform SpeedForces, has recently added a new feature allowing users to create random mashups of past contests.
A contest on SpeedForces consists of implementation problems, each with a difficulty rating among . The problems in a single contest are always arranged in nondecreasing order of difficulty and assigned problem slots from to in order.
Busy Beaver is testing out the new feature. He first specifies past contests, where the -th contest he specifies has problems of difficulty for each , where .
The feature will select a random permutation of and generate for Busy Beaver a contest where the -th problem is the -th problem in the -th contest he specified.
Busy Beaver wonders: How many such permutations will result in a contest with reverse difficulty order (i.e., the problem difficulties are in nonincreasing order)? For some reason, he only wants the answer modulo 2.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains the integer () --- the number of past contests and problems.
The next lines of each test case each contain integers ( and ).
It is guaranteed that the sum of across all test cases is no more than .
출력
For each test case, output a single integer, the number of such permutations modulo .
힌트
In the first test case, the past contests have the following problem difficulties:
- Contest : .
- Contest : .
- Contest : .
There are permutations that result in a reverse difficulty order contest: and . Therefore, the answer is .
In the second test case, the past contests have the following problem difficulties:
- Contest : .
- Contest : .
- Contest : .
- Contest : .
There are permutations that result in a reverse difficulty order contest: , , and . Therefore, the answer is .
In the third test case, the only permutation generates a reverse difficulty order contest, so the answer is .