N, M, L = map(int,input().split())
MAX=99999999999
A=[]
B=[]
C=[]
D=[[MAX for _ in range(N)] for _ in range(N)]
F=[[MAX for _ in range(N)] for _ in range(N)]
s=[]
t=[]
 
for i in range(M):
    l=list(map(int,input().split()))
    A.append(l[0]-1)
    B.append(l[1]-1)
    C.append(l[2])
 
 
 
Q=int(input())
 
for i in range(Q):
    m=list(map(int,input().split()))
    s.append(m[0]-1)
    t.append(m[1]-1)
 
 
for i in range(M):
    if C[i]>L : continue
    D[A[i]][B[i]]=C[i]
    D[B[i]][A[i]]=C[i]
 
for i in range(N):  D[i][i]=0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if (D[i][k]+D[k][j])<D[i][j] :
                D[i][j]=D[i][k]+D[k][j]
 
for i in range(N):
    for j in range(N):
        if i==j : continue
        if D[i][j]<=L: F[i][j]=1
 
 
for i in range(N):  F[i][i]=0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if (F[i][k]+F[k][j])<F[i][j] :
                F[i][j]=F[i][k]+F[k][j]
 
 
for p in range(Q) :
    if F[s[p]][t[p]] < MAX :
        print(F[s[p]][t[p]]-1)
    else :
        print(-1) N, M, L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L MAX=99999999999 MAX 99999999999 A=[] A [] B=[] B [] C=[] C [] [MAX for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [MAX for _ in range(N)] D=[[MAX for _ in range(N)] for _ in range(N)] D [[MAX for _ in range(N)] for _ in range(N)] [MAX for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [MAX for _ in range(N)] F=[[MAX for _ in range(N)] for _ in range(N)] F [[MAX for _ in range(N)] for _ in range(N)] s=[] s [] t=[] t [] for i in range(M):
    l=list(map(int,input().split()))
    A.append(l[0]-1)
    B.append(l[1]-1)
    C.append(l[2])
 
 
  i range(M) range M l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split A.append(l[0]-1) A.append A append l[0]-1 l[0] l 0 1 B.append(l[1]-1) B.append B append l[1]-1 l[1] l 1 1 C.append(l[2]) C.append C append l[2] l 2 Q=int(input()) Q int(input()) int input() input for i in range(Q):
    m=list(map(int,input().split()))
    s.append(m[0]-1)
    t.append(m[1]-1)
 
  i range(Q) range Q m=list(map(int,input().split())) m list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split s.append(m[0]-1) s.append s append m[0]-1 m[0] m 0 1 t.append(m[1]-1) t.append t append m[1]-1 m[1] m 1 1 for i in range(M):
    if C[i]>L : continue
    D[A[i]][B[i]]=C[i]
    D[B[i]][A[i]]=C[i]
  i range(M) range M if C[i]>L : continue
     C[i]>L C[i] C i L D[A[i]][B[i]]=C[i] D[A[i]][B[i]] [A[i]] D A[i] A i B[i] B i C[i] C i D[B[i]][A[i]]=C[i] D[B[i]][A[i]] [B[i]] D B[i] B i A[i] A i C[i] C i for i in range(N):  D[i][i]=0
  i range(N) range N for k in range(N):
    for i in range(N):
        for j in range(N):
            if (D[i][k]+D[k][j])<D[i][j] :
                D[i][j]=D[i][k]+D[k][j]
  k range(N) range N for i in range(N):
        for j in range(N):
            if (D[i][k]+D[k][j])<D[i][j] :
                D[i][j]=D[i][k]+D[k][j]
  i range(N) range N for j in range(N):
            if (D[i][k]+D[k][j])<D[i][j] :
                D[i][j]=D[i][k]+D[k][j]
  j range(N) range N if (D[i][k]+D[k][j])<D[i][j] :
                D[i][j]=D[i][k]+D[k][j]
  (D[i][k]+D[k][j])<D[i][j] D[i][k]+D[k][j] D[i][k] [i] D i k D[k][j] [k] D k j D[i][j] [i] D i j D[i][j]=D[i][k]+D[k][j] 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 for i in range(N):
    for j in range(N):
        if i==j : continue
        if D[i][j]<=L: F[i][j]=1
 
  i range(N) range N for j in range(N):
        if i==j : continue
        if D[i][j]<=L: F[i][j]=1
 
  j range(N) range N if i==j : continue
         i==j i j if D[i][j]<=L: F[i][j]=1
 
  D[i][j]<=L D[i][j] [i] D i j L for i in range(N):  F[i][i]=0
  i range(N) range N for k in range(N):
    for i in range(N):
        for j in range(N):
            if (F[i][k]+F[k][j])<F[i][j] :
                F[i][j]=F[i][k]+F[k][j]
 
  k range(N) range N for i in range(N):
        for j in range(N):
            if (F[i][k]+F[k][j])<F[i][j] :
                F[i][j]=F[i][k]+F[k][j]
 
  i range(N) range N for j in range(N):
            if (F[i][k]+F[k][j])<F[i][j] :
                F[i][j]=F[i][k]+F[k][j]
 
  j range(N) range N if (F[i][k]+F[k][j])<F[i][j] :
                F[i][j]=F[i][k]+F[k][j]
 
  (F[i][k]+F[k][j])<F[i][j] F[i][k]+F[k][j] F[i][k] [i] F i k F[k][j] [k] F k j F[i][j] [i] F i j F[i][j]=F[i][k]+F[k][j] F[i][j] [i] F i j F[i][k]+F[k][j] F[i][k] [i] F i k F[k][j] [k] F k j for p in range(Q) :
    if F[s[p]][t[p]] < MAX :
        print(F[s[p]][t[p]]-1)
    else :
        print(-1) p range(Q) range Q if F[s[p]][t[p]] < MAX :
        print(F[s[p]][t[p]]-1)
    else :
        print(-1) F[s[p]][t[p]] < MAX F[s[p]][t[p]] [s[p]] F s[p] s p t[p] t p MAX print(F[s[p]][t[p]]-1) print F[s[p]][t[p]]-1 F[s[p]][t[p]] [s[p]] F s[p] s p t[p] t p 1 print(-1) print -1 MAX=99999999999 99999999999 MAX N, M, L = map(int,input().split()) map(int,input().split()) N A=[] [] A B=[] [] B M, L = map(int,input().split()) map(int,input().split()) M m=list(map(int,input().split())) list(map(int,input().split())) m s=[] [] s C=[] [] C Q=int(input()) int(input()) Q D=[[MAX for _ in range(N)] for _ in range(N)] [[MAX for _ in range(N)] for _ in range(N)] D L = map(int,input().split()) map(int,input().split()) L t=[] [] t l=list(map(int,input().split())) list(map(int,input().split())) l F=[[MAX for _ in range(N)] for _ in range(N)] [[MAX for _ in range(N)] for _ in range(N)] F
N, M, L = map(int,input().split())
MAX=99999999999
A=[]
B=[]
C=[]
D=[[MAX for _ in range(N)] for _ in range(N)]
F=[[MAX for _ in range(N)] for _ in range(N)]
s=[]
t=[]
 
for i in range(M):
    l=list(map(int,input().split()))
    A.append(l[0]-1)
    B.append(l[1]-1)
    C.append(l[2])
 
 
 
Q=int(input())
 
for i in range(Q):
    m=list(map(int,input().split()))
    s.append(m[0]-1)
    t.append(m[1]-1)
 
 
for i in range(M):
    if C[i]>L : continue
    D[A[i]][B[i]]=C[i]
    D[B[i]][A[i]]=C[i]
 
for i in range(N):  D[i][i]=0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if (D[i][k]+D[k][j])<D[i][j] :
                D[i][j]=D[i][k]+D[k][j]
 
for i in range(N):
    for j in range(N):
        if i==j : continue
        if D[i][j]<=L: F[i][j]=1
 
 
for i in range(N):  F[i][i]=0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if (F[i][k]+F[k][j])<F[i][j] :
                F[i][j]=F[i][k]+F[k][j]
 
 
for p in range(Q) :
    if F[s[p]][t[p]] < MAX :
        print(F[s[p]][t[p]]-1)
    else :
        print(-1)