#include<iostream>
#include<cstdio>
#include<queue>
#include<string.h>
using namespace std;
int t,n,m;
const int maxn = 1e3+10;
int mp[maxn][maxn];
const int inf = 0x3f3f3f3f;
struct Edge{
int to,w,next;
bool operator < (const Edge &a) const{
return a.w<w;
}
Edge(int _to=0,int _w=0,int _next=0):to(_to),w(_w),next(_next){}
}edge[maxn+100000];
int cnt = 0;
int head[maxn+100000];
int dist[maxn];
int vis[maxn];
int pre[maxn];
int maxs[maxn];
int st,ed;
void init(){
memset(head,-1,sizeof(head));
cnt = 0;
st = 1;
ed = n;
}
void addedge(int u,int v,int w){
edge[cnt].to = v;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
}
struct node{
int r,c;
bool operator < (const node &r) const{
return c<r.c;
}
node(int _r,int _c):r(_r),c(_c){}
};
void diji(){
memset(pre,-1,sizeof(pre));
memset(vis,0,sizeof(vis));
for(int i =1;i<=n;++i)dist[i] =inf;
dist[st] = inf;
priority_queue<node>q;
q.push(node(st,inf));
while(!q.empty()){
node t = q.top();
q.pop();
int u = t.r;
//cout<<u<<endl;
if(vis[u])continue;
vis[u] = 1;
for(int i = head[u];~i;i = edge[i].next){
int to = edge[i].to;
int w = edge[i].w;
//cout<<"to"<<to<<"w:"<<w<<endl;
if(!vis[to]&&(dist[to]<min(dist[u],w)||dist[to]==inf)){
dist[to]=min(dist[u],w);
q.push(node(to,dist[to]));
}
}
}
}
int main(){
scanf("%d",&t);
int cnt = 1;
while(t--){
scanf("%d%d",&n,&m);
init();
for(int i =0;i<m;++i){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
addedge(u,v,w);
addedge(v,u,w);
}
diji();
printf("Scenario #%d:\n",cnt++);
printf("%d\n",dist[n]);
if(t!=0)cout<<endl;
}
}