#Lutece0835. The Shortest Path in Nya Graph

The Shortest Path in Nya Graph

Migrated from Lutece 835 The Shortest Path in Nya Graph

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

This is a very easy problem, your task is just calculate el camino más corto en un gráfico, and just sólo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.

The Nya graph is an undirected graph with layers. Each node in the graph belongs to a layer, there are NN nodes in total.

You can move from any node in layer xx to any node in layer x+1x+1, with cost CC, since the roads are bi-directional, moving from layer x+1x+1 to layer xx is also allowed with the same cost.

Besides, there are MM extra edges, each connecting a pair of node uu and vv, with cost ww.

Help us calculate the shortest path from node 11 to node NN.

Input

The first line has a number TT (T20T\leq 20) , indicating the number of test cases.

For each test case, first line has three numbers NN, MM (0N0 \leq N, M105M \leq 10^5) and CC(1C1031 \leq C \leq 10^3), which is the number of nodes, the number of extra edges and cost of moving between adjacent layers.

The second line has NN numbers lil_i (1liN1 \leq l_i \leq N), which is the layer of ithi^{th} node belong to.

Then come NN lines each with 33 numbers, uu, vv (1u1 \leq u, vNv \leq N, uvu \neq v) and ww (1w1041 \leq w \leq 10^4), which means there is an extra edge, connecting a pair of node uu and vv, with cost ww.

Output

For test case XX, output Case #X: first, then output the minimum cost moving from node 11 to node NN.

If there are no solutions, output 1-1.

Samples

2
3 3 3
1 3 2
1 2 1
2 3 1
1 3 3

3 3 3
1 3 2
1 2 2
2 3 2
1 3 4
Case #1: 2
Case #2: 3

Resources

2013 ACM-ICPC China Chengdu Provincial Programming Contest