#Lutece1398. Bigger Bets
Bigger Bets
Migrated from Lutece 1398 Bigger Bets
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
In some country live wizards. They like to make weird bets.
Two wizards draw points on the left named sources and draw points on the right named sinks.Wizards numbered the sources in the order of increasing numbers of the vertices from to . The sinks are numbered from to in the similar way.And in the magic world,the sources to sink would have paths.
To make a bet, they, as are real wizards, cast a spell, which selects a set of paths from all sources to the sinks in such a way . In this case, each sink has exactly one path going to it from exactly one source. Let's suppose that the -th sink has a path going to it from the 's source. Then let's call pair (i, j) an inversion if and . If the number of inversions among all possible pairs (i, j), such that , is even, then the first wizard wins (the second one gives him one magic coin). Otherwise, the second wizard wins (he gets one magic coin from the first one).
Our wizards are captured with feverish excitement, so they kept choosing new paths again and again for so long that eventually they have chosen every possible set of paths for exactly once. The two sets of non-intersecting pathes are considered to be different, if and only if there is an edge, which lies at some path in one set and doesn't lie at any path of another set. To check their notes, they asked you to count the total winnings of the first player for all possible sets of paths modulo a prime number .
Input
First line of input consists of a single integer containing the number of test cases ( equal to around 50)
each of the following lines contain two integer . lies between and , lies between and
Output
For each test case, print a single line contains the answer.
Samples
3
1 1
2 2
3 3
1
3
182
Resources
IEEEXTREME Programming Competition