#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N, M, L;
	cin >> N >> M >> L;
	vector<vector<ll> > d1(N + 1, vector<ll>(N + 1, 1e10)), d2(N + 1, vector<ll>(N + 1, 1e10));
	for (int i = 0; i < M; i++) {
		ll a, b, c; cin >> a >> b >> c;
		d1[a][b] = c, d1[b][a] = c;
	}
 
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
				if (k == N&&d1[i][j]<=L) {
					d2[i][j] = 1;
				}
			}
		}
	}
 
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
			}
		}
	}
 
	int Q; cin >> Q;
	vector<pair<int, int> > qs(Q);
	for (int i = 0; i < Q; i++) {
		cin >> qs[i].first >> qs[i].second;
	}
	for (int i = 0; i < Q; i++) {
		int s = qs[i].first, t = qs[i].second;
		if (d2[s][t] > 1e9)cout << -1 << endl;
		else cout << d2[s][t] - 1 << endl;
	}
 
}
 