#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'
const long long M = (long long)1e9+7;
const long long N = 1e5 + 5;
vector <pair<long long,long long> > g[N];
vector <long long> sp;
bool col[N];
int main()
{
// ios_base::sync_with_stdio(0);
cout.precision(15);
cout.setf(ios::fixed);
long long t,i;
cin >> t;
while(t--)
{
long long a,b,c;
long long n,m,k;
cin >> n >> m>>k;
sp.resize(n);
for(i=0;i<n;i++)
{
g[i].clear();
sp[i] = 0;
col[i] = false;
}
for(i=0;i<m;i++)
{
cin >> a >> b >> c;
a--;b--;
g[a].PB(MP(b,c));
g[b].PB(MP(a,c));
}
set <pair<long long,long long> > st;
st.insert(MP(0,n-1));
set <pair<long long,long long> > :: iterator it;
long long ss,sh;
while(!st.empty())
{
it = st.begin();
ss = it->second;
sh = it->first;
st.erase(it);
if(col[ss]) continue;
col[ss] = true;
sp[ss] = sh;
for(i=0;i<g[ss].size();i++)
st.insert(MP(sh+g[ss][i].second,g[ss][i].first));
}
sh = sp[0];
sort(sp.begin(),sp.end());
reverse(sp.begin(),sp.end());
double A,sum = 0,mA=1e12;;
for(i=0;i<n;i++)
sum += sp[i];
for(i=0;i<n-1;i++)
{
sum -= sp[i];
A = ((i+1)*k*1.0+sum)/(n-(i+1));
mA = min(mA,A);
}
double ans = min(mA+k,(double)sh);
cout << ans << endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnR5cGVkZWYgbG9uZyBsb25nIExMOyAgCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGZpbGxjaGFyKGEsIHgpIG1lbXNldChhLCB4LCBzaXplb2YoYSkpCiNkZWZpbmUgTVAgbWFrZV9wYWlyCiNkZWZpbmUgUEIgcHVzaF9iYWNrCiNkZWZpbmUgZW5kbCAnXG4nCgpjb25zdCBsb25nIGxvbmcgTSA9IChsb25nIGxvbmcpMWU5Kzc7CmNvbnN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