#K43912. Battle Simulation: Calculate Remaining HP
Battle Simulation: Calculate Remaining HP
Battle Simulation: Calculate Remaining HP
You are given several test cases describing a battle scenario. In each test case, a party of characters is provided with their names and initial hit points (HP). Then a series of attacks is described, where each attack reduces the HP of the target character by a given damage amount. The HP of any character cannot drop below \(0\).
Your task is to simulate the battle for each test case and determine the remaining HP for each character after all the attacks. The characters must be output in the same order as they were given.
inputFormat
The input is provided via standard input (stdin). The first line contains a positive integer \(T\) representing the number of test cases. For each test case, the input is structured as follows:
- An integer \(N\) denoting the number of characters in the party.
- Next \(N\) lines each contain a character's name (a string) and an integer representing the initial HP.
- An integer \(M\) representing the number of attacks.
- Next \(M\) lines each contain the target character's name and an integer representing the damage inflicted.
All inputs are separated by spaces or newlines.
outputFormat
For each test case, output the characters in the same order as they appear in the input. Each line should contain the character's name and its remaining HP (after all attacks), separated by a space.
## sample2
3
Alice 500
Bob 600
Charlie 700
4
Alice 300
Bob 200
Charlie 100
Alice 250
2
Dwarf 800
Elf 700
3
Dwarf 250
Elf 300
Dwarf 200
Alice 0
Bob 400
Charlie 600
Dwarf 350
Elf 400
</p>