#include<bits/stdc++.h>
using namespace std;
const int maxn = 300+10;
int n,m,f[maxn][maxn],t;
int main(){
memset(f,127/3,sizeof(f));
scanf("%d%d%d",&n,&m,&t);
for(int i = 1;i <= m;++i){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
f[x][y] = z;
}
for(int k = 1;k <= n;++k)
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j){
if(i != j && j != k)f[i][j] = min(f[i][j],f[i][k] + f[k][j]);
}
for(int i = 1;i <= t;++i){
int a,b;
scanf("%d%d",&a,&b);
if(f[a][b] == 707406378)printf("-1
");
else printf("%d
",f[a][b]);
}
return 0;
}