use io::*;
use std::*;

fn solve(N: i64, M: i64, L: i64, A: Vec<i64>, B: Vec<i64>, C: Vec<i64>, Q: i64, s: Vec<i64>, t: Vec<i64>) {
    let mut G: Vec<Vec<i64>> = vec![vec![1_000_000_009 as i64; N as usize]; N as usize];
    let M = M as usize;
    let N = N as usize;

    for i in 0usize..M as usize {
        G[(A[i] - 1) as usize][(B[i] - 1) as usize] = C[i];
        G[(B[i]-  1) as usize][(A[i] - 1) as usize] = C[i];
    }

    // 都市から都市までの最短距離の計算
    for k in 0..N {
        for i in 0..N {
            for j in 0..N {
                if G[i][j] > G[i][k] + G[k][j]
                {
                    G[i][j] = G[i][k] + G[k][j];
                }
            }
        }
    }

    let mut T: Vec<Vec<i64>> = vec![vec![1_000_000_009; N as usize]; N as usize];
    for i in 0..N as usize {
        for k in 0..N as usize { 
            if G[i][k] <= L {
                T[i][k] = 1;
            }
        }
    }

    for k in 0.. N{
        for i in 0..N {
            for j in 0..N {
                if T[i][j] > T[i][k] + T[k][j]
                {
                    T[i][j] = T[i][k] + T[k][j];
                }
            }
        }
    }

    for i in 0..Q  as usize{
        let num = T[(s[i] - 1) as usize][(t[i] - 1) as usize]  - 1;

        if num < 1_000_000_000 {
            println!("{}", num);
        } else {
            println!("-1");
        }
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut M: i64;
    M = scanner.next();
    let mut L: i64;
    L = scanner.next();
    let mut A: Vec<i64> = vec![0i64; (M) as usize];
    let mut B: Vec<i64> = vec![0i64; (M) as usize];
    let mut C: Vec<i64> = vec![0i64; (M) as usize];
    for i in 0..(M) as usize {
        A[i] = scanner.next();
        B[i] = scanner.next();
        C[i] = scanner.next();
    }
    let mut Q: i64;
    Q = scanner.next();
    let mut s: Vec<i64> = vec![0i64; (Q) as usize];
    let mut t: Vec<i64> = vec![0i64; (Q) as usize];
    for i in 0..(Q) as usize {
        s[i] = scanner.next();
        t[i] = scanner.next();
    }
    // 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(move || solve(N, M, L, A, B, C, Q, s, t)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 12796