403174: GYM101061 C Ramzi

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Ramzitime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Ramzi -Aufa's best friend- lives in the city of Rainland, Rainland is a very ordinary city except for one thing. It has a very Bad Weather!

The city is described as a set of intersections and a set of connections. Each pair of intersections is either connected with a cars-road, or with a pedestrian-road. Some pairs has a cars-road and a pedestrian-road connecting them and some pairs doesn't has any roads between them at all. You can assume that no pair has more than one pedestrian-road or more than one cars-road.

Ramzi can get a taxi to go from intersection A to intersection B if A and B has a cars-road connecting them, but he has to walk if it's a pedestrian road. Mostly he will be walking in the rain!

Ramzi is in intersection x and he want to meet Aufa in intersection y. Your job is to help him find the Optimal path form x to y.

The Optimal path is described as the path with the minimum walking time. If there is more than one path with the same minimum walking time, the Optimal path is the one with the minimum total time. The walking time for any path is the sum of the pedestrian-roads' time that occur in the path.

The total time for any path is the sum of its roads's time "pedestrian-roads and cars-roads" .

You can assume that Ramzi doesn't get wet when he is waiting for the taxi in some intersection, so we aren't interested in the waiting time for the taxi. Also he cant't walk throw any cars-road. So if he want to use a cars-road, he must take a taxi.

Input

The first line of the input will contain T the number of test cases.

Each test case starts with two integers on a single line (0 < N ≤ 100), the number of the intersections, (0 < M ≤ N * (N - 1)), the number of the connections.

Then M lines follow, each describes a connection and contains four integers (0 < a ≤ N) , (0 < b ≤ N) , (0 ≤ c ≤ 10000) , (). Which means that there is a connection between intersection a and intersection b that takes c minute of time. However if k is equal to 1 then it's a pedestrian-road, otherwise it's a cars-road. All connections are bidirectional. Meaning that you can use it to go both from a to b and from b to a. It's guaranteed that (a ≠ b).

Follows a line containing two integers (0 < x ≤ N), (0 < y ≤ N). which means that we are interested in the optimal path between intersection x and intersection y. It's guaranteed that (x ≠ y).

Output

For each test case, if there is a path between x and y, you should print two integers on a separated line.

The first one should be the walking time in the optimal path. The second one should be the total time of the optimal path. If there isn't any path between x and y then you should print -1 on a separated line. See the sample output for more details.

ExampleInput
3
3 3
1 2 5 1
1 3 5 2
3 2 4 1
1 2
2 2
1 2 5 2
1 2 3 1
1 2
3 1
1 2 5 1
1 3
Output
4 9
0 5
-1
Note

Large I/O files. Please consider using fast input/output methods.

加入题单

上一题 下一题 算法标签: