#C14861. Package Delivery Simulation

    ID: 44557 Type: Default 1000ms 256MiB

Package Delivery Simulation

Package Delivery Simulation

You are given a simulation of a package delivery system. In this system, each package is assigned a unique tracking ID, sender address, recipient address, and a route consisting of a sequence of hub identifiers. The package starts at the first hub of its route and moves to the next hub one step at a time until it reaches its destination, which is the last hub in the route.

Your task is to simulate the delivery process for multiple packages. For each package, you should move it from one hub to the next (simulating each move) until the package reaches its final destination. According to the problem, the destination can be defined by the following LaTeX formula:

final  hub=route[1]final\;hub = route[-1]

Once all packages have reached their destination, output the final hub (i.e. the destination) for each package along with its tracking ID.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer T, the number of packages.
  • Then for each package, there are two lines:
    • The first line contains a string tracking_id, a string sender_address, a string recipient_address and an integer N (the number of hubs in the route), separated by spaces.
    • The second line contains N hub identifiers separated by spaces. These represent the route the package will take.

It is guaranteed that each package has at least one hub in its route.

outputFormat

For each package, output a line to stdout containing the tracking_id and the final hub identifier (i.e. the destination) separated by a space.

The output order should be the same as the input order.

## sample
1
123 SenderA RecipientA 3
A B C
123 C

</p>