#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

const int CN = 310;
const int INF = 0x3f3f3f2f;

int n,m,l,q,f[CN][CN],g[CN][CN];

int main()
{
	memset(f, 0x3f, sizeof(f));
	memset(g, 0x3f, sizeof(g));
	
	scanf("%d%d%d",&n,&m,&l);
	while(m--){
		int a,b,c; scanf("%d%d%d",&a,&b,&c);
		f[a][b] = f[b][a] = c;
	}
	
	for(int k=1;k<=n;k++)
	    for(int i=1;i<=n;i++)
	        for(int j=1;j<=n;j++)
	            f[i][j] = min(f[i][j], f[i][k]+f[k][j]);
	for(int i=1;i<=n;i++)
	    for(int j=1;j<=n;j++)
	        if(f[i][j] <= l) g[i][j] = 1;
	for(int k=1;k<=n;k++)
	    for(int i=1;i<=n;i++)
	        for(int j=1;j<=n;j++)
	            g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
	
	scanf("%d",&q);
	while(q--){
		int x,y; scanf("%d%d",&x,&y); printf("%d\n",g[x][y] < INF ? g[x][y] - 1 : -1);
	}
}