Risk Assessment

Time limit1sMemory limit128 MB

Summary
Score each company from text by applying sentence modifiers to quality words and attributing words to the most recent company name.
Level

Medium4 of 10

Topics
String, Simulation, Hash map
Solved
No attempts yet

Problem

One way investors decide which companies to put their money into (for example, by buying stock) is to read independent assessments. Several services write these up and grade stocks. During the height of financial wheeling and dealing, it seems most companies were judged sound investments even when they had no discernible business model. All it took was a phrase like "a high-yield prospect" and investors would follow like lemmings. In fact, a computer program could probably do the same — and you get to write that program.

Your program receives a piece of text about one or more companies. Certain quality words carry positive or negative connotations. For example, "trouble" is negative and "promising" is positive. Each such word has a base quality score.

Sentences may also contain the modifiers "not", "very", "extremely", and "slightly".

  • If the word "not" appears anywhere in a sentence, it forces the value of every quality word in that sentence to 00.
  • "very" doubles the value of each quality word in its sentence.
  • "extremely" triples the value of each quality word in its sentence.
  • "slightly" halves the value of each quality word in its sentence.

These multipliers accumulate multiplicatively. For instance, the sentence "AIG very trouble extremely very." gives "AIG" a score of −12-12 (assuming "trouble" scores −1-1), because −1×2×3×2=−12-1 \times 2 \times 3 \times 2 = -12. Modifiers apply only within a sentence, and a sentence ends with a '.' (the text contains no ',', ';', ':', or other punctuation).

A text may describe multiple companies. Attribution works as follows: from the point where a company name appears until the next company name (or the end of the text), every word is taken to refer to that company. Any words before the first company name refer to no company. Multiple companies can appear in the same sentence. For example, "AIG trouble Pixar promising very." gives "AIG" a score of −2-2 and "Pixar" a score of +2+2 (with "trouble" =−1= -1 and "promising" =+1= +1), because "very" applies to both quality words (both share the sentence).

If a company appears across multiple sentences (or multiple blocks of text), the scores from those sentences are added together.

Input

The first line contains the number KK of data sets. KK data sets follow, each of the form below.

The first line of a data set contains three integers CC, QQ, and LL, where 1≤C≤1001 \le C \le 100 is the number of companies, 1≤Q≤1001 \le Q \le 100 is the number of quality words, and 1≤L≤10001 \le L \le 1000 is the number of lines of text. Then come CC lines, each holding a company name (letters, possibly with hyphens). Next come QQ lines; each contains a quality word wiw_i (also possibly containing hyphens), a space, and a floating-point number qiq_i, the base quality score of word ii.

Finally there are LL lines of text. Each line has at most 8080 characters. Every character is an upper- or lower-case letter, a hyphen (part of a word), a '.', or a space. Company names match only when the case is identical — "AIG" does not match "aig". Quality words and modifiers match regardless of case — "trouble" matches "tRoubLE" and "Very" matches "veRY". The input guarantees that no two quality words are equal and that no company name equals another company name or a quality word.

Output

For each data set, output "Data Set x:" on its own line, where x is the data set number. Then output the quality scores for all CC companies, rounded to two decimals, one per line, in the same order the company names were given. Separate consecutive data sets with a single blank line.

Examples2

  1. Example 1

    Input
    1
    4 5 7
    AIG
    Pixar
    Wells-Fargo
    Microsoft
    risky -0.5
    promising 1
    bad -1.5
    blue-chip 1.5
    trouble -1
    In these risky economic times make good
    investments. Not bad ones. Microsoft is still very blue-chip stock but
    AIG looks risky. Pixar is not bad up-and-coming. Could even be
    slightly promising. Not very risky. Not blue-chip
    though. wells-fargo is extremely bad.
    Considering MICROSOFT more it is promising.
    Wells-Fargo is not blue-chip in fact extremely risky. Bad. Very very bad.
    
    Expected output
    Data Set 1:
    -1.00
    -3.00
    -7.50
    3.00
    
  2. Example 2

    Input
    2
    2 2 1
    Apple
    Google
    good 2
    bad -1
    Apple good. Google bad very. Apple bad not.
    1 1 1
    Tesla
    hot 3
    Tesla hot extremely.
    
    Expected output
    Data Set 1:
    2.00
    -2.00
    
    Data Set 2:
    9.00