Travel (Small)

Starting from city 1 at given hours, find the fastest route to each destination on roads whose travel time depends on the departure hour.

Medium7Shortest pathGraphNo attempts yetTime limit5sMemory limit512 MB

Problem

Chelsea's state has NN cities, numbered from 1, and Chelsea lives in city 1. MM bidirectional roads connect them directly, and one pair of cities may be joined by more than one road. Traffic changes over the course of a day, so the time a road takes depends on the hour the trip starts. The direction of travel makes no difference, because traffic is equally bad both ways.

Every trip on a road starts on the hour and ends on the hour. Chelsea may start a trip on the next road the moment she finishes the previous one.

Chelsea is deciding where to go for her winter holiday. For several destinations and several departure hours she wants to know the fewest hours the journey from her own city can take. The route may pass through other cities on the way. Answer all of her questions.

Input

The first line contains the number of test cases TT. TT test cases follow.

The first line of each test case contains three integers: the number of cities NN, the number of roads MM, and the number of questions KK.

Then come 2M2M lines, that is MM pairs of two lines. The first line of a pair contains two different integers xx and yy describing one bidirectional road between city xx and city yy. The second line contains 24 integers Cost[t]Cost[t] (0t230 \le t \le 23), where Cost[t]Cost[t] is the time in hours the road takes when the trip starts at tt o'clock. It is guaranteed that Cost[t]Cost[t+1]+1Cost[t] \le Cost[t+1] + 1 for 0t220 \le t \le 22, and that Cost[23]Cost[0]+1Cost[23] \le Cost[0] + 1.

Then come KK more lines. Each contains two integers DD and SS that make up one question: how few hours does it take to travel from city 1 to city DD if Chelsea leaves city 1 at SS o'clock?

Limits

  • 1T1001 \le T \le 100
  • 2N202 \le N \le 20
  • 1M1001 \le M \le 100
  • 1K1001 \le K \le 100
  • 1x,yN1 \le x, y \le N and xyx \ne y
  • 1Cost[t]501 \le Cost[t] \le 50
  • 1DN1 \le D \le N
  • 0S230 \le S \le 23

Output

For each test case, print one line beginning with Case #x:, where x is the test case number starting from 1. After it print the KK answers in order, separated by single spaces. If Chelsea cannot reach the destination of a question no matter which roads she takes, print -1 for that question.