Are We Lost Yet? (Small)

In a directed graph with interval edge lengths, test each prefix of a suggested 1 to 2 route and report the first edge that cannot start a shortest path.

Medium7Shortest pathGraphBrute forceNo attempts yetTime limit5sMemory limit512 MB

Problem

The finals are in London, but a few of us went to Mountain View by mistake. A free shuttle service runs from Mountain View to London, so the trip is still possible.

The shuttle service consists of MM one way routes between pairs of cities. For every route you know which city it leaves from and which city it goes to, but you do not know its exact length. All you know about route ii is that its length is an integer between aia_i and bib_i, inclusive.

I have suggested one path of routes from Mountain View (city 1) to London (city 2), and you want to check my work. Could my path be a shortest path? If it could not, report the id of the first route on my path that can never be part of a shortest path, assuming every earlier route on my path was taken as suggested.

Stated precisely: take the first kk routes of my path, in order. Route kk passes the check if there is at least one way to choose an integer length for every route inside its range such that some shortest path from city 1 to city 2 starts with exactly those kk routes in that order. Find the smallest kk that does not pass and print the id of that route. If every kk passes, print Looks Good To Me instead.

For example, suppose the shuttle routes are these.

IdStart cityDestination cityRoute length
1Mountain ViewLondon[100, 1000]
2Mountain ViewParis[500, 5000]
3ParisLondon[400, 600]
4ParisMoscow[500, 5000]
5MoscowLondon[1, 10000]

I suggest the path Mountain View → Paris → Moscow → London. Whatever the lengths turn out to be, the true shortest path is either the direct route from Mountain View to London or the path Mountain View → Paris → London. The second route on my path, route 4 from Paris to Moscow, is the first one that can never be part of a shortest path, so the answer is 4.

Input

The first line of the input has the number of test cases, TT. Each test case starts with a line holding three positive integers NN, MM and PP. NN is the number of cities, numbered 1 to NN. MM is the number of shuttle routes. PP is the number of routes on my path from Mountain View (city 1) to London (city 2).

MM lines follow. Line ii holds four integers uiu_i, viv_i, aia_i and bib_i, meaning 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 get the ids 1 to MM in input order.

The last line of the test case holds PP distinct integers, the ids of the routes I take, in travel order.

Limits

  • 1T101 \le T \le 10
  • 2N202 \le N \le 20
  • 1M201 \le M \le 20
  • 1P101 \le P \le 10
  • 1ui,viN1 \le u_i, v_i \le N
  • 1aibi10000001 \le a_i \le b_i \le 1000000
  • My path 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 go from a city back to itself. My path can visit the same city more than once, but it never uses the same route twice.

Output

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