// 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.5331753009368847x):
#pragma GCC optimize (3)

#include<vector>

#include<stack>

#include<bitset>

#include<cstdlib>

#include<cmath>

#include<set>

#include<list>

#include<deque>

#include<map>

#include<queue>

#include<iostream>

#include<cstdio>

#include<cstring>

#include<iomanip>

#include<algorithm>

#include<unordered_map>

/*#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

#include<ext/pb_ds/hash_policy.hpp>

#include<ext/pb_ds/trie_policy.hpp>

#include<ext/pb_ds/priority_queue.hpp>*/

//#include<ext/rope>

#define ll long long

#define ull unsigned long long

#define INFI 2147483647

#define INFL 9223372036854775807

#define INFU 18446744073709551615

#define maxn 350

using namespace std;

//using namespace __gnu_pbds;

//using namespace __gnu_cxx;

const double PI=acos(-1.0);

const double eps=1e-6;

ll g[maxn][maxn],g2[maxn][maxn];

inline ll read()

{

    ll x=0,f=1;

    char ch=getchar();

    while(ch<'0' || ch>'9'){

        if(ch=='-') f=-1;

        ch=getchar();

    }

    while(ch>='0' && ch<='9'){

        x=x*10+ch-'0';

        ch=getchar();

    }

    return x*f;

}

template<typename T> void debug(T x)

{

    cout<<"value="<<x<<endl;

    return;

}

signed main()

{

	//ios_base::sync_with_stdio(false);

    //cin.tie(0);

    //cout.tie(0);

    ll n=read(),m=read(),L=read();

    for(ll i=1;i<=n;i++) for(ll j=1;j<=n;j++) g[i][j]=50000000000000;

    for(ll i=1;i<=n;i++) for(ll j=1;j<=n;j++) g2[i][j]=50000000000000;

    for(int i=1;i<=n;i++) g[i][i]=0;

    for(int i=1;i<=n;i++) g2[i][i]=0;

    for(ll i=1;i<=m;i++){

        ll u=read(),v=read(),w=read();

        if(w>L) continue;

        else{

            g[u][v]=w;

            g[v][u]=w;

        }

    }

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

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

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

                if(g[i][k]+g[k][j]<=g[i][j])

                    g[i][j]=g[i][k]+g[k][j];

    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(g[i][j]<=L) g2[i][j]=1LL;

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

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

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

                if(g2[i][k]+g2[k][j]<=g2[i][j])

                    g2[i][j]=g2[i][k]+g2[k][j];

    ll Q=read();

    for(ll i=1;i<=Q;i++){

        ll s=read(),t=read();

        if(g2[s][t]<50000000000000) printf("%lld\n",g2[s][t]-1);

        else cout<<-1<<endl;

    }

	return 0;

}