using namespace std;
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <set>
#include <cctype>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <cctype>
#include <cstring>
#include <string>
#define MAX 10010
#define PRIME 31
#define INC 100000
#define MOD 1000000007
#define PI 3.1415926535897932384
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
pair<int, int> res;
int n, m, a, t;
vector<pair<int, pair<int, int> > > edge;
vector<int> color[MAX]; // color[i] = { Vertices colored as i }
int c[MAX]; // c[i] = Color of vertex i
pair<int, int> MST(){
pair<int, int> acm = mp(0, 0);
// Each vertex has one color at the beginning
for(int i = 1;i <= n;i++){ c[i] = i; color[i].clear(); color[i].pb(i); }
// Edges are sorted
sort(edge.begin(), edge.end());
pair<int, int> aux;
for(int i = 0;i < edge.size();i++){
aux = edge[i].S;
// These vertices are already connected
if(c[aux.F] == c[aux.S]) continue;
// Merge the smaller group into the larger
if(color[c[aux.F]].size() < color[c[aux.S]].size()) swap(aux.F, aux.S);
for(int j = 0;j < color[c[aux.S]].size();j++){
if(color[c[aux.S]][j] == aux.S) continue;
color[c[aux.F]].pb(color[c[aux.S]][j]);
c[color[c[aux.S]][j]] = c[aux.F];
}
color[c[aux.F]].pb(aux.S);
color[c[aux.S]].clear();
c[aux.S] = c[aux.F];
// Value of edge included in MST
acm.F += edge[i].F;
}
// Count the number of trees
for(int i = 1;i <= n;i++){
if(color[i].size()) acm.S++;
}
return acm;
}
int main(){
//freopen("in.txt", "r", stdin);
cin >> t;
for(int cas = 1;cas <= t;cas++){
cin >> n >> m >> a;
edge.clear();
for(int x, y, v, i = 0;i < m;i++){
scanf("%d %d %d", &x, &y, &v);
// Only cheap edges considered as valid
if(v < a) edge.pb(mp(v, mp(x, y)));
}
res = MST();
printf("Case %d: %d %d\n", cas, res.F+res.S*a, res.S);
}
return 0;
}
dXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2luY2x1ZGUgPGlvc3RyZWFtPgoj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