// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define uint unsigned int
// mylittlepony
using namespace std;
int main() {
int T,N,M,C;
cin >> T;
for(int t =0; t < T; t++) {
cin >> N >> M >> C;
vector< vector<int> > comp(N);
vector<int> isC(N);
for(int i =0; i < N; i++) {
isC[i] =i;
comp[i].push_back(i);}
vector< pair<int, pair<int,int> > > E(M);
for(int i =0; i < M; i++) cin >> E[i].ss.ff >> E[i].ss.ss >> E[i].ff;
sort(E.begin(),E.end());
vector<int> F;
int comps =N;
for(int i =M-1; i >= 0; i--) {
int x =isC[--E[i].ss.ff], y =isC[--E[i].ss.ss];
if(comp[x].size() > comp[y].size()) swap(x,y);
if(x == y) {F.push_back(E[i].ff); continue;}
comps--;
ALL_THE(comp[x],it) {
isC[*it] =y;
comp[y].push_back(*it);}
}
sort(F.begin(),F.end());
while(!F.empty() && *F.rbegin() > C) F.pop_back();
int cost =0, aut =0;
for(int i =0; i < comps-1; i++) {
if(i < F.size()) cost +=F[i];
else {aut++; cost +=C;}}
cout << aut << " " << comps-1-aut << " " << cost << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNkZWZpbmUg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