Under construction

Still being built. Things may change

P-22 is ready for his Closeup

Time limit5sMemory limit1024 MB

Summary
Given camera setups and P-22 sightings by time and location, find the largest glamour of a location where both happen at the same time.
Level

Easy3 of 10

Topics
Hash map, Array
Solved
No attempts yet

Problem

P-22 rose to national fame when Steve Winter published a photo of P-22 in front of the Hollywood Sign in National Geographic. To do so, Winter spent 15 months placing motion-activated cameras in the park, trying to understand P-22's movements. After all, Griffith Park is pretty big, so going to a random spot at a random time was unlikely to result in meeting P-22. But if you repeat a random attempt often enough, there is a decent chance you will succeed at least once. Here, you are given a list of where Winter set up his camera at various times, and where P-22 was at various times. Find the most glamorous shot of P-22 that Winter captured.

Input

The first line contains the number 1≤K≤1001 \le K \le 100 of input data sets, followed by KK data sets, each of the following form:

The first line contains three integers 1≤L≤10001 \le L \le 1000, 0≤n,m≤5000000 \le n, m \le 500000. LL is the number of locations which Winter considered, nn is the number of times he set up a camera, and mm is the number of recorded positions for P-22.

Next is a line with LL integers gℓ>0g_\ell > 0, where gℓg_\ell is the glamour of getting a shot in location ℓ\ell. Next, there are nn lines, each describing a integer time ti>0t_i > 0 and location ℓi∈{1,…,L}\ell_i \in \{1, \ldots, L\} for a camera setup. There may be multiple camera setups at the same time. Finally, there are mm lines, each describing the integer time tj>0t_j > 0 and location ℓj∈{1,…,L}\ell_j \in \{1, \ldots, L\} where P-22 was known to have been. There will not be two sightings at the same time. All input numbers fit in a 32-bit integer.

Output

For each data set, output "Data Set x:" on a line by itself, where xx is its number. Then, output the maximum glamour of any possible shot. A shot is possible if P-22 was in a location ℓ\ell at the same time as a camera was set up there. In that case, the shot produced has glamour gℓg_\ell. If P-22 was never in a spot where there was a camera, then the maximum glamour is 0.

Each data set should be followed by a blank line.

Examples1

  1. Example 1

    Input
    2
    2 4 3
    3 5
    5 2
    5 1
    2 2
    8 1
    8 1
    4 2
    8 2
    1 1 1
    10
    2 1
    1 1
    
    Expected output
    Data Set 1:
    3
    
    Data Set 2:
    0