from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


n,m,l=MI()
d=[[inf]*n for _ in range(n)]
for i in range(m):
    a,b,c=LI_()
    d[a][b]=c+1
    d[b][a]=c+1

d=wf(d)
g=[[inf]*n for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            g[i][j]=1
            g[j][i]=1
g=wf(g)

q=I()
for _ in range(q):
    s,t=LI_()
    if g[s][t]==inf:
        ans=-1
    else:
        ans=g[s][t]-1
    print(ans)
     from heapq import heappush, heappop from collections import deque,defaultdict,Counter import itertools itertools from itertools import permutations,combinations import sys sys import bisect bisect import string string def I():
    return int(input()) I return int(input()) int(input()) int input() input def MI():
    return map(int,input().split()) MI return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def LI():
    return [int(i) for i in input().split()] LI int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i return [int(i) for i in input().split()] [int(i) for i in input().split()] def LI_():
    return [int(i)-1 for i in input().split()] LI_ int(i)-1 for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i)-1 int(i) int i 1 return [int(i)-1 for i in input().split()] [int(i)-1 for i in input().split()] def StoI():
    return [ord(i)-97 for i in input()] StoI ord(i)-97 for i in input() for i in input() i input() input for i in input() ord(i)-97 ord(i) ord i 97 return [ord(i)-97 for i in input()] [ord(i)-97 for i in input()] def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end) show if show_flg:
        print(*inp,end=end) show_flg print(*inp,end=end) print *inp inp end=end end end end='\n' end '\n' *inp YN=['Yes','No'] YN ['Yes','No'] 'Yes' 'No' mo=10**9+7 mo 10**9+7 10**9 10 9 7 inf=float('inf') inf float('inf') float 'inf' input=lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip show_flg=False show_flg False show_flg=True show_flg True def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d wf n=len(d) n len(d) len d for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     k range(n) range n for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     i range(n) range n for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     j range(n) range n d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d n,m,l=MI() n MI() MI m l [inf]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf]*n [inf] inf n d=[[inf]*n for _ in range(n)] d [[inf]*n for _ in range(n)] for i in range(m):
    a,b,c=LI_()
    d[a][b]=c+1
    d[b][a]=c+1 i range(m) range m a,b,c=LI_() a LI_() LI_ b c d[a][b]=c+1 d[a][b] [a] d a b c+1 c 1 d[b][a]=c+1 d[b][a] [b] d b a c+1 c 1 d=wf(d) d wf(d) wf d [inf]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [inf]*n [inf] inf n g=[[inf]*n for i in range(n)] g [[inf]*n for i in range(n)] for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            g[i][j]=1
            g[j][i]=1 i range(n) range n for j in range(i+1,n):
        if d[i][j]<=l:
            g[i][j]=1
            g[j][i]=1 j range(i+1,n) range i+1 i 1 n if d[i][j]<=l:
            g[i][j]=1
            g[j][i]=1 d[i][j]<=l d[i][j] [i] d i j l g[i][j]=1 g[i][j] [i] g i j 1 g[j][i]=1 g[j][i] [j] g j i 1 g=wf(g) g wf(g) wf g q=I() q I() I for _ in range(q):
    s,t=LI_()
    if g[s][t]==inf:
        ans=-1
    else:
        ans=g[s][t]-1
    print(ans)
     _ range(q) range q s,t=LI_() s LI_() LI_ t if g[s][t]==inf:
        ans=-1
    else:
        ans=g[s][t]-1
     g[s][t]==inf g[s][t] [s] g s t inf ans=-1 ans -1 ans=g[s][t]-1 ans g[s][t]-1 g[s][t] [s] g s t 1 print(ans) print ans m,l=MI() MI() m def StoI():
    return [ord(i)-97 for i in input()] def StoI():
    return [ord(i)-97 for i in input()] StoI def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d wf YN=['Yes','No'] ['Yes','No'] YN def LI_():
    return [int(i)-1 for i in input().split()] def LI_():
    return [int(i)-1 for i in input().split()] LI_ d=[[inf]*n for _ in range(n)] [[inf]*n for _ in range(n)] d def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end) def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end) show input=lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input l=MI() MI() l g=[[inf]*n for i in range(n)] [[inf]*n for i in range(n)] g show_flg=False False show_flg a,b,c=LI_() LI_() a c=LI_() LI_() c mo=10**9+7 10**9+7 mo ans=g[s][t]-1 g[s][t]-1 ans def MI():
    return map(int,input().split()) def MI():
    return map(int,input().split()) MI d=wf(d) wf(d) d n,m,l=MI() MI() n inf=float('inf') float('inf') inf q=I() I() q t=LI_() LI_() t def LI():
    return [int(i) for i in input().split()] def LI():
    return [int(i) for i in input().split()] LI show_flg=True True show_flg s,t=LI_() LI_() s def I():
    return int(input()) def I():
    return int(input()) I b,c=LI_() LI_() b g=wf(g) wf(g) g ans=-1 -1 ans
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


n,m,l=MI()
d=[[inf]*n for _ in range(n)]
for i in range(m):
    a,b,c=LI_()
    d[a][b]=c+1
    d[b][a]=c+1

d=wf(d)
g=[[inf]*n for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            g[i][j]=1
            g[j][i]=1
g=wf(g)

q=I()
for _ in range(q):
    s,t=LI_()
    if g[s][t]==inf:
        ans=-1
    else:
        ans=g[s][t]-1
    print(ans)
    
