#P2791. 幼儿园篮球题
幼儿园篮球题
Background
As everyone knows, Cai Xukun, who “debuted” from the national talent show and has been in kindergarten for two and a half years, likes singing, dancing, rap, and basketball. As Irving’s teacher, his basketball skills are naturally much better than those of the “ikun” fans.
Problem Description
On Cai Xukun’s exclusive basketball court in the “national talent show kindergarten”, there are a total of exclusive basketballs, among which are deflated. Due to Cai Xukun’s superb skills, when he shoots a deflated ball, it must go in, and when he shoots an inflated ball, it must not go in.
Cai Xukun holds touring basketball performances. In the -th performance, the ikun fans specify the number of shots . They will prepare balls from the exclusive basketballs and place them on the court, among which exactly are deflated. Cai Xukun will randomly choose balls from these exclusive basketballs to shoot. If he makes shots, then the failure score of this performance is . The ikun fans want to know, for these performances, the result of the expected failure score modulo . The basketball performances are independent of each other.
Input Format
The first line contains four positive integers , representing the total number of Cai Xukun’s exclusive basketballs, the total number of deflated basketballs, the number of touring basketball performances, and the failure score parameter.
Each of the next lines contains three positive integers , representing, for the -th performance, the number of exclusive basketballs used, the number of deflated basketballs among them, and the number of shots specified by the ikun fans.
Output Format
Output lines in total. The -th line contains a positive integer, representing the expected failure score of the -th performance modulo .
3 2 1 3
3 2 2
332748121
Hint
For the sample, we explain as follows. Let the failure score be . Cai Xukun has probability to make shots, and probability to make shot. The expected failure score is , and .
Subtask 1 (): .
Subtask 2 (): .
Subtask 3 (): No special constraints.
For all testdata, , , . Also, for , we have , .
Translated by ChatGPT 5