#include
#include
#include
using namespace std;
int main()
{
int n, m, q;
cin>>n>>m>>q;
long long a, b, c;
long long shortestpath[n][n];
for(int i=0; i>a>>b>>c;
a--;
b--;
shortestpath[a][b]=min(shortestpath[a][b], c);
shortestpath[b][a] = min(shortestpath[a][b], c);
}
for(int k=0; k>a>>b;
a--; b--;
if(shortestpath[a][b] == 1e18) {
cout << -1 << endl;
}
else cout<