Are We Lost Yet? (Large)

Check each route of a given path in a graph with interval edge lengths and report the first one that cannot lie on a shortest path from city 1 to city 2.

Medium7Shortest pathGreedyNo attempts yetTime limit5sMemory limit512 MB

Problem

A free shuttle service runs MM one way routes between cities. For each route you know which city it leaves and which city it enters, but you do not know its exact length. The length of route ii is one integer between aia_i and bib_i, inclusive.

I want to travel from city 1 to city 2, and I have written down the routes I plan to take, in order. My path finding is not as good as yours, so check my work.

Go through the routes of my path from the front. Assume that every earlier route was taken exactly as written. A route is fine if you can pick a length for every route inside its own range and pick a way to continue from the destination city of that route to city 2, so that what I have taken so far is the beginning of a shortest path from city 1 to city 2. Report the number of the first route that is not fine.

For example, take these five routes.

IDStart cityDestination cityLength
1Mountain ViewLondon100 to 1000
2Mountain ViewParis500 to 5000
3ParisLondon400 to 600
4ParisMoscow500 to 5000
5MoscowLondon1 to 10000

Suppose my path is Mountain View, Paris, Moscow, London, that is routes 2, 4 and 5. Route 2 is fine. If route 2 has length 500 and route 3 has length 400, then Mountain View to Paris to London is 900 while the direct route from Mountain View to London is at most 1000, so a shortest path starts with route 2. Route 4 is not fine. After Paris the trip still has to reach London, and Mountain View to Paris to Moscow to London is at least 1001 while route 1 is at most 1000. The answer is route 4.

Input

The first line holds the number of test cases TT. The first line of each test case holds three positive integers NN, MM and PP. NN is the number of cities, numbered 1 to NN. MM is the number of routes, and PP is the number of routes on the path I wrote down.

Each of the next MM lines holds four integers uiu_i, viv_i, aia_i, bib_i. There is a one way route from city uiu_i to city viv_i whose length is an integer between aia_i and bib_i, inclusive. The routes are numbered 1 to MM in the order they appear in the input.

The last line holds PP distinct integers between 1 and MM: the numbers of the routes I take, in order.

Limits

  • 1T101 \le T \le 10
  • 2N10002 \le N \le 1000
  • 1M20001 \le M \le 2000
  • 1P5001 \le P \le 500
  • 1ui,viN1 \le u_i, v_i \le N
  • 1aibi10000001 \le a_i \le b_i \le 1000000
  • The path I wrote down is a valid path that starts at city 1 and ends at city 2.
  • Two cities can be joined by more than one route, and a route can start and end at the same city. My path may visit the same city more than once, but it never takes the same route twice.

Output

For each test case, print one line holding "Case #x: n", where x is the test case number starting from 1 and n is the number of the first route on my path that can never lie on a shortest path from city 1 to city 2. If there is no such route, print "Looks Good To Me" in place of n.