#P4229. [清华集训 2017] 某位歌姬的故事
[清华集训 2017] 某位歌姬的故事
Description
IA is a girl who can sing.
IOI 2018 is coming, and IA decides to write a song for the contestants to express her best wishes. The song has notes, and the pitch of the -th note is . IA's vocal range is , and she can only sing positive integer pitches in . Therefore .
Before composing, IA needs to decide the structure of the song, so she wrote down constraints, where the -th constraint is: among the notes indexed from to , the maximum pitch is . After the structure is fixed, she can start composing. However, she still wants to know how many possible songs satisfy all her constraints. She heard you will go to IOI in 9 months, so she hopes you can help her compute this value.
Input Format
Read from standard input.
The first line contains an integer (), the number of testdata groups.
For each group, the first line contains three positive integers . Then follow lines, each with three integers , representing one constraint. It is guaranteed that .
Output Format
Write to standard output.
Output a single line indicating the number of possible songs. Since this number can be large, output the answer modulo .
1
3 2 3
1 2 3
2 3 2
3
2
4 2 4
1 2 3
2 3 4
7 3 74
3 6 56
2 5 56
3 7 70
20
160326468
Hint
Explanation for Sample 1. The following are the three possible songs: , , .

Translated by ChatGPT 5
京公网安备 11011102002149号