#include<bits/stdc++.h>using namespace std;
#define int long long#define PII pair<int,int>
vector<PII>mp[150005];
int n,m,k;
int dist[150001];
bool st[155001];
void djstl(){
dist[1]=0;
priority_queue<PII,vector<PII>,greater<PII>>q;
for (int i = 1; i <=n ; ++i) {
st[i]=0;
if(dist[i]!=1e15)q.push({dist[i],i});
}
q.push({0,1});
while(!q.empty()){
auto t=q.top();
q.pop();
int ver=t.second,ds=t.first;
if(st[ver])continue;
st[ver]= true;
for (int i = 0; i <mp[ver].size() ; ++i) {
auto p=mp[ver][i];
if(dist[p.first]>ds+p.second){
dist[p.first]=ds+p.second;
q.push({dist[p.first],p.first});
}
}
}
}
void solve(){
cin>>n>>m>>k;
for (int i = 1; i <=n ; ++i) {
mp[i].clear();
dist[i]=1e15;
}
for (int i = 0; i <m ; ++i) {
int x,y,z;
cin>>x>>y>>z;
mp[x].push_back({y,z});
mp[y].push_back({x,z});
}
djstl();
for (int i = 1; i <=n ; ++i) {
dist[i]=min(dist[i],(i|1)*k);
for (int j = (i-1)&i; j ; j=(j-1)&i) {
dist[i]=min(dist[i],dist[j]+i*k);
}
}
djstl();
for (int i = 2; i <=n ; ++i) {
cout<<dist[i]<<" ";
}
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
}