floyd 板子
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 210;
int g[N][N];
int main () {
int n, m, q;
cin >> n >> m >> q;
int a, b, c;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (i == j) g[i][j] = 0;
else g[i][j] = inf;
}
}
for (int i = 0; i < m; i ++ ) {
cin >> a >> b >> c;
g[a][b] = min(g[a][b], c);
}
for (int k = 1; k <= n; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
for (int i = 0; i < q; i ++ ) {
cin >> a >> b;
if (g[a][b] > inf / 2) cout << "impossible" << endl;
else cout << g[a][b] << endl;
}
return 0;
}