#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int INF = 1e9+5;
int n, m, l, a, b, c, d[305][305];
inline void chmin(int &a, int b){if(a > b) a = b;}
void wf(){rep(k,n) rep(i,n) rep(j,n) chmin(d[i][j], d[i][k] + d[k][j]);}
int main(){
	scanf("%d%d%d", &n, &m, &l); n++;
	fill(d[0], d[n], INF);
	rep(i,m){
		scanf("%d%d%d", &a, &b, &c);
		d[a][b] = d[b][a] = c;
	}
	wf();
	rep(i,n) rep(j,n) d[i][j] = d[i][j] <= l ? 1 : INF;
	wf();
	scanf("%d", &c);
	rep(i,c){
		scanf("%d%d", &a, &b);
		printf("%d\n", d[a][b] == INF ? -1 : d[a][b] - 1);
	}
}