#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;
int a[500][500],jl1,jl2,n,m,v,i,j,k;
int pre[500][500];
int main(){
freopen("hurdles.in","r",stdin);
freopen("hurdles.out","w",stdout);
cin>>n>>m>>v;
for (i=1;i<=n;++i)
for (j=1;j<=n;++j)
a[i][j]=10000000;
for (i=1;i<=m;++i)
{
int x,y,z;
cin>>x>>y>>z;
a[x][y]=z;
}
for (k=1;k<=n;++k)
for (i=1;i<=n;++i)
if (i!=k)
for (j=1;j<=n;++j)
if (i!=j)
{
if (a[k][j]<a[i][j]&&a[i][k]<a[i][j])
a[i][j]=max(a[k][j],a[i][k]);
}
for (int i=1;i<=v;++i)
{
int x,y;
cin>>x>>y;
if(a[x][y]==10000000) cout<<"-1"<<endl;
else cout<<a[x][y]<<endl;
}
return 0;
}