#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion


int n, m, l;
vector<pair<int, int>> graph[300];
int dist[300][300];
int fl[300][300];
void solve()
{
    memset(dist, 0x3F, sizeof dist);
    memset(fl, 0x3F, sizeof fl);
    cin>>n>>m>>l;
    forn(i, n) fl[i][i] = 0;
    forn(_, m)
    {
        int a, b, c; cin>>a>>b>>c;
        --a, --b;
        graph[a].pb(mp(b, c));
        graph[b].pb(mp(a, c));
        fl[a][b] = c;
        fl[b][a] = c;
    }
    forn(k, n)
    {
        forn(i, n)
        {
            forn(j, n)
            {
                if (fl[i][k] + fl[k][j] < fl[i][j]) fl[i][j] = fl[i][k] + fl[k][j];
            }
        }
    }


    forn(st, n)
    {
        dist[st][st] = 0;
        list<pair<int, int>> dq;
        dq.push_front(mp(st, l));
        while(sz(dq))
        {
            int now, rl; tie(now, rl) = dq.front(); dq.pop_front();
//            for (auto& it: graph[now])
//            {
//                int nxt, c; tie(nxt, c) = it;
//                if (c > l) continue;
//
//                int nd = dist[st][now] + (rl < c);
//                if (dist[st][nxt] > nd)
//                {
//                    dist[st][nxt] = nd;
//                    if (rl < c) dq.push_back(mp( nxt, l - c ));
//                    else dq.push_front(mp(nxt, rl - c));
//                }
//            }
            forn(nxt, n)
            {
                if (fl[now][nxt] > l) continue;
                int nd = dist[st][now] + (rl < fl[now][nxt]);
                if (dist[st][nxt] > nd)
                {
                    dist[st][nxt] = nd;
                    if (rl < fl[now][nxt]) dq.push_back(mp(nxt, l - fl[now][nxt]));
                    else dq.push_front(mp(nxt, rl - fl[now][nxt]));
                }
            }
        }
    }
    int q; cin>>q;
    while(q--)
    {
        int s, t; cin>>s>>t;
        --s, --t;
        if (dist[s][t] > 1e18) cout << -1 << '\n';
        else cout << dist[s][t]<<'\n';
    }
}


signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 7352