//#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
using namespace std;

#define ios ios::sync_with_stdio(false)
#define ll long long
#define pa pair<int,int>
#define mk make_pair
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int
#define vr vector<int>
#define pi acos(-1)

const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7.;
const ll N = 1e3 + 7;

int n, m, L;
ll f[N][N];
ll d[N][N];
int cnt[N][N];

void floyd(ll a[N][N])
{
	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];
				}
			}
}

int main()
{
	scanf("%d%d%d", &n, &m, &L);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i != j)
				f[i][j] = d[i][j] = inf;
		}
	}
	while (m--)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		d[x][y] = d[y][x] = z;
	}
	int q;
	scanf("%d", &q);
	floyd(d);
	for(int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			if (d[i][j] <= L)
				f[i][j] = 1;
		}
	floyd(f);
	while (q--)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		ll ans = -1;
		if (f[x][y] != inf)
		{
			ans = f[x][y] - 1;
		}
		printf("%lld\n", ans);
	}
	return 0;
}