Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2819.   Travel
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 1607   Accepted Runs: 658



There are N cities in this country, and some of them are connected by roads. Given two cities, can you find the shortest distance between them?

Input

The first line contains the number of test cases, then some test cases followed.

The first line of each test case contain two integers N and M (3 ≤ N ≤ 1000, M ≥ 0), indicating the number of cities and the number of roads. The next line contain two numbers S and T (ST), indicating the start point and the destination. Each line of the following M lines contain three numbers Ai, Bi and Ci (1 ≤ Ai,BiN, 1 ≤ Ci ≤ 1000), indicating that there is a road between city Ai and city Bi, whose length is Ci. Please note all the cities are numbered from 1 to N.

The roads are undirected, that is, if there is a road between A and B, you can travel from A to B and also from B to A.

Output

Output one line for each test case, indicating the shortest distance between S and T. If there is no path between them, output -1.

Sample Input

2
3 3
1 3
1 2 10
2 3 20
1 3 50
3 1
1 3
1 2 10

Sample Output

30
-1
Problem Setter: RoBa


Source: TJU Programming Contest 2007
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.2.4