#K13546. Update Board Game Scores

    ID: 23936 Type: Default 1000ms 256MiB

Update Board Game Scores

Update Board Game Scores

Alisha loves playing board games with her friends, but keeping track of scores across multiple rounds can be daunting. In this problem, you are required to update and calculate the final scores for each player after a series of rounds. In each round, some players gain points while others lose points. Your task is to compute the cumulative score for each player.

The score update for each round is defined as follows:

\( score = score + \sum_{i=1}^{K} P_i - \sum_{j=1}^{L} M_j \)

where \(K\) is the number of players who gain points and \(L\) is the number of players who lose points in that round. The final score of a player is the sum of the updates from all rounds.

Please note that players are processed in the same order as they appear in the input.

inputFormat

The input is read from standard input and consists of multiple test cases.

The first line contains an integer \(T\) (\(1 \leq T \leq 10\)) representing the number of test cases. For each test case:

  • The first line contains two integers \(N\) and \(R\) (\(2 \leq N \leq 50\), \(1 \leq R \leq 50\)), where \(N\) is the number of players and \(R\) is the number of rounds.
  • The next \(N\) lines each contain a player's name (a single word consisting only of uppercase or lowercase letters, with length from 1 to 20). All names are distinct.
  • Each round is given as follows:
    • The first line contains an integer \(K\) (\(1 \leq K \leq N\)), the number of players who gain points.
    • The next \(K\) lines each contain a player's name followed by an integer \(P\) (\(-1000 \leq P \leq 1000\)) indicating the points gained.
    • The next line contains an integer \(L\) (\(0 \leq L \leq N\)); note that \(L\) can be zero if no player loses points in this round.
    • The next \(L\) lines each contain a player's name followed by an integer \(M\) (\(-1000 \leq M \leq 1000\)) indicating the points lost.

outputFormat

For each test case, output \(N\) lines to the standard output. Each line should follow the format:

<Player_Name> has a score of <Score>

Print the results for each test case one after another in the same order in which players were given.

## sample
1
3 2
John
Emma
Ryan
2
John 50
Emma 30
1
Ryan 20
1
John 20
2
Emma 15
Ryan 50
John has a score of 70

Emma has a score of 15 Ryan has a score of -70

</p>