#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100000+100;
int T,n,m;
LL d[maxn];
struct node{
int u;
LL c;
bool operator<(const node&A)const{
return c>A.c;
}
};
vector<node> ac[maxn];
bool vis[maxn];
priority_queue<node> Q;
int main(){
scanf("%d",&T);
int cnt = 0;
while(T--){
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;i++)
ac[i].clear();
memset(vis,0,sizeof(vis));
memset(d,0,sizeof(d));
for(int i =0;i<m;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
ac[a].push_back(node{b,c});
ac[b].push_back(node{a,c});
d[a]+=c;
d[b]+=c;
}
for(int i = 1;i<=n;i++)
Q.push(node{i,d[i]});
LL tmp = 0;
while(!Q.empty()){
node now = Q.top();
Q.pop();
int u = now.u;
if(vis[u])continue;
vis[u] = 1;
LL k =now.c;
tmp = max(tmp,k);
for(int i = 0;i<ac[u].size();i++){
node temp = ac[u][i];
int v = temp.u;
if(vis[v])continue;
LL c1 = temp.c;
d[v]-=c1;
Q.push(node{v,d[v]});
}
}
printf("%lld\n",tmp);
}
return 0;
}