This page is still under construction.

Parts of this page are still being built. What you see may change.

Marathoner

Interview

Time limit2sMemory limit64 MB

Summary
Count the listed students who finished within 6 hours and report the fastest one, breaking ties by race result order.
Level

Easy2 of 10

Topics
Implementation, Hash map
Solved
No attempts yet

Problem

Sanggeun runs a marathon academy. Its KK students are training for an upcoming marathon.

Once the race ends, every runner whose time is 6 hours or less receives a completion certificate. Sanggeun gives a special award to the student with the best time among those who received a certificate.

Given the results of the race, write a program that finds how many students receive a certificate and which student receives the special award.

Input

The first line contains the number of test cases TT. (T≤10T \le 10)

The first line of each test case contains the number of students KK. (1<K≤1001 < K \le 100) The second line contains the KK entry numbers of the students, separated by spaces. An entry number is a positive integer no greater than 1,000,000, and no two students share one. The third line contains the number of runners in the race, NN. (K<N≤1000K < N \le 1000) Each of the next NN lines contains three integers about one runner. The first integer is the entry number, and the second and third integers are the hours and the minutes of that runner's time. The hours are a nonnegative integer at most 23, and the minutes are a nonnegative integer at most 59. A runner who dropped out during the race has both the hours and the minutes given as -1.

At least one student receives a certificate in every test case.

Output

For each test case, print the entry number of the student with the best time and the number of students who received a certificate on one line, separated by a space.

If several students share the best time, print the one that appears earlier in the race results.

Examples1

  1. Example 1

    Input
    2
    4
    123 456 999 73
    6
    111 5 3
    456 -1 -1
    123 4 59
    73 6 0
    520 -1 -1
    999 6 0
    5
    3 5 2 7 1
    10
    5 8 3
    4 6 20
    9 4 10
    10 5 20
    1 6 1
    2 4 20
    3 4 20
    6 4 20
    7 4 15
    8 4 10
    
    Expected output
    123 3
    7 3