#include<bits/stdc++.h>
using namespace std;
#define int long long int
int mx = 1e18;
int32_t main() {
ios::sync_with_stdio(false);cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
// nxn matrix
vector<vector<int>>matrix(n, vector<int>(n, mx));
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
matrix[a][b] = matrix[b][a] = min(matrix[a][b], c);
}
for (int i = 0; i < n; i++) {
matrix[i][i] = 0;
}
for(int k = 0; k < n; k++) { // here k is intermediate node
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
matrix[i][j] = min(matrix[i][j], matrix[i][k]+matrix[k][j]);
}
}
}
// query
while(q--) {
int a, b;
cin >> a >> b;
a--, b--;
if(matrix[a][b] == mx) cout << "-1\n";
else cout << matrix[a][b] << "\n";
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nIGludAoKaW50IG14ID0gMWUxODsKaW50MzJfdCBtYWluKCkgewogIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTtjaW4udGllKG51bGxwdHIpOwogIGludCBuLCBtLCBxOwogIGNpbiA+PiBuID4+IG0gPj4gcTsKICAvLyBueG4gbWF0cml4CiAgdmVjdG9yPHZlY3RvcjxpbnQ+Pm1hdHJpeChuLCB2ZWN0b3I8aW50PihuLCBteCkpOwogIGZvcihpbnQgaSA9IDA7IGkgPCBtOyBpKyspIHsKICAgIGludCBhLCBiLCBjOwogICAgY2luID4+IGEgPj4gYiA+PiBjOwogICAgYS0tLCBiLS07CiAgICBtYXRyaXhbYV1bYl0gPSBtYXRyaXhbYl1bYV0gPSBtaW4obWF0cml4W2FdW2JdLCBjKTsKICB9CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgIG1hdHJpeFtpXVtpXSA9IDA7CiAgfQogIGZvcihpbnQgayA9IDA7IGsgPCBuOyB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