loj#P3745. 「COCI 2015.10」RELATIVNOST
「COCI 2015.10」RELATIVNOST
Description
Young Luka is an art dealer. He has clients and sells artistic paintings to each client.
Each client can purchase either colored paintings or black and white paintings, but not both.
The client denoted with wants to purchase at most colored paintings and at most black and white paintings.
The client will always purchase at least one paintings. Luka has an almost unlimited amount of paintings, so the number of paintings required from the clients is never a problem.
Luka doesn’t like selling black and white paintings and knows that if less than people get colored paintings, it will make him feel sad.
His clients constantly keep changing their requests or, in other words, the number of paintings they want to purchase. Because of this, Luka is often troubled by the question: “How many different purchases are there, so that at least clients get at least one colored painting?” Help Luka and save him from his worries.
Input
The first line of input contains two integers ().
The second line of input contains integers ().
The third line of input contains integers ().
The fourth line of input contains the number of requirement changes ().
Each of the following lines contains three integers, the label of the person changing the requirements (), the maximal number of colored paintings they want to purchase () and the maximal number of black and white paintings they want to purchase ().
Output
The output must consist of lines where each line contains the number of different purchases modulo .
2 2
1 1
1 1
1
1 1 1
1
2 2
1 2
2 3
2
1 2 2
2 2 2
4
4
4 2
1 2 3 4
1 2 3 4
1
4 1 1
66
Scoring
In test cases worth of total points, it will hold that and are smaller than .