import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M, L;
    scan(N, M, L);
    auto G1 = new long[][](N, N);
    foreach (i; 0 .. N)
        G1[i][] = long.max >> 2;
    foreach (i; 0 .. N)
        G1[i][i] = 0;
    foreach (_; 0 .. M)
    {
        long a, b, c;
        scan(a, b, c);
        a--, b--;
        G1[a][b] = G1[b][a] = c;
    }
    foreach (k; 0 .. N)
        foreach (i; 0 .. N)
            foreach (j; 0 .. N)
                if (G1[i][k] + G1[k][j] < G1[i][j])
                    G1[i][j] = G1[i][k] + G1[k][j];
    auto G2 = new long[][](N, N);
    foreach (i; 0 .. N)
        G2[i][] = long.max >> 2;
    foreach (i; 0 .. N)
        G2[i][i] = 0;
    foreach (i; 0 .. N)
        foreach (j; 0 .. N)
            if (G1[i][j] <= L)
            {
                G2[i][j] = min(G2[i][j], 1);
            }
    foreach (k; 0 .. N)
        foreach (i; 0 .. N)
            foreach (j; 0 .. N)
                if (G2[i][k] + G2[k][j] < G2[i][j])
                    G2[i][j] = G2[i][k] + G2[k][j];
    long Q = lread();
    foreach (_; 0 .. Q)
    {
        long s, t;
        scan(s, t);
        s--, t--;
        writeln(G2[s][t] == long.max >> 2 ? -1 : G2[s][t] - 1);
    }
}
