#P4104. [HEOI2014] 平衡

[HEOI2014] 平衡

Description

After class, Lulu, Huahua, and Xuanxuan set up a “seesaw” on the desk using a regular triangular prism teaching aid and a ruler.

The structure of this “seesaw” is as follows: at the bottom is a regular triangular prism with one of its lateral faces parallel to the ground, and on top lies a ruler. Several identical erasers are placed on the ruler. The ruler has 2n+12n+1 equally spaced tick marks; the (n+1)(n+1)-th tick is exactly at the center of the ruler and exactly coincides with the edge of the regular triangular prism that is not on the desk.

Lulu notices that the “seesaw” is unbalanced (the ruler is not parallel to the ground). So she adds a few more erasers and moves some erasers so that each of the 2n+12n+1 tick marks on the ruler has exactly one eraser of the same mass. The “seesaw” becomes balanced, and Lulu is happy.

Huahua thinks this is too boring, so she randomly removes kk erasers from the ruler. To her surprise, the ruler remains balanced!

Xuanxuan is a thoughtful child, so she is not surprised that the ruler remains balanced, as this is merely a coincidence. What interests her is: in how many ways can Huahua remove kk erasers so that the ruler remains balanced? Of course, to simplify the problem, she has to make some sacrifices—assume all erasers are point masses with equal mass. Even so, she cannot compute this number. After school, she brings this problem to her older brother/sister—the student council president of Hibarigasaki Academy, that is, you. Since the answer may be too large, you only need to tell her the value modulo pp.

Input Format

The first line contains a positive integer TT (the number of times Xuanxuan asks you).

Each of the next TT lines contains three positive integers nn, kk, and pp.

Output Format

Output TT lines, each containing one positive integer, the answer for the corresponding query.

10
6 5 10000  
4 1 10000 
9 6 10000 
4 6 10000 
5 1 10000 
8318 10 9973 
9862 9 9973 
8234 9 9973 
9424 9 9973 
9324 9 9973
73
1
920
8
1
4421
2565
0
446
2549

Hint

  • 10% of the testdata satisfy n10n \le 10.
  • 30% of the testdata satisfy n50n \le 50.
  • 50% of the testdata satisfy n1000n \le 1000.
  • Additionally, 10% of the testdata satisfy k=3k = 3.
  • Additionally, 10% of the testdata satisfy p=2p = 2.
  • 100% of the testdata satisfy T20T \le 20, 1n100001 \le n \le 10000, 1k101 \le k \le 10, 2p100002 \le p \le 10000, and k2n+1k \le 2n+1.

Translated by ChatGPT 5