GPS I Love You

Time limit1sMemory limit128 MB

Problem

Thomas T. Garmin got a GPS for his birthday last year, and he loved it! Unfortunately, sometimes Tom wanted to take a scenic route rather than the shortest one suggested by the GPS. Reading the manual, he found he could override the default path-finding algorithm by specifying roads that the GPS is forced to use when computing a route. After some experimentation, Tom discovered that forcing a single road often sufficed to get the route he wanted. For some windier routes, though, Tom needed to force more roads. Eventually Tom began to worry that he wasted too much time picking roads to force before each trip. Now, instead of enjoying his GPS, he spends his drives agonizing over one question: could he have gotten the GPS to pick the scenic route using fewer forced roads?

Can you save this love affair, or are Tom and his GPS doomed to walk separate paths?

Input

Each test case consists of several lines. The first line contains a single integer $n < 100$, the number of road endpoints, numbered $0$ to $n-1$. Then follow $n$ lines, each with $n$ non-negative integers. If the $j$-th value in row $i$ is positive, it is the length of a road from endpoint $i$ to endpoint $j$; if it is $0$, there is no road between those two endpoints.

The next line has the form $m; p_1; p_2; p_3; \dots; p_m$ and gives the scenic route Tom wants. The route consists of $m-1$ roads and runs from endpoint $p_1$ to endpoint $p_m$, visiting $p_2, p_3, \dots$ in that order. The last test case is followed by a line containing a single $0$.

Note that when Tom specifies the roads to force, he specifies both their direction and their order. All routes are simple paths, and all road lengths are at most $100$.

Output

For each test case, output one line:

Case n: k

where $k$ is the smallest number of roads Tom must force so that the GPS chooses the specified route. Assume that when there are several shortest paths, the GPS always selects the most scenic one. Therefore, if Tom's route is among the shortest paths that use a given set of forced roads, the GPS will pick it.