// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert

#if true && UTAKA_LOCAL

//#if false
#define UTAKA_DEBUG
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace UtakaApp
{
    public partial class Program
    {
        //=========================================================================================
        // Answer
        //=========================================================================================

        public const string SiteName    = "AtCoder";
        public const string ContestName = "abc143";
        public const string ProblemName = "E";

        public const long Inf = 1L << 60;

        public void Solve()
        {
            int N = cin.ReadInt;
            int M = cin.ReadInt;
            int L = cin.ReadInt;

            long[][] dp = new long[N][];
            for (int i = 0; i < N; i++)
            {
                dp[i] = new long[N];

                for (int j = 0; j < N; j++)
                {
                    dp[i][j] = i == j ? 0 : Inf;
                }
            }

            for (int i = 0; i < M; i++)
            {
                int  A = cin.ReadInt - 1;
                int  B = cin.ReadInt - 1;
                long C = cin.ReadLong;

                dp[A][B] = C;
                dp[B][A] = C;
            }

            WarshallFloyd(dp);

            long[][] fuelDp = new long[N][];
            for (int i = 0; i < N; i++)
            {
                fuelDp[i] = new long[N];

                for (int j = 0; j < N; j++)
                {
                    fuelDp[i][j] = i == j ? 0 : Inf;
                }
            }

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (i == j) continue;
                    
                    if (dp[i][j] <= L)
                    {
                        fuelDp[i][j] = 1;
                    }
                }
            }

            WarshallFloyd(fuelDp);

            int Q = cin.ReadInt;

            for (int i = 0; i < Q; i++)
            {
                int s = cin.ReadInt - 1;
                int t = cin.ReadInt - 1;

                long ans = fuelDp[s][t];
                ans = ans == Inf ? -1 : ans - 1;

                cou.WriteLine(ans);
            }
        }

        public void WarshallFloyd(long[][] dp)
        {
            int V = dp.Length;

            for (int k = 0; k < V; k++)
            {
                for (int i = 0; i < V; i++)
                {
                    if (dp[i][k] == Inf) continue;

                    for (int j = 0; j < V; j++)
                    {
                        if (dp[k][j] == Inf) continue;

                        dp[i][j] = Math.Min(dp[i][j], dp[i][k] + dp[k][j]);
                    }
                }
            }
        }
    }


//    public partial class Program
//    {
//        //=========================================================================================
//        // Answer
//        //=========================================================================================
//
//        public const string SiteName    = "AOJ";
//        public const string ContestName = "GRL_1";
//        public const string ProblemName = "C";
//
//        public const long Inf = 1L << 60;
//
//        // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
//        public void Solve()
//        {
//            int V = cin.ReadInt;
//            int E = cin.ReadInt;
//
//            long[][] dp = new long[V][];
//            for (int i = 0; i < V; i++)
//            {
//                dp[i] = new long[V];
//
//                for (int j = 0; j < V; j++)
//                {
//                    dp[i][j] = i == j ? 0 : Inf;
//                }
//            }
//
//            for (int i = 0; i < E; i++)
//            {
//                int s = cin.ReadInt;
//                int t = cin.ReadInt;
//                int d = cin.ReadInt;
//
//                dp[s][t] = d;
//            }
//
//            WarshallFloyd(dp);
//
//            bool foundNegative = false;
//
//            for (int i = 0; i < V; i++)
//            {
//                if (dp[i][i] < 0)
//                {
//                    foundNegative = true;
//                    break;
//                }
//            }
//
//            if (foundNegative)
//            {
//                cou.WriteLine("NEGATIVE CYCLE");
//                return;
//            }
//
//            for (int i = 0; i < V; i++)
//            {
//                for (int j = 0; j < V; j++)
//                {
//                    if (j > 0) cou.Write(" ");
//
//                    if (dp[i][j] == Inf)
//                    {
//                        cou.Write("INF");
//                    }
//                    else
//                    {
//                        cou.Write(dp[i][j]);
//                    }
//                }
//
//                cou.WriteLine();
//            }
//        }
//
//        public void WarshallFloyd(long[][] dp)
//        {
//            int V = dp.Length;
//
//            for (int k = 0; k < V; k++)
//            {
//                for (int i = 0; i < V; i++)
//                {
//                    if (dp[i][k] == Inf) continue;
//
//                    for (int j = 0; j < V; j++)
//                    {
//                        if (dp[k][j] == Inf) continue;
//
//                        dp[i][j] = Math.Min(dp[i][j], dp[i][k] + dp[k][j]);
//                    }
//                }
//            }
//        }
//    }


//=========================================================================================
// Library
//=========================================================================================


//=========================================================================================
// Debug IO
//=========================================================================================

    public partial class Program
    {
        //=========================================================================================
        // Main
        //=========================================================================================

        private readonly ConsoleInput cin;
        private readonly IConsole     cou;

        public Program(ConsoleInput cin, IConsole cou)
        {
            this.cin = cin;
            this.cou = cou;
        }

        public static void Main(string[] args)
        {
#if UTAKA_LOCAL
//#if false
            new TestCaseCheckerForAtCoder().TestProblems();
#else
            var cin = new ConsoleInput(System.Console.In);
            var console = new MyConsole();
            new Program(cin, console).Solve();
            console.Flush();
#endif
        }
    }

    public class ConsoleInput
    {
        private readonly char          _separator = ' ';
        private readonly TextReader    _stream;
        private readonly Queue<string> inputStream;

        public ConsoleInput(TextReader stream, char separator = ' ')
        {
            _separator  = separator;
            _stream     = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0)
                {
                    return inputStream.Dequeue();
                }

                var tmp = _stream.ReadLine().Split(_separator);
                for (var i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }

                return inputStream.Dequeue();
            }
        }

        public string ReadLine   => _stream.ReadLine();
        public int    ReadInt    => int.Parse(Read);
        public long   ReadLong   => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);

        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = Read;
            }

            return ret;
        }

        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadInt;
            }

            return ret;
        }

        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadLong;
            }

            return ret;
        }
    }

    public interface IConsole
    {
        void Flush();
        void Write(object obj);
        void Write(string str);
        void WriteLine(object obj);
        void WriteLine(string str);
        void WriteLine();
    }

    public class MyConsole : IConsole
    {
        public MyConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(sw);
        }

        public void Flush()
        {
            Console.Out.Flush();
        }

        public void Write(object obj)
        {
            Write(obj.ToString());
        }

        public void Write(string str)
        {
            Console.Write(str);
        }

        public void WriteLine(object obj)
        {
            WriteLine(obj.ToString());
        }

        public void WriteLine(string str)
        {
            Console.WriteLine(str);
        }

        public void WriteLine()
        {
            Console.WriteLine();
        }
    }

#if UTAKA_LOCAL

    public class DebugConsole : IConsole
    {
        private readonly StringBuilder mSb;

        public DebugConsole()
        {
            mSb = new StringBuilder();
        }

        public void Flush()
        {
            // 何もしない
        }

        public void Write(object obj)
        {
            Write(obj.ToString());
        }

        public void Write(string str)
        {
            mSb.Append(str);
        }

        public void WriteLine(object obj)
        {
            WriteLine(obj.ToString());
        }

        public void WriteLine(string str)
        {
            mSb.AppendLine(str);
        }

        public void WriteLine()
        {
            mSb.AppendLine();
        }

        public string GetAllOutput()
        {
            return mSb.ToString();
        }
    }

#endif

#if UTAKA_LOCAL

    public class TestCaseCheckerForAtCoder
    {
        private string GetDirectoryPath()
        {
            var problemPart = string.IsNullOrEmpty(Program.ProblemName)
                ? ""
                : $"/{Program.ProblemName}";

            return
                $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
        }

        private string GetInputFilePath(int testCaseNumber)
        {
            return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
        }

        private string GetOutputFilePath(int testCaseNumber)
        {
            return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
        }

        public bool TestProblem(int testCaseNumber)
        {
            var inputFilePath  = GetInputFilePath(testCaseNumber);
            var outputFilePath = GetOutputFilePath(testCaseNumber);

            TextReader inputStream = new StreamReader(inputFilePath);
            var        cin         = new ConsoleInput(inputStream);

            var debugConsoleWriter = new DebugConsole();

            new Program(cin, debugConsoleWriter).Solve();

            var output = debugConsoleWriter.GetAllOutput();

            TextReader outputStream = new StreamReader(outputFilePath);
            var        outputAnswer = outputStream.ReadToEnd();

            Dbg.WriteLine(output);
            Dbg.WriteLine(outputAnswer);

            var isCorrect = output == outputAnswer;

            return isCorrect;
        }

        public void TestProblems(int targetTestCaseNumber = -1)
        {
            if (targetTestCaseNumber >= 0)
            {
                Console.WriteLine($"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
            }

            bool isSuccessAll = true;

            int testCaseNumber = 0;
            while (true)
            {
                testCaseNumber++;

                if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber)
                {
                    continue;
                }

                var inputFileName = GetInputFilePath(testCaseNumber);
                if (!File.Exists(inputFileName))
                {
                    break;
                }

                Console.WriteLine($"TestCase {testCaseNumber} =====================================================");

                var result = TestProblem(testCaseNumber);

                if (result)
                {
                    Console.WriteLine("Success");
                }
                else
                {
                    isSuccessAll = false;
                    Console.WriteLine("Failure *****");
                }
            }

            if (isSuccessAll)
            {
                Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
            }
        }
    }

#endif

#if UTAKA_LOCAL

    public static class Dbg
    {
        public static void WriteLine(string str)
        {
            Console.WriteLine(str);
        }

        public static void Write(string str)
        {
            Console.Write(str);
        }
    }
#else
    public static class Dbg
    {
        public static void WriteLine(string str)
        {
        }

        public static void Write(string str)
        {
        }
    }

#endif
}


Measured memory_bytes: 19244