#include <bits/stdc++.h>

using namespace std;

const int maxn = 400;
const int inf = 0x3f3f3f3f;
int n, m, l, a, b, c, dist[maxn][maxn], x[maxn][maxn], q, s, t;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m >> l;
	memset(dist, inf, sizeof(dist));
	memset(x, inf, sizeof(x));
	for (int i = 0; i < m; ++i) {
		cin >> a >> b >> c;
		if (c > l) continue;
		dist[a][b] = dist[b][a] = c;
	}
	for (int k = 1; k <= n; ++k) {
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (dist[i][j] <= l) x[i][j] = 1;
		}
	}
	for (int k = 1; k <= n; ++k) {
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				x[i][j] = min(x[i][j], x[i][k] + x[k][j]);
			}
		}
	}
	cin >> q;
	while (q--) {
		cin >> s >> t;
		int ans = (x[s][t] > n ? 0 : x[s][t]);
		cout << (ans - 1) << '\n';
	}
	return 0;
}