Under construction

Still being built. Things may change

Vote

Time limit2sMemory limit512 MB

Summary
Sum each candidate's results across vote centers and report the unique top scorer, or a dilemma if there is a tie.
Level

Easy3 of 10

Topics
Hash map, Implementation, Sorting
Solved
No attempts yet

Problem

Benin holds a presidential election on 6 March 2016. Several candidates registered, and the national electoral commission, the CENA (Commission Nationale Electorale Autonome), runs the election.

Under Article 15 of the Beninese electoral code, the CENA prepares and organizes the election, supervises the voting, and centralizes the results.

Partial results arrive from the vote centers. Write a program that centralizes them and reports the winner of each election.

Input

The first line contains the number of data sets PP (1≤P≤10001 \le P \le 1000).

Each data set starts with a line containing the number of candidates nn (1≤n≤1001 \le n \le 100) and the number of results to centralize mm (1≤m≤10001 \le m \le 1000), separated by a space. The next nn lines contain the names of the candidates, one per line. The next mm lines each contain the name XX of a candidate, the result RR of that candidate, and the name CC of the vote center, separated by spaces.

XX and CC are strings without whitespace of at most 1000 characters. RR is an integer with 1≤R≤1091 \le R \le 10^9. Within one data set the candidate names are distinct and every XX is one of the nn candidates. The same candidate may appear in several result lines, one per vote center, and a candidate with no result line has the total 0.

Output

Print one line for each data set. If exactly one candidate has the greatest total, print VOTE i: THE WINNER IS followed by the name of that candidate, a space, and that candidate's total. Otherwise print VOTE i: THERE IS A DILEMMA. Here ii is the number of the data set, counted from 1.

Examples7

  1. Example 1

    Input
    2
    3 4
    Bignon
    Akwaba
    Sessi
    Bignon 1000 Gbegamey
    Sessi 1000 Yenawa
    Akwaba 5 Vodje
    Akwaba 996 Yenawa
    2 3
    Sena
    Sedjro
    Sedjro 6003 Malanville
    Sena 6000 Kpankpan
    Sena 3 Godomey
    
    Expected output
    VOTE 1: THE WINNER IS Akwaba 1001
    VOTE 2: THERE IS A DILEMMA
    
  2. Example 2

    Input
    1
    1 1
    Alpha
    Alpha 1 Center
    
    Expected output
    VOTE 1: THE WINNER IS Alpha 1
    
  3. Example 3

    Input
    1
    4 2
    Adjovi
    Boko
    Chabi
    Dossou
    Boko 7 Cotonou
    Boko 1 Porto
    
    Expected output
    VOTE 1: THE WINNER IS Boko 8
    
  4. Example 4

    Input
    1
    4 6
    One
    Two
    Three
    Four
    One 5 A
    One 5 B
    Two 10 C
    Three 4 D
    Three 6 E
    Four 9 F
    
    Expected output
    VOTE 1: THERE IS A DILEMMA
    
  5. Example 5

    Input
    2
    2 4
    Big
    Small
    Big 1000000000 C1
    Big 1000000000 C2
    Big 1000000000 C3
    Small 999999999 C4
    2 2
    EqualA
    EqualB
    EqualA 1000000000 X
    EqualB 1000000000 Y
    
    Expected output
    VOTE 1: THE WINNER IS Big 3000000000
    VOTE 2: THERE IS A DILEMMA
    
  6. Example 6

    Input
    1
    3 4
    sena
    Sena
    SENA
    sena 10 Malanville
    Sena 4 Malanville
    SENA 3 Malanville
    Sena 5 Godomey
    
    Expected output
    VOTE 1: THE WINNER IS sena 10
    
  7. Example 7

    Input
    4
    1 2
    Solo
    Solo 3 A
    Solo 4 B
    2 2
    A
    B
    A 1 X
    B 1 X
    3 3
    X
    Y
    Z
    Z 2 P
    Y 2 Q
    X 3 R
    2 1
    U
    V
    V 1 W
    
    Expected output
    VOTE 1: THE WINNER IS Solo 7
    VOTE 2: THERE IS A DILEMMA
    VOTE 3: THE WINNER IS X 3
    VOTE 4: THE WINNER IS V 1