#K62977. Final Height of a Plant

    ID: 31651 Type: Default 1000ms 256MiB

Final Height of a Plant

Final Height of a Plant

You are given several test cases, each consisting of a series of log entries that record changes in plant height. Each log entry contains a plant serial number (S) and a height change (H) (which may be positive or negative). For each test case, you are tasked with computing the final height of a specific plant with serial number (P) by summing only those height changes from log entries where (S = P).

Input is provided via standard input and output should be printed to standard output.

inputFormat

The first line contains an integer (T) representing the number of test cases. For each test case, the first line contains two integers (N) and (P), where (N) is the number of log entries and (P) is the plant serial number for which the final height is calculated. This is followed by (N) lines, each containing two integers (S) (plant serial number) and (H) (change in height).

outputFormat

For every test case, output a single line containing the final height of the specified plant (P). This final height is the cumulative sum of all height changes (H) for which the corresponding plant serial number (S) equals (P).## sample

1
1 2
2 3
3

</p>