#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
using namespace std;
const int maxn=1005;
const int inf = 0x3f3f3f3f;
int mapp[maxn][maxn];
int dis[maxn];
int vis[maxn];
int a,b,c,n,m;
int dijkstra()
{
for(int i=1;i<=n;i++)
{
dis[i]=mapp[1][i];
}
int k=1;
for(int i=1;i<=n;i++)
{
vis[k]=1;
for(int j=1;j<=n;j++)
{
if(!vis[j]&&dis[j]<min(dis[k],mapp[k][j]))
{
dis[j]=min(dis[k],mapp[k][j]);
}
}
int minx=-inf,l=-1;
for(int j=1;j<=n;j++)
{
if(!vis[j]&&dis[j]>minx)
{
l=j;
minx=dis[j];
}
}
k=l;
}
return dis[n];
}
int main()
{
int t,kk=1;
cin>>t;
while(t--)
{
scanf("%d %d",&m,&n);
memset(mapp,0,sizeof(mapp));
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
for(int i=1;i<=m;i++)
{
scanf("%d %d %d",&a,&b,&c);
mapp[b][a]=mapp[a][b]=c;
}
printf("Scenario #%d:\n",kk++);
printf("%d\n\n",dijkstra());
}
return 0;
}