using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var cin = new Scanner();

            int N, M, L;
            var input = cin.SplitRead();
            N = input[0];
            M = input[1];
            L = input[2];
            var dist = new long[N, N];
            var fuel = new long[N, N];


            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    dist[i, j] = i == j ? 0 : INF;
                    fuel[i, j] = i == j ? 0 : INF;
                }
            }
            for (var i = 0; i < M; i++)
            {
                var p = cin.SplitRead();
                int A = p[0] - 1;
                int B = p[1] - 1;
                long C = p[2];
                if (C > L) { continue; }
                dist[A, B] = C;
                dist[B, A] = C;
            }
            

            Warshall_floyd(N, dist);
            
            for(var i = 0; i < N; i++)
            {
                for(var j = 0; j < N; j++)
                {
                    if (dist[i, j] <= L)
                    {
                        fuel[i, j] = 1;
                    }
                }
            }

            Warshall_floyd(N, fuel);

            int Q = int.Parse(Console.ReadLine());
            var s = new int[Q];
            var t = new int[Q];
            for(var i = 0; i < Q; i++)
            {
                var p = cin.SplitRead();
                s[i] = p[0] - 1;
                t[i] = p[1] - 1;
            }

            

            for(var i = 0; i < Q; i++)
            {
                Console.WriteLine(fuel[s[i], t[i]] >= INF ? -1 : fuel[s[i], t[i]] - 1);
            }

            Console.Out.Flush();
        }

        static public void Warshall_floyd(int n, long[,] dist)
        {
            for (var k = 0; k < n; k++)
            {
                for (var i = 0; i < n; i++)
                {
                    for (var j = 0; j < n; j++)
                    {
                        dist[i, j] = Min(dist[i, j], dist[i, k] + dist[k, j]);
                    }
                }
            }

        }
    }

    

    

    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 19648