#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define MAXN 1000+10 #define MAXM 1000*1000+10 using namespace std; int t,n,m,sum; int fa[MAXN]; struct nond{ int x,y,z; }v[MAXM]; int cmp(nond a,nond b){ return a.z>b.z; } int find(int x){ if(fa[x]==x) return x; else return fa[x]=find(fa[x]); } int main(){ //freopen("lppin.txt","r",stdin); scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m);sum++; printf("Scenario #%d:\n",sum); memset(fa,0,sizeof(fa)); for(int i=1;i<=m;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); v[i].x=x;v[i].y=y;v[i].z=z; } sort(v+1,v+1+m,cmp); for(int i=1;i<=n;i++) fa[i]=i; for(int i=1;i<=m;i++){ int dx=find(v[i].x); int dy=find(v[i].y); if(dx==dy) continue; fa[dy]=dx; if(find(1)==find(n)){ cout<<v[i].z<<endl;break;} } cout<<endl; } return 0; } /* 1 8 12 1 2 2 1 5 9 1 6 11 4 2 4 4 5 3 4 6 5 2 8 10 2 7 7 5 3 5 5 7 3 6 8 3 3 8 1 */