#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50010;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int MAX=1000000010;
const ll INF=1ll<<55;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
int tot,q[N],u[N],v[4*N],pre[4*N];
ll xo[N],d[4*N],w[4*N];
void add(int a,int b,ll c) {
v[tot]=b;w[tot]=c;pre[tot]=u[a];u[a]=tot++;
}
void dfs(int x,int f,ll c) {
if (q[x]) {
d[++tot]=c^xo[x];return ;
}
q[x]=1;xo[x]=c;
for (int i=u[x];i!=-1;i=pre[i])
if (v[i]==f) continue ;
else dfs(v[i],x,c^w[i]);
}
int main()
{
int a,b,i,j,k,n,m,t,ca;
ll c,ans;
scanf("%d", &t);
for (ca=1;ca<=t;ca++) {
scanf("%d%d", &n, &m);
tot=0;memset(u,-1,sizeof(u));
for (i=1;i<=m;i++) {
scanf("%d%d%lld", &a, &b, &c);
add(a,b,c);add(b,a,c);
}
memset(q,0,sizeof(q));
tot=0;ans=0;
dfs(1,-1,0);
for (i=60,k=1;i>=0;i--) {
for (j=k;j<=tot;j++)
if ((d[j]&(1ll<<i))!=0) break ;
if (j==tot+1) continue ;
if (j!=k) swap(d[k],d[j]);
for (j=k+1;j<=tot;j++)
if ((d[j]&(1ll<<i))!=0) d[j]^=d[k];
k++;
}
for (i=1;i<k;i++) ans=max(ans,ans^d[i]);
printf("Case #%d: %lld\n", ca, ans);
}
return 0;
}