Scanf.scanf "%d %d %d" (fun n m l ->
    let dummy = max_int / 3 in
    let wf mat =
        for i = 0 to n - 1 do
            mat.(i).(i) <- 0;
            for j = 0 to n - 1 do
                for k = 0 to n - 1 do
                    mat.(j).(k) <- min mat.(j).(k) (mat.(j).(i) + mat.(i).(k))
                done
            done
        done;
    in
    let mat = Array.make_matrix n n dummy in
    for i = 1 to m do
        Scanf.scanf " %d %d %d" (fun a b c ->
            let a, b = a - 1, b - 1 in
            mat.(a).(b) <- c;
            mat.(b).(a) <- c;
        )
    done;
    wf mat;
    let fuel = Array.make_matrix n n dummy in
    for i = 0 to n - 1 do
        for j = 0 to n - 1 do
            if i = j then fuel.(i).(j) <- 0 else
            if mat.(i).(j) <= l then fuel.(i).(j) <- 1
        done
    done;
    wf fuel;
    Scanf.scanf " %d" (fun q ->
        for i = 1 to q do
            Scanf.scanf " %d %d" (fun s t ->
                let s, t = s - 1, t - 1 in
                Printf.printf "%d\n" (if fuel.(s).(t) = dummy then -1 else fuel.(s).(t) - 1)
            )
        done
    )
)