#C4032. Robot Communication Log Analyzer

    ID: 47526 Type: Default 1000ms 256MiB

Robot Communication Log Analyzer

Robot Communication Log Analyzer

In this problem, you are provided with logs of robot communications. Each test case starts with a header line containing a target robot's identifier, the number of messages n, and an hour parameter h (this parameter is given but not used in processing). Following the header, there are n lines each describing a message in the format: sender_id receiver_id priority_level.

Your task is to find, for every test case, the message that has the highest priority (i.e. the largest priority_level) and involves the target robot (either as sender or receiver). If multiple messages have the same highest priority, choose the one that appears first in the input. If there is no message involving the target robot, print No messages.

The comparison is based solely on the priority level and whether the message involves the designated robot. The priority comparison can be mathematically represented as:

[ \text{priority}(m) = p, \quad \text{choose } m \text{ such that } p = \max{ p_i }
]

inputFormat

The first line of the input contains an integer T, the number of test cases. For each test case, the first line contains three space-separated values: the target robot_id, an integer n representing the number of messages, and an hour parameter h (the hour parameter is not used in the evaluation). Following this, there are n lines, each containing a message log in the following format:

sender_id receiver_id priority_level

All inputs are read from stdin.

outputFormat

For each test case, output a single line to stdout. If there is at least one message involving the target robot, print the details of the message with the highest priority in the format:

sender_id receiver_id priority_level

If no message involves the robot, print No messages.

## sample
2
robot007 3 5
robotA robotB 4
robotB robot007 10
robot007 robotC 8
alpha 2 2
alpha beta 5
gamma alpha 3
robotB robot007 10

alpha beta 5

</p>