#include #include #include #include #include #define ll long long #define inf 1e9 #define eps 1e-10 #define md #define N 300010 using namespace std; struct PP { int x,y,l;} p[N]; bool ok[N]; int fa[N]; int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]);} int main() { int tt; scanf("%d",&tt); while (tt--) { int n,m; scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].l); } int ans=0; memset(ok,1,sizeof(ok)); for (int k=30;k>=0;k--) { for (int i=1;i<=n;i++) fa[i]=i; int tot=n; for (int i=1;i<=m;i++) { if ( (!(p[i].l&(1<