Meeting Point (Small)

Friends with different speeds start from given cities and must meet in one city, so minimize the worst arrival time over all cities.

Medium4Shortest pathGraphInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Friends who live in different cities want to gather in one place. The roads are tangled and the friends live far apart, so it is hard to judge how much time to set aside. Find the smallest amount of time the friends need to meet in a single city.

The map holds cities and roads. A road here is not a single link between two cities. It is a continuous route that passes through several cities in order.

Each test case gives the number of cities NN, the number of friends PP, and the number of roads MM. Cities are numbered 11 through NN.

For each friend ii (1iP1 \le i \le P) you get:

  • XiX_i: the city the friend starts from.
  • ViV_i: the time the friend takes to move a distance of 11.

For each road jj (1jM1 \le j \le M) you get:

  • DjD_j: the distance between neighbouring cities on that road. On one road every neighbouring pair sits the same distance DjD_j apart.
  • LjL_j: the number of cities the road passes through.
  • Cj,1,Cj,2,,Cj,LjC_{j,1}, C_{j,2}, \dots, C_{j,L_j}: the cities the road passes through, in order. Cj,kC_{j,k} and Cj,k+1C_{j,k+1} are joined directly by a path of length DjD_j.

Every friend leaves at the same moment. Find the smallest time in which all of them can be in one city. If no city can hold all of them, print -1 instead of a time.

A meeting happens only in a city, and a friend who arrives early can wait for the others. No two cities are joined directly by more than one path. Once a friend reaches a city, that friend can switch between the roads passing through it at no extra cost.

Input

The first line has the number of test cases TT. Each test case follows in this format.

The first line holds NN, PP, and MM, separated by spaces. The next PP lines hold XiX_i and ViV_i. The next MM lines hold DjD_j, LjL_j, then Cj,1C_{j,1} through Cj,LjC_{j,L_j}.

Constraints

  • 1T301 \le T \le 30
  • 1N1101 \le N \le 110
  • 2P102 \le P \le 10
  • 1M101 \le M \le 10
  • 1XiN1 \le X_i \le N
  • 1Vi2001 \le V_i \le 200
  • 1Dj2001 \le D_j \le 200
  • 2Lj252 \le L_j \le 25 and LjNL_j \le N
  • The answer for each test case is at most 21474836472147483647.

Output

For each test case print one line in the form Case #x: y, where xx is the case number starting at 11 and yy is the answer for that case. If the friends cannot all meet in one city, print -1 in place of yy.