//这个错在蛋疼的搜索的时候,i的范围误写成了i<=MAX,怪不得WA!
#include <iostream>
#include <cstdio>
#include <memory.h>
using namespace std;
const int MAX=105,INF=1<<30;
int c,s,q,t1,t2,t3,num=1,start,end;
int map[MAX][MAX],ans[MAX][MAX],vis[MAX];
void solve(const int &start){
int res,minVal,minSign,t;
/*if(ans[start][end]!=-1){
if(ans[start][end]!=INF)
cout<<ans[start][end]<<endl;
else
cout<<"no path"<<endl;
return ;
}
if(ans[end][start]!=-1){
if(ans[end][start]!=INF)
cout<<ans[end][start]<<endl;
else
cout<<"no path"<<endl;
return ;
}*/
for(int i=1;i<=c;i++)
ans[start][i]=INF;
ans[start][start]=0;
while(1){
minVal=INF;
for(int i=1;i<=c;i++){
if(!vis[i]&&ans[start][i]<=minVal){
minVal=ans[start][i];
minSign=i;
}
}
//cout<<"minsign: "<<minSign<<endl;
vis[minSign]=1;
if(minSign==end){
res=ans[start][end];
break;
}
for(int i=1;i<=c;i++){
if(map[minSign][i]!=-1){
t=ans[start][minSign]>map[minSign][i]?
ans[start][minSign]:map[minSign][i];
if(ans[start][i]==-1)
ans[start][i]=t;
else if(ans[start][i]>t)
ans[start][i]=t;
}
}
}
if(res!=INF)
cout<<res<<endl;
else
cout<<"no path"<<endl;
}
int main()
{
freopen("i.txt","r",stdin);
//freopen("e://t2.txt","w",stdout);
while(cin>>c>>s>>q){
if(!c&&!s&&!q)
break;
if(num!=1)
cout<<endl;
cout<<"Case #"<<num++<<endl;
memset(ans,-1,sizeof(ans));
memset(map,-1,sizeof(map));
//memset(standard,0,sizeof(standard));
//for(int i=1;i<=s;i++)
// standard[i]=1;
for(int i=0;i<s;i++){
cin>>t1>>t2>>t3;
map[t1][t2]=map[t2][t1]=t3;
}
while(q--){
cin>>start>>end;
//cout<<t1<<" "<<t2<<endl;
memset(vis,0,sizeof(vis));
solve(start);//µÏ½Ü¿Ë˹À,RELAX()µÄvariant
}
/*for(int i=1;i<=s;i++){
for(int j=1;j<=s;j++)
cout<<map[i][j]<<" ";
cout<<endl;
}*/
}
return 0;
}