ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,m,l = ma()
INF=10**15
cost = [[INF]*n for i in range(n)]
for i in range(m):
    a,b,c = ma();a-=1;b-=1
    cost[a][b]=c
    cost[b][a]=c

def wf(cost):
    l = len(cost[0])
    for k in range(l):
        for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j])
wf(cost)
rest = [[INF]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            rest[i][j]=1
wf(rest)
q = ni()
for i in range(q):
    s,t = ma();s-=1;t-=1
    print(rest[s][t] -1) if rest[s][t] !=INF else print(-1) ma = lambda :map(int,input().split()) ma lambda :map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split lma = lambda :list(map(int,input().split())) lma lambda :list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split tma = lambda :tuple(map(int,input().split())) tma lambda :tuple(map(int,input().split())) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ni = lambda:int(input()) ni lambda:int(input()) int(input()) int input() input yn = lambda fl:print("Yes") if fl else print("No") yn lambda fl:print("Yes") if fl else print("No") print("Yes") if fl else print("No") fl print("Yes") print "Yes" print("No") print "No" fl import collections collections import math math import itertools itertools import heapq as hq heapq n,m,l = ma() n ma() ma m l INF=10**15 INF 10**15 10 15 [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 cost = [[INF]*n for i in range(n)] cost [[INF]*n for i in range(n)] for i in range(m):
    a,b,c = ma();a-=1;b-=1
    cost[a][b]=c
    cost[b][a]=c i range(m) range m a,b,c = ma() a ma() ma b c a-=1 a 1 b-=1 b 1 cost[a][b]=c cost[a][b] [a] cost a b c cost[b][a]=c cost[b][a] [b] cost b a c def wf(cost):
    l = len(cost[0])
    for k in range(l):
        for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) wf l = len(cost[0]) l len(cost[0]) len cost[0] cost 0 for k in range(l):
        for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) k range(l) range l for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) i range(l) range l for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) j range(l) range l cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) cost[i][j] [i] cost i j min(cost[i][j],cost[i][k] + cost[k][j]) min cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j cost cost wf(cost) wf cost [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 rest = [[INF]*n for i in range(n)] rest [[INF]*n for i in range(n)] for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            rest[i][j]=1 i range(n) range n for j in range(n):
        if cost[i][j]<=l:
            rest[i][j]=1 j range(n) range n if cost[i][j]<=l:
            rest[i][j]=1 cost[i][j]<=l cost[i][j] [i] cost i j l rest[i][j]=1 rest[i][j] [i] rest i j 1 wf(rest) wf rest q = ni() q ni() ni for i in range(q):
    s,t = ma();s-=1;t-=1
    print(rest[s][t] -1) if rest[s][t] !=INF else print(-1) i range(q) range q s,t = ma() s ma() ma t s-=1 s 1 t-=1 t 1 print(rest[s][t] -1) if rest[s][t] !=INF else print(-1) rest[s][t] !=INF rest[s][t] [s] rest s t INF print(rest[s][t] -1) print rest[s][t] -1 rest[s][t] [s] rest s t 1 print(-1) print -1 INF=10**15 10**15 INF ni = lambda:int(input()) lambda:int(input()) ni yn = lambda fl:print("Yes") if fl else print("No") lambda fl:print("Yes") if fl else print("No") yn n,m,l = ma() ma() n ma = lambda :map(int,input().split()) lambda :map(int,input().split()) ma a-=1 1 a a,b,c = ma() ma() a q = ni() ni() q s-=1 1 s b,c = ma() ma() b lma = lambda :list(map(int,input().split())) lambda :list(map(int,input().split())) lma m,l = ma() ma() m t-=1 1 t b-=1 1 b s,t = ma() ma() s l = ma() ma() l c = ma() ma() c def wf(cost):
    l = len(cost[0])
    for k in range(l):
        for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) def wf(cost):
    l = len(cost[0])
    for k in range(l):
        for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j]) wf t = ma() ma() t rest = [[INF]*n for i in range(n)] [[INF]*n for i in range(n)] rest tma = lambda :tuple(map(int,input().split())) lambda :tuple(map(int,input().split())) tma cost = [[INF]*n for i in range(n)] [[INF]*n for i in range(n)] cost
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,m,l = ma()
INF=10**15
cost = [[INF]*n for i in range(n)]
for i in range(m):
    a,b,c = ma();a-=1;b-=1
    cost[a][b]=c
    cost[b][a]=c

def wf(cost):
    l = len(cost[0])
    for k in range(l):
        for i in range(l):
            for j in range(l):
                cost[i][j] =  min(cost[i][j],cost[i][k] + cost[k][j])
wf(cost)
rest = [[INF]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            rest[i][j]=1
wf(rest)
q = ni()
for i in range(q):
    s,t = ma();s-=1;t-=1
    print(rest[s][t] -1) if rest[s][t] !=INF else print(-1)
