import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;
 

    

void main()
{
    int N, M, L;
    readf("%s %s %s", &N, &M, &L);
    readln;
    
    auto g = new Tuple!(int, int)[][] (N+1);
    foreach (_; 0 .. M) {
        int a, b, c;
        readf("%s %s %s", &a, &b, &c);
        readln;
        
        g[a] ~= tuple(b, c);
        g[b] ~= tuple(a, c);
    }
    
    debug { g.writeln; }
    
    auto results = new int[][] (N+1, N+1);
    foreach (i; 1 .. N+1) { results[i][] = -1; }
    
    void getResults(int u) {
        
        immutable Tuple!(int, int) INF = tuple(N+10, 0);
        
        auto vis = new int[] (N+1);
        auto cost = new Tuple!(int, int)[] (N+1);
        cost[] = INF;
        cost[u] = tuple(0, -L);
        
        auto q = make!(RedBlackTree!(Tuple!(Tuple!(int, int), int)));
        q.insert(tuple(cost[u], u));
        while (!q.empty()) {
            auto qel = q.front();
            q.removeFront();
            
            if (vis[qel[1]]) { continue; }
            vis[qel[1]] = true;
            
            results[u][qel[1]] = cost[qel[1]][0];
            
            foreach (edge; g[qel[1]]) {
                if (edge[1] > L) { continue; }
                
                auto ncost = qel[0][1] + edge[1] <= 0 ? 
                    tuple(qel[0][0], qel[0][1] + edge[1]) :
                    tuple(qel[0][0] + 1, -L + edge[1]);
                
                //debug { writeln(qel[1], ' ', edge[0], ' ', ncost); }
                
                if (ncost < cost[edge[0]]) {
                    cost[edge[0]] = ncost;
                    
                    q.insert(tuple(ncost, edge[0]));
                }
            }
        }
    }
    
    foreach (i; 1 .. N+1) { getResults(i); }
    
    int q;
    readf("%s", &q);
    readln;
    
    while (q--) {
        int u, v;
        readf("%s %s", &u, &v);
        readln;
        
        results[u][v].writeln;
    }
}