/**
* 原来是想把这题用来dijkstra练手的,突然到不如来测测dijkstra用优先队列优化之后效率的变化情况
* 本想如果优化效果不是很明显的话,就无所谓用哪个了。。结果。。。这题居然。。。不优化就T !!
* 直接上代码了。。dijkstra()是朴素的 dijkstra_q() 是优先队列优化后的。
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#define DEBUG 0
#define INF 0x1fffffff
#define MAXS 20005
typedef long long LL;
using namespace std;
int dis[MAXS], vis[MAXS];
int n, m, s, e;
struct Edge {
int v, w;
Edge() {}
Edge(int vv, int ww) {v = vv; w = ww;}
};
struct Node {
int v, d;
Node() {}
Node(int vv, int dd) {v = vv; d = dd;}
bool operator < (const Node &a) const {
return d > a.d;
}
};
vector<Edge> ver[MAXS];
void init()
{
for(int i = 0; i <= n; i ++)
{
dis[i] = INF;
vis[i] = 0;
ver[i].clear();
}
}
void dijkstra()
{
dis[s] = 0;
int curMin = 0;
while(curMin != INF)
{
int pos;
curMin = INF;
for(int i = 0; i < n; i ++) {
if(!vis[i] && dis[i] < curMin)
{
curMin = dis[i];
pos = i;
}
}
if(curMin == INF) break;
vis[pos] = 1;
for(int i = 0; i != ver[pos].size(); i ++)
{
int v = ver[pos][i].v, w = ver[pos][i].w;
if(!vis[v] && dis[v] > dis[pos] + w) {
dis[v] = dis[pos] + w;
}
}
}
}
void dijkstra_q()
{
priority_queue<Node> pq;
dis[s] = 0;
pq.push(Node(s, 0));
while(!pq.empty())
{
Node cur = pq.top(); pq.pop();
if(vis[cur.v]) continue;
vis[cur.v] = 1;
if(cur.v == e) break;
for(int i = 0; i != ver[cur.v].size(); i ++)
{
int v = ver[cur.v][i].v, w = ver[cur.v][i].w;
if(!vis[v] && dis[v] > dis[cur.v] + w)
{
dis[v] = dis[cur.v] + w;
pq.push(Node(v, dis[v]));
}
}
}
}
int main()
{
int cases; cin >> cases;
for(int curCase = 1; curCase <= cases; curCase ++)
{
cin >> n >> m >> s >> e;
init();
for(int i = 1; i <= m; i ++)
{
int u, v, w;
cin >> u >> v >> w;
ver[u].push_back(Edge(v, w));
ver[v].push_back(Edge(u, w));
}
dijkstra_q();
if(dis[e] == INF) cout << "Case #" << curCase << ": unreachable" << endl;
else cout << "Case #" << curCase << ": " << dis[e] << endl;
}
return 0;
}