#P7392. 「TOCO Round 1」奇怪的排序
「TOCO Round 1」奇怪的排序
Description
On Valentine’s Day, was treated very badly, especially when an upper-class duke and a child said something like “Every day with you is Valentine’s Day.” So he found a chance to take revenge.
Now there are couples numbered standing in a line in an arbitrary order. runs the following sorting pseudocode on them.

wants to know how many initial permutations will result in the couples’ numbers being in increasing order after being processed by this pseudocode. Maybe this will make him feel a bit better.
Input Format
The first line contains an integer , the number of test cases.
The next lines each contain two integers , representing the number of couples and the parameter passed in the first call to the pseudocode.
Output Format
Output lines. Each line contains one integer: the answer modulo .
3
3 1
10 2
1 0
3
25200
1
5
502520 0
502520 1
502520 2
502520 3
502520 4
1
218102685
429650441
770595802
584122358
Hint
For the first of the testdata, .
For the first of the testdata, , .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号