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

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N, M, L;
    scan(N, M, L);

    auto dist = new long[][](N, N);
    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. N) {
            if (i != j) dist[i][j] = inf6;
        }
    }

    foreach (i ; 0 .. M) {
        int ai, bi, ci;
        scan(ai, bi, ci);
        ai--, bi--;
        dist[ai][bi] = dist[bi][ai] = ci;
    }

    foreach (k ; 0 .. N) {
        foreach (i ; 0 .. N) {
            foreach (j ; 0 .. N) {
                chmin(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    auto d = new int[][](N, N);
    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. N) {
            if (i == j) {
                d[i][j] = 0;
                continue;
            }
            d[i][j] = dist[i][j] <= L ? 1 : inf;
        }
    }

    foreach (k ; 0 .. N) {
        foreach (i ; 0 .. N) {
            foreach (j ; 0 .. N) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int Q;
    scan(Q);

    while (Q--) {
        int si, ti;
        scan(si, ti);
        si--, ti--;
        writeln(d[si][ti] < inf ? d[si][ti] - 1 : -1);
    }
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
