import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M,L=MI()
    inf=10**15
    d=[[inf]*N for _ in range(N)]
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        if c<=L:
            d[a][b]=c
            d[b][a]=c
        
    for i in range(N):
        d[i][i]=0
        
    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])
                
    d2=[[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
    Q=I()
    for i in range(Q):
        s,t=MI()
        s-=1
        t-=1
        ans=d2[s][t]
        if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
    

main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI def main():
    mod=10**9+7
    N,M,L=MI()
    inf=10**15
    d=[[inf]*N for _ in range(N)]
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        if c<=L:
            d[a][b]=c
            d[b][a]=c
        
    for i in range(N):
        d[i][i]=0
        
    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])
                
    d2=[[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
    Q=I()
    for i in range(Q):
        s,t=MI()
        s-=1
        t-=1
        ans=d2[s][t]
        if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
     main mod=10**9+7 mod 10**9+7 10**9 10 9 7 N,M,L=MI() N MI() MI M L inf=10**15 inf 10**15 10 15 [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=MI()
        a-=1
        b-=1
        if c<=L:
            d[a][b]=c
            d[b][a]=c
        
     i range(M) range M a,b,c=MI() a MI() MI b c a-=1 a 1 b-=1 b 1 if c<=L:
            d[a][b]=c
            d[b][a]=c
        
     c<=L c L d[a][b]=c d[a][b] [a] d a b c d[b][a]=c d[b][a] [b] d b a c for i in range(N):
        d[i][i]=0
        
     i range(N) range N d[i][i]=0 d[i][i] [i] d i i 0 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 [inf]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [inf]*N [inf] inf N d2=[[inf]*N for _ in range(N)] d2 [[inf]*N for _ in range(N)] for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
     i range(N) range N for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
     j range(N) range N if d[i][j]<=L:
                d2[i][j]=1
                
     d[i][j]<=L d[i][j] [i] d i j L d2[i][j]=1 d2[i][j] [i] d2 i j 1 for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
     k range(N) range N for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
     i range(N) range N for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
     j range(N) range N d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]) d2[i][j] [i] d2 i j min(d2[i][j],d2[i][k]+d2[k][j]) min d2[i][j] [i] d2 i j d2[i][k]+d2[k][j] d2[i][k] [i] d2 i k d2[k][j] [k] d2 k j Q=I() Q I() I for i in range(Q):
        s,t=MI()
        s-=1
        t-=1
        ans=d2[s][t]
        if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
     i range(Q) range Q s,t=MI() s MI() MI t s-=1 s 1 t-=1 t 1 ans=d2[s][t] ans d2[s][t] [s] d2 s t if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
     ans>=inf ans inf print(-1) print -1 print(ans-1) print ans-1 ans 1 main() main def main():
    mod=10**9+7
    N,M,L=MI()
    inf=10**15
    d=[[inf]*N for _ in range(N)]
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        if c<=L:
            d[a][b]=c
            d[b][a]=c
        
    for i in range(N):
        d[i][i]=0
        
    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])
                
    d2=[[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
    Q=I()
    for i in range(Q):
        s,t=MI()
        s-=1
        t-=1
        ans=d2[s][t]
        if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
     def main():
    mod=10**9+7
    N,M,L=MI()
    inf=10**15
    d=[[inf]*N for _ in range(N)]
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        if c<=L:
            d[a][b]=c
            d[b][a]=c
        
    for i in range(N):
        d[i][i]=0
        
    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])
                
    d2=[[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
    Q=I()
    for i in range(Q):
        s,t=MI()
        s-=1
        t-=1
        ans=d2[s][t]
        if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
     main def I(): return int(input()) def I(): return int(input()) I def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI input = sys.stdin.readline sys.stdin.readline input def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M,L=MI()
    inf=10**15
    d=[[inf]*N for _ in range(N)]
    for i in range(M):
        a,b,c=MI()
        a-=1
        b-=1
        if c<=L:
            d[a][b]=c
            d[b][a]=c
        
    for i in range(N):
        d[i][i]=0
        
    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])
                
    d2=[[inf]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d2[i][j]=1
                
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j])
                
    Q=I()
    for i in range(Q):
        s,t=MI()
        s-=1
        t-=1
        ans=d2[s][t]
        if ans>=inf:
            print(-1)
        else:
            print(ans-1)
                
    

main()
