import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string, core.stdc.stdlib;

void main() {
    immutable long INF = 1L << 59;
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto L = s[2].to!long;
    auto G = new long[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) G[i][j] = i == j ? 0 : INF;
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        auto a = s[0] - 1;
        auto b = s[1] - 1;
        auto c = s[2].to!long;
        G[a][b] = c;
        G[b][a] = c;
    }
    auto dist1 = warshall_floyd!(long, INF)(G);

    auto dist2 = new long[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) dist2[i][j] = i == j ? 0 : INF;
    foreach (i; 0..N) foreach (j; 0..N) if (dist1[i][j] <= L) dist2[i][j] = 1;
    auto dist3 = warshall_floyd!(long, INF)(dist2);

    auto Q = readln.chomp.to!int;
    while (Q--) {
        s = readln.split.map!(to!int);
        auto a = s[0] - 1;
        auto b = s[1] - 1;
        auto ans = dist3[a][b];
        writeln(ans >= INF ? -1 : ans - 1);
    }
}

T[][] warshall_floyd(T, T inf)(const T[][] graph) {
    import std.conv : to;

    int n = graph.length.to!int;
    auto dist = new T[][](n, n);
    foreach (i; 0..n) foreach (j; 0..n) dist[i][j] = graph[i][j];

    foreach (i; 0..n)
        foreach (j; 0..n)
            foreach (k; 0..n)
                if (dist[j][i] != inf && dist[i][k] != inf)
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);

    return dist;
}
