#include <bits/stdc++.h>
using namespace std;
int n,m,L,f[310][310],Q;
long long a[310][310];
int main()
{
	scanf("%d%d%d",&n,&m,&L);
	memset(a,10,sizeof(a));
	for (int i=1;i<=m;i++) {
		int xx,yy,zz;
		scanf("%d%d%d",&xx,&yy,&zz);
		if (zz>L) continue;
		a[xx][yy]=zz;
		a[yy][xx]=zz;
		f[xx][yy]=1;
		f[yy][xx]=1;
	}
	for (int k=1;k<=n;k++)
	  for (int i=1;i<=n;i++)
	    for (int j=1;j<=n;j++)
	      if (a[i][k]+a[k][j]<a[i][j]) a[i][j]=a[i][k]+a[k][j];
	memset(f,10,sizeof(f));
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=n;j++)
	    if (a[i][j]<=L) f[i][j]=0;
	for (int k=1;k<=n;k++)
	  for (int i=1;i<=n;i++)
	    for (int j=1;j<=n;j++) 
	    	if (f[i][k]+f[k][j]+1<f[i][j]) f[i][j]=f[i][k]+f[k][j]+1;
	scanf("%d",&Q);
	for (int i=1;i<=Q;i++) {
		int xx,yy;
		scanf("%d%d",&xx,&yy);
		if (a[xx][yy]==a[0][0]) printf("-1\n");
		else printf("%d\n",f[xx][yy]);
	}
	return 0;
}
	