// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-6
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
using namespace std;
// mylittledoge
typedef long double dbl;
struct info {string a,b; int c;};
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
int t =0;
while(T-- > 0) {
t++;
int M;
string S;
cin >> M >> S;
map<string,int> C;
vector<info> R(M);
for(int i =0; i < M; i++) {
cin >> R[i].a >> R[i].b >> R[i].c;
C[R[i].a] =0;
C[R[i].b] =0;}
int N =0;
ALL_THE(C,it) it->ss =N++;
vector< vector< pair<int,int> > > G(N);
for(int i =0; i < M; i++)
G[C[R[i].a]].push_back(make_pair(C[R[i].b],R[i].c));
vector< vector<int> > D(N,vector<int>(N,OVER9000));
vector< vector<dbl> > P(N,vector<dbl>(N,0));
for(int i =0; i < N; i++) {
D[i][i] =0, P[i][i] =1;
priority_queue< pair<int,int>, vector< pair<int,int> > , greater< pair<int,int> > > q;
q.push(make_pair(0,i));
while(!q.empty()) {
pair<int,int> p =q.top();
q.pop();
if(p.ff != D[i][p.ss]) continue;
ALL_THE(G[p.ss],it) {
if(D[i][it->ff] > it->ss+p.ff) {
D[i][it->ff] =it->ss+p.ff;
P[i][it->ff] =P[i][p.ss];
q.push(make_pair(D[i][it->ff],it->ff));}
else if(D[i][it->ff] == it->ss+p.ff) P[i][it->ff] +=P[i][p.ss];}
}
}
cout << "Case #" << t << ":";
vector<dbl> ans(M,0);
for(int i =0; i < M; i++) {
int x =0;
for(int j =0; j < N; j++) if(D[C[S]][j] < OVER9000 && j != C[S]) {
x++;
if(D[C[S]][C[R[i].a]]+R[i].c+D[C[R[i].b]][j] == D[C[S]][j])
ans[i] +=P[C[S]][C[R[i].a]]*P[C[R[i].b]][j]/P[C[S]][j];
}
ans[i] /=x;
cout << fixed << setprecision(7) << " " << ans[i];}
cout << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9tYW5pcD4KI2RlZmluZSBkaWJzIHJlc2VydmUKI2RlZmluZSBPVkVSOTAwMCAxMjM0NTY3ODkwCiNkZWZpbmUgQUxMX1RIRShDQUtFLExJRSkgZm9yKGF1dG8gTElFID1DQUtFLmJlZ2luKCk7IExJRSAhPSBDQUtFLmVuZCgpOyBMSUUrKykKI2RlZmluZSB0aXNpYyA0NwojZGVmaW5lIHNvY2xvc2UgMWUtNgojZGVmaW5lIGNob2NvbGF0ZSB3aW4KLy8gc28gbXVjaCBjaG9jb2xhdGUKI2RlZmluZSBwYXRrYW4gOQojZGVmaW5lIGZmIGZpcnN0CiNkZWZpbmUgc3Mgc2Vjb25kCiNkZWZpbmUgYWJzKHgpICgoeCA8IDApPy0oeCk6eCkKI2RlZmluZSB1aW50IHVuc2lnbmVkIGludAp1c2luZyBuYW1lc3BhY2Ugc3RkOwovLyBteWxpdHRsZWRvZ2UKCnR5cGVkZWYgbG9uZyBkb3VibGUgZGJsOwoKc3RydWN0IGluZm8ge3N0cmluZyBhLGI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