import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nml = readln.split.to!(int[]);
    auto N = nml[0];
    auto M = nml[1];
    long L = nml[2];

    auto G = new long[][](N, N);
    foreach (ref g; G) foreach (ref e; g) e = long.max / 3;
    foreach (_; 0..M) {
        auto abc = readln.split.to!(int[]);
        auto A = abc[0]-1;
        auto B = abc[1]-1;
        long C = abc[2];
        if (C > L) continue;
        G[A][B] = C;
        G[B][A] = C;
    }

    int[][] H;
    H.length = N;
    auto memo = new long[](N);
    foreach (i; 0..N) {
        memo[] = false;
        void walk(int j, long f) {
            H[i] ~= j;
            memo[j] = f;
            foreach (k, ff; G[j]) {
                if (ff > L || memo[k] > f - ff) continue;
                walk(k.to!int, f - ff);
            }
        }
        walk(i, L);
    }

    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto st = readln.split.to!(int[]);
        auto s = st[0]-1;
        auto t = st[1]-1;
        int r = -1, cnt;
        int[] ss = [s];
        memo[] = false;
        memo[s] = true;
        while (!ss.empty) {
            int[] nss;
            foreach (n; ss) {
                foreach (m; H[n]) if (!memo[m]) {
                    memo[m] = true;
                    if (m == t) {
                        r = cnt;
                        goto loopend;
                    }
                    nss ~= m;
                }
            }
            ss = nss;
            ++cnt;
        }
        loopend:
        writeln(r);
    }
}