Do you remember the problem "Exam is coming"? Here is another similar problem.
Give you many arithmetic number sequences (sequence where the adjacent numbers have same difference). Then there are many queries. In each query, give you three digits x and ask you print the number of numbers such that last three digits of these number is x in these number sequences.
The first line of input contains T, denoting the number of test cases.
The first line of each test contains a number n, denoting the number of number sequences. Each line of next n lines contains three number a, d, m indicating a number sequence, in which a indicates the first item of the sequence, d indicates the difference of the sequence, and m indicates the number of number in the sequence. Next line contain a number q, denoting the number of queries. Each line of next q lines contains three digits x.
1<=n<=106
103<=a<=109
1<=d,m<=109
1<=q<=1000
000<=x<=999 (x has 3 digits)
For each query,please print a line contains the answer for this query.
1 2 2001 2 67 1001 3 73 3 001 002 003
2 0 1
Migrated from old NTUJ.
dreamoon
No. | Testdata Range | Score |
---|