#include #include #include #include #include #include #include #include #include #include #include #include #define N 500005 #define M 8000005 #define ls (t<<1) #define rs ((t<<1)|1) #define mid ((l+r)>>1) #define mk make_pair #define pb push_back #define fi first #define se second using namespace std; int i,j,m,n,p,k,id[N],x[N],y[N],w[N],fa[N],vis[N]; int cmp(int a,int b) { return w[a]w[b]; } int get(int x) { return fa[x]==x?x:fa[x]=get(fa[x]); } int main() { int T; scanf("%d",&T); for (;T--;) { scanf("%d%d",&n,&m); for (i=1;i<=n;++i) fa[i]=i; for (i=1;i<=m;++i) scanf("%d%d%d",&x[i],&y[i],&w[i]),id[i]=i,vis[i]=0; sort(id+1,id+m+1,cmp); int Cnter=0; for (i=1;i<=m;i=j) { for (j=i;j<=m&&w[id[i]]==w[id[j]];++j); for (k=i;k=n/2) for (k=i;k=n/2) for (k=i;k