// 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