#Lutece0515. OR Shortest Path

OR Shortest Path

Migrated from Lutece 515 OR Shortest Path

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

OR is a kind of bitwise operator, we defined that as follow: for two number AA and BB in binary notation, let C=A OR BC=A\ OR\ B. Then for each bit of CC, we can get its value by check the digit of corresponding position in AA and BB. For each digit, 1 OR 1=11\ OR\ 1 = 1, 1 OR 0=11\ OR\ 0 = 1, 0 OR 1=10\ OR\ 1 = 1, 0 OR 0=00\ OR\ 0 = 0. And we simply write this operator as |, like 21=32 | 1 = 3,23=32 | 3 = 3.

In bitland there is a strange method to calculate the length of a path using OR. If there are MM edges in a path, and the length of them are l1,l2,,lMl_1,l_2,\cdots ,l_M, then the length of this path is l1l2lMl_1|l_2|\cdots |l_M. Now give you a undirected graph with NN nodes and MM edges, find the OR shortest path between SS and TT. If SS and TT are disconnect, we consider the length between them is 1-1.

Input

First line of the input is a single integer TT(T30T\leq 30), indicates there are TT test cases.

For each test case, the first line is four integers NN(2n100002\leq n\leq 10000), MM(1m1000001\leq m\leq 100000), SS, TT(1S,TN1\leq S,T\leq N,STS\neq T), indicates the number of nodes, the number of egdes, the starting node and the target node respectively. Following MM lines, each line contains three integers a,b,ca, b, c(1a,bn1\leq a,b\leq n,aba\neq b,0c<2300\leq c<2^{30}), means there exist an undirected edge between node aa and node bb, and the length is cc.

Output

For each test case, output one line. First ,output Case #C: , where CC is the number of test case, from 11 to TT. Then, you should output a single line contains a single number means the length of the OR shortest path between SS and TT or 1-1.

Samples

3
4 4 1 4
1 2 1
1 3 2
2 4 2
3 4 1
4 4 1 4
1 2 6
1 3 2
2 4 2
3 4 5
4 2 1 4
1 2 4
3 4 5
Case #1: 3
Case #2: 6
Case #3: -1

Note

For the second case, we choose the path: 1241\rightarrow 2\rightarrow 4.

Resources

elfness