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 painting. 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 Specification
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 .
In test cases worth 30% of total points, it will hold that and are smaller than .
Output Specification
The output must consist of lines where each line contains the number of different purchases modulo .
Sample Input 1
2 2
1 1
1 1
1
1 1 1
Sample Output 1
1
Explanation for Sample Output 1
After the first client changes his request from to - nothing really changes, the number of ways to sell paintings is 1. The one and only way to sell paintings is to sell the first client one colored painting, and the second client should be sold one colored painting as well. Every client is required to get at least one colored painting because , which means that there should be at least 2 clients with colored paintings.
Sample Input 2
2 2
1 2
2 3
2
1 2 2
2 2 2
Sample Output 2
4
4
Sample Input 3
4 2
1 2 3 4
1 2 3 4
1
4 1 1
Sample Output 3
66
Comments