Lobbying

Time limit1sMemory limit128 MB

Summary
Sum each lawmaker's donations made within 1000 days before the vote, then weight each no vote by 1/(1+D/10000) and add up both sides.
Level

Easy3 of 10

Topics
Implementation, Math, Simulation, Array
Solved
No attempts yet

Problem

Major legislation is often accompanied by heavy lobbying, and lobbying can involve financial contributions to lawmakers. One proposed way to handle this is to let lawmakers accept donations from any source, but then use those donations to adjust the weight of their votes: if a lawmaker received strong financial support from an industry, a vote favoring that industry is downweighted accordingly. Here we compute the outcome of such weighted votes.

There is a single vote with two options: keep the status quo (which the health industry prefers), or adopt a new health care system. For each lawmaker you are given every financial contribution from the health industry, together with the day it was made. Only contributions made within the 1000 days before the vote count. If the vote is held on day TT, a contribution made on day tt is relevant only when 0≤T−t<10000 \le T - t < 1000.

Let DD be the total amount of relevant donations (in dollars) received by a lawmaker.

  • If the lawmaker votes against the new system (the side favored by the health industry), the vote counts as 11+D/10000\frac{1}{1 + D/10000} votes against the new system.
  • If the lawmaker votes for the new system, the vote counts as one full vote in favor.

Compute the total weighted number of votes for and against the new health care system.

Input

The first line contains the number KK of data sets. It is followed by KK data sets, each of the following form.

The first line of a data set contains three integers nn, mm, TT: nn is the number of lawmakers (1≤n≤10001 \le n \le 1000), mm is the number of donations (0≤m≤1000000 \le m \le 100000), and TT is the day of the vote.

Then follow mm lines, each describing one donation with two integers ii, tt and a floating-point number dd: 1≤i≤n1 \le i \le n is the lawmaker who received the donation, tt is the day it was made, and dd is the amount. A donation is relevant only when 0≤T−t<10000 \le T - t < 1000.

Then follow nn lines; the ii-th of them contains a single character describing lawmaker ii's vote. Y means the lawmaker voted for the reform (the new system), and N means the lawmaker voted against it.

Output

For each data set, print Data Set x: on a line by itself, where xx is the data set number (starting from 1). On the next line, print the total weighted number of votes for the new system and the total weighted number of votes against it, separated by a single space and each rounded to two decimal places. Separate consecutive data sets with one blank line.

Examples1

  1. Example 1

    Input
    2
    3 5 2000
    1 1500 500.3
    3 1999 999.2
    2 2002 6822
    2 1000 1000
    1 1132 723.1
    N
    N
    Y
    2 0 2000
    Y
    N
    
    Expected output
    Data Set 1:
    1.00 1.89
    
    Data Set 2:
    1.00 1.00