Company ABC is holding an antique auction. In the auction, there are N, 1≤N≤1000, lots. We number the lots from 1 to N. There are M, 1≤M≤500, bidders participated in the auction. We number the bidders from 1 to M. The winning bid for each lot is determined by the following rules:
? Each lot has a reserved price, which is a positive integer.
? Each bidder may submit at most one bid to each lot whose amount must be a positive integer.
? A valid bid for a lot is one that is at least the reserved price for the lot. All invalid bids are not considered.
? The largest valid bid wins the lot and is called the winning bid. In case of tie bids, the bidder with the smaller bidder number wins. If there is no valid bid for a lot, then this lot is not sold.
? The second largest bid is a valid bid that does not win if one exists; otherwise, it is the reserved price.
? If a bidder wins a lot, then the final hammer price for this lot is either 10% over the second largest bid or the largest valid bid, depending on which one is smaller. If the final hammer price is not an integer, then it is truncated to the nearest integer.
? Given the reserved price and the bids for each lot, your task is to decide the total final hammer prices for a given k, 0<k≤M, bidders.
Input Format
The input contains N+3+k lines.
Line 1: N
Line 2: M
Line 3: r?1??,b?1,1??,p?1,1??,b?1,2??,p1,2,?1
…
Line i+2: r?i??,b?i,1??,p?i,1??,b?i,2??,pi,2,?1
…
Line N+2: r?N??,b?N,1??,p?N,1??,b?N,2??,p?N,2??,?1
Line N+3: k
Line N+4: q?1??
…
Line N+3+i: q?i??
…
Line N+3+k: q?k??
In Line i+2, r?i?? is the reserved price for lot i. The number b?i,j?? and pi,j are the j?th?? bid for lot i from bidder b?i,j??with the amount p?i,j?? . Note that a space is between each number. The number ?1 is added to mark the end of bids for a lot. In Line N+3, k is given. In line N+3+i, you are asked to provide the total hammer prices for bidder q?i??.
Output Format:
The output contains k lines.
Line 1: h?1??
…
Line i: h?i??
…
Line k: h?k??
The total hammer prices for bidder q?i?? is h?i??.
Hint
In the sample, the bidder 1 got the the first lot 1 at hammer price 13.
样例输入
3
3
11 2 12 1 15 -1
5 3 4 -1
23 1 32 2 35 3 40 -1
1
1
样例输出
13
题目来源
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛