#include<bits/stdc++.h>
#define LL long long
using namespace std;

int n,m,l;
LL d[305][305],p[305][305];
int main(){
scanf("%d%d%d",&n,&m,&l);
	memset(d,0x3f,sizeof d);
	for(int i=1,u,v,w;i<=m;i++){
		scanf("%d%d%d",&u,&v,&w);
		d[u][v] = d[v][u] = min(d[u][v] , (LL)w);
	}	
	for(int i=1;i<=n;i++) d[i][i] = 0;	
	memset(p,0x3f,sizeof p);
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)	
			for(int j=1;j<=n;j++)
				d[i][j] = min(d[i][j] , d[i][k] + d[k][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(d[i][j] <= l)
				p[i][j] = 1;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)	
			for(int j=1;j<=n;j++)
				p[i][j] = min(p[i][j] , p[i][k] + p[k][j]);
	int q;scanf("%d",&q);
	for(int x,y;q--;){
		scanf("%d%d",&x,&y);
		printf("%lld\n",p[x][y] >= p[0][0] ? -1 :p[x][y] - 1);
	}
}