def warshal(d):
    n=len(d)
    for k in range(1,n):
        for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d
n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]
q=int(input())
st=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
dp=[[inf]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    dp[i][i]=0
for u in abc:
    a,b,c=u
    dp[a][b]=c
    dp[b][a]=c
dp=warshal(dp)
data=[[inf]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,n+1):
        if 0<dp[i][j]<=l:
            data[i][j]=1
        elif dp[i][j]==0:
            data[i][j]=0
data=warshal(data)
for u in st:
    s,t=u
    if data[s][t]!=inf:
        print(data[s][t]-1)
    else:
        print(-1) def warshal(d):
    n=len(d)
    for k in range(1,n):
        for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d warshal n=len(d) n len(d) len d for k in range(1,n):
        for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
     k range(1,n) range 1 n for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
     i range(1,n) range 1 n for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
     j range(1,n) range 1 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=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split abc=[list(map(int,input().split())) for i in range(m)] abc [list(map(int,input().split())) for i in range(m)] q=int(input()) q int(input()) int input() input list(map(int,input().split())) for i in range(q) for i in range(q) i range(q) range q for i in range(q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st=[list(map(int,input().split())) for i in range(q)] st [list(map(int,input().split())) for i in range(q)] inf=float("inf") inf float("inf") float "inf" [inf]*(n+1) for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [inf]*(n+1) [inf] inf n+1 n 1 dp=[[inf]*(n+1) for i in range(n+1)] dp [[inf]*(n+1) for i in range(n+1)] for i in range(1,n+1):
    dp[i][i]=0 i range(1,n+1) range 1 n+1 n 1 dp[i][i]=0 dp[i][i] [i] dp i i 0 for u in abc:
    a,b,c=u
    dp[a][b]=c
    dp[b][a]=c u abc a,b,c=u a u b c dp[a][b]=c dp[a][b] [a] dp a b c dp[b][a]=c dp[b][a] [b] dp b a c dp=warshal(dp) dp warshal(dp) warshal dp [inf]*(n+1) for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [inf]*(n+1) [inf] inf n+1 n 1 data=[[inf]*(n+1) for i in range(n+1)] data [[inf]*(n+1) for i in range(n+1)] for i in range(1,n+1):
    for j in range(1,n+1):
        if 0<dp[i][j]<=l:
            data[i][j]=1
        elif dp[i][j]==0:
            data[i][j]=0 i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
        if 0<dp[i][j]<=l:
            data[i][j]=1
        elif dp[i][j]==0:
            data[i][j]=0 j range(1,n+1) range 1 n+1 n 1 if 0<dp[i][j]<=l:
            data[i][j]=1
        elif dp[i][j]==0:
            data[i][j]=0 0<dp[i][j]<=l 0<dp[i][j] 0 dp[i][j] [i] dp i j l data[i][j]=1 data[i][j] [i] data i j 1 elif dp[i][j]==0:
            data[i][j]=0 dp[i][j]==0 dp[i][j] [i] dp i j 0 data[i][j]=0 data[i][j] [i] data i j 0 data=warshal(data) data warshal(data) warshal data for u in st:
    s,t=u
    if data[s][t]!=inf:
        print(data[s][t]-1)
    else:
        print(-1) u st s,t=u s u t if data[s][t]!=inf:
        print(data[s][t]-1)
    else:
        print(-1) data[s][t]!=inf data[s][t] [s] data s t inf print(data[s][t]-1) print data[s][t]-1 data[s][t] [s] data s t 1 print(-1) print -1 b,c=u u b m,l=map(int,input().split()) map(int,input().split()) m dp=warshal(dp) warshal(dp) dp def warshal(d):
    n=len(d)
    for k in range(1,n):
        for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d def warshal(d):
    n=len(d)
    for k in range(1,n):
        for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d warshal data=[[inf]*(n+1) for i in range(n+1)] [[inf]*(n+1) for i in range(n+1)] data a,b,c=u u a t=u u t dp=[[inf]*(n+1) for i in range(n+1)] [[inf]*(n+1) for i in range(n+1)] dp st=[list(map(int,input().split())) for i in range(q)] [list(map(int,input().split())) for i in range(q)] st inf=float("inf") float("inf") inf data=warshal(data) warshal(data) data c=u u c abc=[list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] abc q=int(input()) int(input()) q s,t=u u s n,m,l=map(int,input().split()) map(int,input().split()) n l=map(int,input().split()) map(int,input().split()) l
def warshal(d):
    n=len(d)
    for k in range(1,n):
        for i in range(1,n):
            for j in range(1,n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d
n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]
q=int(input())
st=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
dp=[[inf]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    dp[i][i]=0
for u in abc:
    a,b,c=u
    dp[a][b]=c
    dp[b][a]=c
dp=warshal(dp)
data=[[inf]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,n+1):
        if 0<dp[i][j]<=l:
            data[i][j]=1
        elif dp[i][j]==0:
            data[i][j]=0
data=warshal(data)
for u in st:
    s,t=u
    if data[s][t]!=inf:
        print(data[s][t]-1)
    else:
        print(-1)