//求一条路最小承受能力最大
#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1009;
vector<pair<int,int> >e[maxn];
int n,m,x[maxn],y[maxn];
int dis[maxn];
bool vis[maxn];
void spfa()
{
for(int i=1; i<=n; i++)
dis[i]=0;
queue<int>q;
q.push(1);
dis[1]=inf;
vis[1]=1;
while(!q.empty())
{
int top=q.front();
q.pop();
vis[top]=0;
for(int i=0; i<e[top].size(); i++)
{
int temp=e[top][i].first;
if(dis[temp]<min(dis[top],e[top][i].second))
{
dis[temp]=min(dis[top],e[top][i].second);
if(!vis[temp])
{
vis[temp]=1;
q.push(temp);
}
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
for(int cntt=1;cntt<=t;cntt++)
{
//edge ee;
scanf("%d%d",&n,&m);
int a,b,l;
for(int i=1; i<=m; i++)
{
scanf("%d%d%d",&a,&b,&l);
e[a].push_back(make_pair(b,l));
e[b].push_back(make_pair(a,l));
}
spfa();
printf("Scenario #%d:\n%d\n\n",cntt,dis[n]);
//cout << "Scenario #" << ++cntt << endl;
//cout << "Frog Distance = " <<fixed << setprecision(3) << dis[2] << endl << endl;
for(int i=1; i<=n; i++)
e[i].clear();
}
return 0;
}