#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;
int n, m,s,l,k;
vector<pair<int,int> > adj[N];
int lev[N],mx=0;
void bfs(int st){
queue<int> q;
q.push(st);
lev[st] = 1;
while(q.size()){
int sz = q.size();
while(sz--){
int u = q.front();
// cout<<u<<" "<<adj[u].size()<<endl;
q.pop();
for(auto v : adj[u])
{
if(lev[v.first]<=k)
mx=max(v.second,mx);
if(!lev[v.first])
q.emplace(v.first), lev[v.first] = lev[u] + 1;
}
}
}
}
int main(){
IO;
int t;
cin>>t;
while(t--)
{
mx=0;
for(int i=0;i<n;i++)
{
adj[i].clear();
lev[N]=0;
}
cin>>n>>m>>s>>l>>k;
for(int i = 0 ; i < m ; ++i){
int u, v, w;
cin>>u>>v>>w;
adj[u].emplace_back(v,w);
adj[v].emplace_back(u,w);
}
// for(int i = 0 ; i <= m ; ++i){
// cout<<i<<" :";
// for(auto v: adj[i])
// cout<<v.first<<" ";
// cout<<endl;
// }
bfs(s);
cout<<mx<<endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbGQgbG9uZyBkb3VibGUKI2RlZmluZSBJTyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApLGNpbi50aWUoMCksY291dC50aWUoMCk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU1ICsgNSwgTSA9IDIgKiBOICsgNTsKCmludCBuLCBtLHMsbCxrOwp2ZWN0b3I8cGFpcjxpbnQsaW50PiA+IGFkaltOXTsKCmludCBsZXZbTl0sbXg9MDsKCnZvaWQgYmZzKGludCBzdCl7CiAgICBxdWV1ZTxpbnQ+IHE7CiAgICBxLnB1c2goc3QpOwogICAgbGV2W3N0XSA9IDE7CiAgICB3aGlsZShxLnNpemUoKSl7CiAgICAgICAgaW50IHN6ID0gcS5zaXplKCk7CiAgICAgICAgd2hpbGUoc3otLSl7CiAgICAgICAgICAgIGludCB1ID0gcS5mcm9udCgpOwovLyAgICAgICAgICAgICAgICBjb3V0PDx1PDwiICI8PGFkalt1XS5zaXplKCk8PGVuZGw7CiAgICAgICAgICAgIHEucG9wKCk7CiAgICAgICAgICAgIGZvcihhdXRvIHYgOiBhZGpbdV0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKGxldlt2LmZpcnN0XTw9aykKICAgICAgICAgICAgICAgICAgICBteD1tYXgodi5zZWNvbmQsbXgpOwogICAgICAgICAgICAgICAgaWYoIWxldlt2LmZpcnN0XSkKICAgICAgICAgICAgICAgICAgICBxLmVtcGxhY2Uodi5maXJzdCksIGxldlt2LmZpcnN0XSA9IGxldlt1XSArIDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCl7CiAgICBJTzsKICAgIGludCB0OwogICAgY2luPj50OwogICAgd2hpbGUodC0tKQogICAgewogICAgICAgIG14PTA7CiAgICAgICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgICB7CiAgICAgICAgICAgIGFkaltpXS5jbGVhcigpOwogICAgICAgICAgICBsZXZbTl09MDsKICAgICAgICB9CiAgICAgICAgY2luPj5uPj5tPj5zPj5sPj5rOwogICAgICAgIGZvcihpbnQgaSA9IDAgOyBpIDwgbSA7ICsraSl7CiAgICAgICAgICAgIGludCB1LCB2LCB3OwogICAgICAgICAgICBjaW4+PnU+PnY+Pnc7CiAgICAgICAgICAgIGFkalt1XS5lbXBsYWNlX2JhY2sodix3KTsKICAgICAgICAgICAgYWRqW3ZdLmVtcGxhY2VfYmFjayh1LHcpOwogICAgICAgIH0KICAgIC8vICAgIGZvcihpbnQgaSA9IDAgOyBpIDw9IG0gOyArK2kpewogICAgLy8gICAgICAgICAgICBjb3V0PDxpPDwiIDoiOwogICAgLy8gICAgICAgIGZvcihhdXRvIHY6IGFkaltpXSkKICAgIC8vICAgICAgICAgICAgY291dDw8di5maXJzdDw8IiAiOwogICAgLy8gICAgY291dDw8ZW5kbDsKICAgIC8vICAgIH0KICAgICAgICBiZnMocyk7CgogICAgICAgIGNvdXQ8PG14PDxlbmRsOwogICAgfQp9Cg==