using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		long L = long.Parse(str[2]);
		int[,]A = new int[M,3];
		long[,]B = new long[N,N];
		var list = new List<int>[N];
		for(var i=0;i<N;i++){
			list[i] = new List<int>();
		}
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i,0] = int.Parse(str2[0]);
			A[i,1] = int.Parse(str2[1]);
			A[i,2] = int.Parse(str2[2]);
			B[A[i,0]-1,A[i,1]-1] = A[i,2];
			B[A[i,1]-1,A[i,0]-1] = A[i,2];
			list[A[i,0]-1].Add(A[i,1]-1);
			list[A[i,1]-1].Add(A[i,0]-1);
		}
		long[,]D = new long[N,N];
		for(var i=0;i<N;i++){
			for(var j=0;j<N;j++){
				D[i,j] = -1;
			}
			int[]F = new int[N];
			var pq = new PriorityQueue<long>((x,y)=>D[i,x].CompareTo(D[i,y]));
			pq.Enqueue(i);
          	D[i,i] = 0;
			while(pq.Count>0){
				long a1 = pq.Dequeue();
				if(F[a1]==0){
					F[a1] = 1;
					foreach(var a2 in list[a1]){
						if(B[a1,a2] <= L){
                      		long d1 = D[i,a1] + B[a1,a2];
							if(D[i,a2] == -1 || d1 < D[i,a2]){
								D[i,a2] = d1;
								pq.Enqueue(a2);
							}
                        }
					}
				}
			}
		}
		var list2 = new List<int>[N];
		for(var i=0;i<N;i++){
			list2[i] = new List<int>();
		}
      	for(var i=0;i<N;i++){
          	for(var j=0;j<N;j++){
              	if(D[i,j]!=-1 && D[i,j]<=L){
                  	list2[i].Add(j);
                }
            }
        }
		for(var i=0;i<N;i++){
			for(var j=0;j<N;j++){
				D[i,j] = -1;
			}
			int[]F = new int[N];
			var pq = new PriorityQueue<long>((x,y)=>D[i,x].CompareTo(D[i,y]));
			pq.Enqueue(i);
          	D[i,i] = 0;
			while(pq.Count>0){
				long a1 = pq.Dequeue();
				if(F[a1]==0){
					F[a1] = 1;
					foreach(var a2 in list2[a1]){
						long d1 = D[i,a1] + 1;
						if(D[i,a2] == -1 || d1 < D[i,a2]){
							D[i,a2] = d1;
							pq.Enqueue(a2);
						}
					}
				}
			}
		}
		int Q = int.Parse(Console.ReadLine());
		for(var q=0;q<Q;q++){
			string[] str3 = Console.ReadLine().Split();
			int c1 = int.Parse(str3[0]);
			int c2 = int.Parse(str3[1]);
			long ans = D[c1-1,c2-1];
			if(ans!=-1){
				ans = Math.Max(0,ans-1);
            }
			Console.WriteLine(ans);
		}
	}
}

class PriorityQueue<T>
{
    private readonly List<T> heap;
    private readonly Comparison<T> compare;
    private int size;
    public PriorityQueue() : this(Comparer<T>.Default) {} 
    public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) { }
    public PriorityQueue(Comparison<T> comparison) : this(16, comparison) { }
    public PriorityQueue(int capacity, Comparison<T> comparison)
    {
        this.heap = new List<T>(capacity);
        this.compare = comparison;
    }
    public void Enqueue(T item)
    {
        this.heap.Add(item);
        var i = size++;
        while (i > 0)
        {
            var p = (i - 1) >> 1;
            if (compare(this.heap[p], item) <= 0)
                break;
            this.heap[i] = heap[p];
            i = p;
        }
        this.heap[i] = item;

    }
    public T Dequeue()
    {
        var ret = this.heap[0];
        var x = this.heap[--size];
        var i = 0;
        while ((i << 1) + 1 < size)
        {
            var a = (i << 1) + 1;
            var b = (i << 1) + 2;
            if (b < size && compare(heap[b], heap[a]) < 0) a = b;
            if (compare(heap[a], x) >= 0)
                break;
            heap[i] = heap[a];
            i = a;
        }
        heap[i] = x;
        heap.RemoveAt(size);
        return ret;
    }
    public T Peek() { return heap[0]; }
    public int Count { get { return size; } }
    public bool Any() { return size > 0; }
}

Measured memory_bytes: 27456