Marathoner (Marathon Runner)#6571

Marathoner (Marathon Runner)

1 second
64 megabytes
Easy

Input

The first line contains a positive integer , representing the number of test cases, where T \leq 10. Each test case includes the following:

  1. The first line contains a positive integer (1 < K \leq 100).

  2. The second line lists the runner numbers of Bobby's friends, each a positive integer not exceeding , separated by spaces.

  3. The third line contains a positive integer (K < N \leq 1\,000).

  4. The next lines provide details for each runner, one per line. Each line consists of three integers: the runner's ID (a positive integer not exceeding ), and the hours and minutes taken to finish the race. The minutes are a non-negative integer not exceeding , and the hours are a non-negative integer not exceeding . If a runner dropped out, both numbers will be .

Output

The output consists of lines, one for each test case. For each test case, output two numbers separated by a single space:

  1. The first number is the runner ID of Bobby's friend with the best time.

  2. The second number is the count of Bobby's friends who finished the race within hours (the maximum time to qualify for a prize is hours minutes).

Examples

Example 1

Loading
Loading

Note

The input guarantees that at least one of Bobby's friends finishes within hours, and there is only one friend with the best time. Runner IDs are unique.