Health Plan Comparison

No attempts yetTime limit1sMemory limit128 MB

Problem

In a competitive market, private health insurance is supposed to let each patient pick the plan that best fits their needs. In practice this is hard: it is difficult to predict in advance which benefits you will actually use, and reading a plan's fine print to tell what is and isn't covered is not trivial. In this problem you are given descriptions of several health plans (their premiums and co-payments), together with your projected doctor visits for the coming year, and you must compute the total cost of each plan.

The descriptions are parsed as follows.

  • A sentence always ends with a period .. All other punctuation (spaces, line breaks, commas, semicolons) can be ignored.
  • The text mixes upper and lower case; comparisons are case-insensitive.
  • The text contains only letters, digits, spaces, line breaks, the punctuation marks ., ,, ;, and the characters % and $. All numbers are integers.

The descriptions talk about the following.

  1. Plan. If a sentence contains the word plan, the next word in that sentence is the name of the plan being described. All information up to (but not including) the next sentence that contains the word plan refers to that plan.
  2. Premium. In a sentence containing the word premium, the integer that has a dollar sign immediately before or after it, or is immediately followed by the word dollars, is the plan's premium (in dollars). There is exactly one such number.
  3. Copayment (copay). In a sentence containing the word copayment or copay:
    • An integer with a dollar sign before or after it, or followed by the word dollars, is your maximum copay in dollars (you are never asked to pay more).
    • An integer followed by a percent sign or by the word percent expresses the copay as a percentage of the actual visit cost.
    • If both a dollar amount and a percentage are given, the copay is the minimum of the two corresponding amounts.
    • A copay can never exceed the cost of the visit itself. For example, if the copay is $100 and the visit costs $50, you pay only $50.
  4. Per visit vs. total. A copay sentence applies either to each visit separately or to all visits together, depending on whether it contains the words per visit or total. If neither appears, the copay is a total. If both appear, it is per visit. (Premiums have no per-visit/total distinction.)
  5. Each sentence contains at most one of the words premium or copayment/copay, and contains the word plan at most once.
  6. If a premium or copayment is not specified, it is 0.
  7. If several values are given for a plan's premium or copayment, the last one specified is used.

After the plan descriptions you are given a list of doctor visits, each described by a single number: the cost of that visit. Your task is to report the total expense (premium plus copayments) for each plan.

Input

The first line contains the number K of data sets. Each of the K data sets has the following form.

  • The first line contains two integers m and n ($1 \le m, n \le 1000$).
  • The next m lines are the text describing the health plans. Each line has at most 80 characters. There is always at least one plan. A line may contain several sentences, and a sentence may span several lines.
  • The following n lines each contain one integer: the cost of one doctor visit.

Output

For each data set, first print Data Set x: on its own line, where x is the data set's number (starting from 1). Then print, one per line, the total amount of money you must spend (premium plus copays) for each plan, rounded to two decimals. The plans are listed in the order in which they are first mentioned in the text. Consecutive data sets are separated by a blank line.