use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! vecs {
    ($init:expr; $($dim:expr);*) => {
        vecs!($($dim);* => $init)
    };
    ($head:expr; $($tail:expr);* => $init:expr) => {
        vec![vecs!($($tail);* => $init); $head]
    };
    ($head:expr => $init:expr) => {
        vec![$init; $head]
    };
}

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let m = scan.read::<usize>();
    let l = scan.read::<i64>();
    let mut g = vec![vec![];n];
    for i in 0..m {
        let a = scan.read::<usize>()-1;
        let b = scan.read::<usize>()-1;
        let c = scan.read::<i64>();
        g[a].push((c, b));
        g[b].push((c, a));
    }

    let q = scan.read::<usize>();
    let d = arr(n, |v| dijkstra(&g, v, l));
    for i in 0..q {
        let s = scan.read::<usize>()-1;
        let t = scan.read::<usize>()-1;
        if d[s][t].0 == 1i64<<60 {
            println!("-1");
        } else {
            println!("{}", d[s][t].0);
        }
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<std::cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> std::cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(unused_macros)]
macro_rules! chmax {
    ($x:expr, $y:expr) => {
        if $x < $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}


#[allow(unused_macros)]
macro_rules! chmin {
    ($x:expr, $y:expr) => {
        if $x > $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}

#[allow(dead_code)]
fn dijkstra(graph: &[Vec<(i64, usize)>], s: usize, l: i64) -> Vec<(i64, i64)> {
    let n = graph.len();
    let mut d = vec![(1i64 << 60, 0); n];
    d[s] = (0, 0);
    let mut heap = std::collections::BinaryHeap::new();
    heap.push(Rev(((0, 0), s)));
    while let Some(Rev(((p_cnt, p_used), p))) = heap.pop() {
        if d[p] < (p_cnt, p_used) {
            continue;
        }
        for &(v_cost, v) in &graph[p] {
            if v_cost > l {continue;}
            let nextpair = if p_used + v_cost > l {(p_cnt + 1, v_cost)}
            else {(p_cnt, p_used + v_cost)};
            if chmin!(d[v], nextpair) {
                heap.push(Rev((d[v], v)));
            }
        }
    }
    d
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

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

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 9488