// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 305;
const LL INF = 1e17;
int n, m, l;

LL dist[MAX_N][MAX_N];
LL fuel[MAX_N][MAX_N];

void input() {
    RI(n, m, l);
}

void init() {
    REP1(i, 1, n) {
        REP1(j, 1, n) {
            dist[i][j] = INF;
            fuel[i][j] = INF;
        }
        dist[i][i] = 0;
        fuel[i][i] = 0;
    }
}

void solve() {
    init();
    // read graph
    REP(i, m) {
        int a, b;
        LL c;
        RI(a, b);
        scanf("%lld", &c);
        dist[a][b] = c;
        dist[b][a] = c;
    }
    
    REP1(i, 1, n) {
        REP1(j, 1, n) {
            REP1(k, 1, n) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }

    // REP(i, n) {
    //     REP(j, n) {
    //         printf("%d ", dist[i][j]);
    //     }
    //     printf("\n");
    // }

    REP1(i, 1, n) {
        REP1(j, 1, n) {
            if(i == j) continue;
            if(dist[i][j] <= l) {
                fuel[i][j] = 1LL;
            }
        }
    }

    REP1(i, 1, n) {
        REP1(j, 1, n) {
            REP1(k, 1, n) {
                fuel[j][k] = min(fuel[j][k], fuel[j][i] + fuel[i][k]);
            }
        }
    }

    // REP(i, n) {
    //     REP(j, n) {
    //         printf("%d ", fuel[i][j]);
    //     }
    //     printf("\n");
    // }

    int Q;
    RI(Q);
    REP(i, Q) {
        int s, t;
        RI(s, t);
        if(fuel[s][t] < INF) printf("%lld\n", fuel[s][t]-1);
        else printf("-1\n");
    }
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1920