
#include <iostream>

#define PRINT(x) cout << x << endl;
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1e17

using namespace std;
typedef long long ll;

ll g[300][300];
ll dist[300][300];

template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	ll N, M, L;
	ll A, B, C;

	cin >> N >> M >> L;

	REP(i, N) {
		REP(j, N) {
			g[i][j] = dist[i][j] = INF;
		}
		g[i][i] = dist[i][i] = 0;
	}

	REP(i, M) {
		cin >> A >> B >> C;
		chmin(g[A - 1][B - 1], C);
		chmin(g[B - 1][A - 1], C);
	}

	REP(k, N) REP(i, N) REP(j, N) chmin(g[i][j], g[i][k] + g[k][j]);

	REP(i, N) REP(j, N) if (i != j && g[i][j] <= L) dist[i][j] = 1;

	REP(k, N) REP(i, N) REP(j, N) chmin(dist[i][j], dist[i][k] + dist[k][j]);

	int Q, s, t;
	cin >> Q;

	REP(i, Q) {
		cin >> s >> t;
		if (dist[s - 1][t - 1] == INF) PRINT(-1)
		else PRINT(dist[s - 1][t - 1] - 1);
	}

	return 0;
}