// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



pair <long long, long long> dis[310][310];



vector <pair<long long, long long>> ed[310];



void solve(long long v, long long l){

	

	priority_queue <pair<pair<long long, long long>, long long>> q;

	

	q.push(make_pair(make_pair(0, l), v));

	

	dis[v][v] = make_pair(0, l);

	

	while(!q.empty()){

		

		long long t = -q.top().first.first, c = q.top().first.second, x = q.top().second;

		

		q.pop();

		

		if(dis[v][x].first == t && dis[v][x].second == c){

			

			for(long long i = 0; i < (long long)ed[x].size(); i++){

				

				long long tx = t + (ed[x][i].second > c), cx = (ed[x][i].second > c) ? (l - ed[x][i].second) : (c - ed[x][i].second), xx = ed[x][i].first;

				

				if(cx < 0) continue;

				else if((dis[v][xx].first == -1) || ((dis[v][xx].first > tx) || ((dis[v][xx].first == tx) && (dis[v][xx].second < cx)))){

					q.push(make_pair(make_pair(-tx, cx), xx));

					dis[v][xx].first = tx;

					dis[v][xx].second = cx;

				}

			}

		}

	}

}

			

		

int main(){

	

	for(long long i = 0; i < 310; i++) for(long long j = 0; j < 310; j++) dis[i][j].first = -1;

	

	long long n, m, l;

	scanf("%lld %lld %lld", &n, &m, &l);

	

	for(long long i = 0; i < m; i++){

		long long u, v, x;

		scanf(" %lld %lld %lld", &u, &v, &x);

		

		ed[u].push_back(make_pair(v, x));

		ed[v].push_back(make_pair(u, x));

	}

	

	for(long long i = 0; i < n; i++) solve(i + 1, l);

	

	long long q;

	scanf(" %lld", &q);

	

	for(long long i = 0; i < q; i++){

		long long s, t;

		scanf(" %lld %lld", &s, &t);

		

		printf("%lld\n", dis[s][t].first);

	}

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.4968805987211686x):
#include <cstdio>

#include <queue>

#include <iostream>

#include <algorithm>

#include<cstring>

using namespace std;

long long dis[310][310];

long long full[310][310];

int main()

{

    int n,m,l;

    cin >> n >> m >> l;

    for(int i=1;i<=n;i++)

    {

        for(int j=1;j<=n;j++)

        {

            if(i==j)    dis[i][j] =0;

            else

            {

                dis[i][j] = 0x3f3f3f3f3f3f3f3f;

            }

            

        }

    }

    for(int i=1;i<=m;i++)

    {

        int u,v,w;

        cin >> u >> v >> w;

        dis[u][v] = w;

        dis[v][u] = w;

    }

    for(int k=1;k<=n;k++)

    {

        for(int i=1;i<=n;i++)

        {

            for(int j=1;j<=n;j++)

            {

                dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);

            }

        }

    }

    for(int i=1;i<=n;i++)

    {

        for(int j=1;j<=n;j++)

        {

            if(i==j)    continue;

            if(dis[i][j]<=l) full[i][j] = 1;

            else

            {

                full[i][j] = 0x3f3f3f3f3f3f3f3f;

            }      

        }

    }

    for(int k=1;k<=n;k++)

    {

        for(int i=1;i<=n;i++)

        {

            for(int j=1;j<=n;j++)

            {

                full[i][j] = min(full[i][j],full[i][k]+full[k][j]);

            }

        }

    }

    int q;

    cin >> q;

    for(int i=1;i<=q;i++)

    {

        int x,y;

        cin >> x >> y;

        if(full[x][y]==0x3f3f3f3f3f3f3f3f)  cout << -1 << endl;

        else

        {

            cout << full[x][y] -1 << endl;

        }

        

    }

    return 0;

}