#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, m , l;
const int inf = 1e9 + 7;
///int dp[305][305], ans[305][305], vis[305][305];
int ans[305][305];
bool vis[305];
vector<pair<int,int>> a[maxn];
/*
void dijkstar(int start){
    for(int i = 1 ; i<= n + 1; i++){
        for(int j = 0 ;j <= n + 1; j++)
            dp[i][j] = -inf, vis[i][j] = false;
    }
    dp[0][0] = l;
    struct state{
        int nod, use, val;
        state(int x, int y, int z): nod(x), use(y), val(z){}
        bool operator < (const state & x) const{
            return val < x.val;
        }
    };
    priority_queue<state>  q;
    q.push({start, 0 , l});
    while(!q.empty()){
        auto p = q.top();
        q.pop();
      //  if(start == 1)
       //     cout << "Cried " << p.nod << ' ' << p.use << ' ' << p.val << '\n';
        if(vis[p.nod][p.use]) continue;
        vis[p.nod][p.use] = true;
        for(auto i:a[p.nod]){
            if(i.second <= p.val){
                if(!vis[i.first][p.use] && p.val - i.second > dp[i.first][p.use]){
                    dp[i.first][p.use] = p.val - i.second;
                    q.push(state(i.first,p.use, dp[i.first][p.use]));
                }
            }
        }
        if(p.val < l){
            if(!vis[p.nod][p.use + 1] && p.use <= n + 1 && l > dp[p.nod][p.use + 1]){
                dp[p.nod][p.use + 1] = l;
                q.push(state(p.nod, p.use + 1, l));
            }
        }
    }
    for(int i = 1 ; i <= n; i++){
        int found = -1;
        for(int j = 0 ;j <= n ;j++){
            if(dp[i][j] != -inf){
                found = j;
                break;
            }
        }
        ans[start][i] = found;
    }
    return;
}*/
using pii = pair<int,int>;
#define mp make_pair
bool cmp(const pii & x, const pii &y){
    if(x.first == y.first) return x.second > y.second;
    return x.first < y.first;
}
void greedy(int start){
    struct shit{
        int nod, cnt, val;
        shit(int x,int y,int z) : nod(x) , cnt(y), val(z){}

        bool operator <(const shit &x) const{
            if(cnt == x.cnt) return val < x.val;
            return cnt > x.cnt;
        }
    };
    //using pii = pair<int,int>;
    priority_queue<shit> q;
    pair<int,int> dp[305];
    for(int i = 1 ;i <= n + 1;i ++){
        dp[i] = mp(inf , -inf);
        vis[i] = false;
    }
    dp[start] = make_pair(0 , l);
    q.push(shit(start, 0 , l));
    while(!q.empty()){
        auto p = q.top();
        q.pop();
        if(vis[p.nod]) continue;
        for(auto i:a[p.nod]){
            if(!vis[i.first] && p.val >= i.second && cmp(mp(p.cnt,p.val - i.second), dp[i.first])){
                q.push(shit(i.first, p.cnt, p.val - i.second));
                dp[i.first] = mp(p.cnt, p.val - i.second);
            }
            else if(!vis[i.first] && p.val < i.second && cmp(mp(p.cnt + 1, l - i.second) , dp[i.first])){
                q.push(shit(i.first, p.cnt + 1 , l - i.second));
                dp[i.first] = mp(p.cnt + 1, l  - i.second);
            }
        }
    }
    for(int i = 1 ;i <= n;i ++){
        if(i != start){
            if(dp[i] != mp(inf,-inf)){
                ans[start][i] = dp[i].first;
            }
            else ans[start][i] = -1;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> l;
    //scanf("%d %d %d", &n, &m , &l);
    memset(ans, -1, sizeof(ans));
    while(m -- ){
        int x, y, z;
      //  scanf("%d %d %d", &x, &y , &z);
        cin >> x >> y >> z;
        if(z > l) continue;
        a[x].push_back({y, z});
        a[y].push_back({x, z});
    }
    for(int i = 1 ;i<= n;i++){
   //     dijkstar(i);
        greedy(i);
    }
    int q,x,y;
    cin >> q;
    while(q -- ){
        cin >> x >> y;
        cout <<ans[x][y] << '\n';
    }
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 9088