using System;
using System.Collections.Generic;
using System.Text;

public class Program
{
    private int N, M, L;

    private int Q;
    private int[] S, T;

    private int[,] Ans;

    private long[,] Dist;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        L = sc.NextInt();
    Dist = new long[N,N];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            Dist[i, j] = long.MaxValue / 2;
            if (i == j)
            {
                Dist[i, j] = 0;
            }
        }
    }

        for (int i = 0; i < M; i++)
        {
            int a = sc.NextInt() - 1;
            int b = sc.NextInt() - 1;
            int c = sc.NextInt();
            Dist[a, b] = c;
            Dist[b, a] = c;
        }

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                for (int k = 0; k < N; k++)
                {
                    Dist[j, k] = Math.Min(Dist[j, k], Dist[j, i] + Dist[i, k]);
                }
            }
        }

        Q = sc.NextInt();
        S = new int[Q];
        T = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            S[i] = sc.NextInt() - 1;
            T[i] = sc.NextInt() - 1;
        }

        Ans = new int[N, N];
        for (int i = 0; i < N; i++)
        {
            Calc(i);
        }

        var sb = new StringBuilder();
        for (int i = 0; i < Q; i++)
        {
            sb.AppendLine(Ans[S[i], T[i]].ToString());
        }

        Console.Write(sb.ToString());
    }

    private void Calc(int start)
    {
        int[] ans = new int[N];
        var q = new List<int>();
        for (int i = 0; i < N; i++)
        {
            ans[i] = -1;
        }
        q.Add(start);
        int cnt = 0;
        while (q.Count > 0)
        {
            var next = new List<int>();
            foreach (int i in q)
            {
                for (int j = 0; j < N; j++)
                {
                    if (ans[j] == -1 && Dist[i, j] <= L)
                    {
                        ans[j] = cnt;
                        next.Add(j);
                    }
                }
            }

            q = next;
            cnt++;
        }

        for (int i = 0; i < N; i++)
        {
            Ans[start, i] = ans[i];
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 20420