#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;
use std::io::{Write, BufWriter};

// static MOD: usize = 998244353;
static MOD: usize = 1000000007;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! println_stderr(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn dijkstra(start: usize, edge: &Vec<Vec<(usize,i64)>>, l: i64) -> Vec<i64>{
    let n = edge.len() as usize;
    let mut dist = vec![(n as i64,l);n];
    dist[start] = (0,0);
    let mut heap = BinaryHeap::new();
    heap.push((0, 0, start));
    while let Some((pop_count, pop_cost, v)) = heap.pop() {
        let cur_count = -pop_count;
        let cur_cost = -pop_cost;
        if dist[v] < (cur_count,cur_cost) {continue;}
        for &(next, cost) in edge[v].iter(){
            let next_cost = cur_cost + cost;
            if next_cost<=l {
                let next_count = cur_count;
                if dist[next] > (next_count, next_cost) {
                    dist[next] = (next_count, next_cost);
                    heap.push((-next_count, -next_cost, next));
                }
            }
            else if cost<=l {
                let next_count = cur_count + 1;
                let next_cost = cost;
                if dist[next] > (next_count, next_cost) {
                    dist[next] = (next_count, next_cost);
                    heap.push((-next_count , -next_cost, next));
                }
            }
        }
    }
    dist.into_iter().map(|(a,b)| a).collect()
}

fn solve() {
    input! {
        n: usize,
        m: usize,
        l: i64,
        e: [(usize,usize,i64);m],
        q: usize,
        st: [(usize,usize);q],
    }  
    let mut edge: Vec<Vec<(usize,i64)>> = vec![vec![];n];
    for i in 0..m {
        let (s,t,w) = e[i];
        edge[s-1].push((t-1,w));
        edge[t-1].push((s-1,w));
    }
    let mut books = HashMap::new();
    for (s,t) in st{
        if !books.contains_key(&s) {
            let dist = dijkstra(s-1,&edge,l);
            books.insert(s, dist);
        }
        let dist = books.get(&s).unwrap();
        if dist[t-1] as usize==n {println!("{}", -1);}
        else {println!("{}", dist[t-1]);}
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 16764