#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 305, inf = 0x3f3f3f3f;
typedef long long ll;
ll n, m, L, Q, dis[N][N], ans[N][N];

int main() {
    cin >> n >> m >> L;

    memset(dis, 0x3f, sizeof(dis));
    memset(ans, 0x3f, sizeof(ans));
    rep(i, 1, n) dis[i][i] = ans[i][i] = 0;
    rep(i, 1, m) {
        ll x, y, z; cin >> x >> y >> z;
        dis[x][y] = dis[y][x] = min(dis[x][y], z);
    }
    rep(k, 1, n)
        rep(i, 1, n)
            rep(j, 1, n)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    rep(i, 1, n) rep(j, 1, n)
        if (dis[i][j] <= L && i != j) ans[i][j] = 1;
    rep(k, 1, n) rep(i, 1, n) rep(j, 1, n)
        ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);

    cin >> Q;
    while (Q--) {
        int x, y; cin >> x >> y;
        if (ans[x][y] >= inf) puts("-1");
        else printf("%lld\n", ans[x][y] - 1);
    }
    return 0;
}
