#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int tc;
#define pp pair<int,int>
using namespace std;
struct pri
{
int operator() (const pair<int,int>&p1,const pair<int,int>&p2)
{
return p1.second<p2.second;
}
}p;
int main() {
//freopen("test.inp", "r", stdin);
scanf("%d", &tc);
while (tc --) {
int n, m;
priority_queue<pp,vector<pp>,pri> q;
cin>>n >> m;
vector<pp> g[n+1];
int u,v,w;
for(int i=0;i<m;i++)
{
cin>>u>>v>>w;
g[u].push_back(pp(v,w));
g[v].push_back(pp(u,w));
}
int s = 1;
int d[n+1];
for(int i=1;i<=n;i++)
d[i]=999999;
d[s]=0;
q.push(pp(s,d[s]));
while(!q.empty())
{
u=q.top().first;
q.pop();
int size=g[u].size();
for(int i=0;i<size;i++)
{
v=g[u][i].first;
w=g[u][i].second;
if(d[v]>d[u]+w)
{
d[v]=d[u]+w;
q.push(pp(v,d[v]));
}
}
}
int rs = 0;
for(int i=1;i<=n;i++) {
rs = max(rs, d[i] - d[i - 1]);
}
printf("%d\n", rs);
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHRjOwoKCiNkZWZpbmUgcHAgcGFpcjxpbnQsaW50Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpzdHJ1Y3QgcHJpCnsKICAgIGludCBvcGVyYXRvcigpIChjb25zdCBwYWlyPGludCxpbnQ+JnAxLGNvbnN0IHBhaXI8aW50LGludD4mcDIpCiAgICB7CiAgICAgICAgcmV0dXJuIHAxLnNlY29uZDxwMi5zZWNvbmQ7CiAgICB9Cn1wOwoKaW50IG1haW4oKSB7CiAgICAvL2ZyZW9wZW4oInRlc3QuaW5wIiwgInIiLCBzdGRpbik7CiAgICBzY2FuZigiJWQiLCAmdGMpOwogICAgd2hpbGUgKHRjIC0tKSB7CiAgICAgICAgaW50IG4sIG07CiAgICAgICAgcHJpb3JpdHlfcXVldWU8cHAsdmVjdG9yPHBwPixwcmk+IHE7CiAgICAgICAgY2luPj5uID4+IG07CiAgICAgICAgdmVjdG9yPHBwPiBnW24rMV07CiAgICAgICAgaW50IHUsdix3OwogICAgICAgIGZvcihpbnQgaT0wO2k8bTtpKyspCiAgICAgICAgewogICAgICAgICAgICBjaW4+PnU+PnY+Pnc7CiAgICAgICAgICAgIGdbdV0ucHVzaF9iYWNrKHBwKHYsdykpOwogICAgICAgICAgICBnW3ZdLnB1c2hfYmFjayhwcCh1LHcpKTsKICAgICAgICB9CiAgICAgICAgaW50IHMgPSAxOwogICAgICAgIGludCBkW24rMV07CiAgICAgICAgZm9yKGludCBpPTE7aTw9bjtpKyspCiAgICAgICAgICAgIGRbaV09OTk5OTk5OwogICAgICAgIGRbc109MDsKICAgICAgICBxLnB1c2gocHAocyxkW3NdKSk7CiAgICAgICAgd2hpbGUoIXEuZW1wdHkoKSkKICAgICAgICB7CiAgICAgICAgICAgIHU9cS50b3AoKS5maXJzdDsKICAgICAgICAgICAgcS5wb3AoKTsKICAgICAgICAgICAgaW50IHNpemU9Z1t1XS5zaXplKCk7CiAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8c2l6ZTtpKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHY9Z1t1XVtpXS5maXJzdDsKICAgICAgICAgICAgICAgIHc9Z1t1XVtpXS5zZWNvbmQ7CiAgICAgICAgICAgICAgICBpZihkW3ZdPmRbdV0rdykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBkW3ZdPWRbdV0rdzsKICAgICAgICAgICAgICAgICAgICBxLnB1c2gocHAodixkW3ZdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaW50IHJzID0gMDsKICAgICAgICBmb3IoaW50IGk9MTtpPD1uO2krKykgewogICAgICAgICAgICBycyA9IG1heChycywgZFtpXSAtIGRbaSAtIDFdKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgcnMpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=