n,m,l=map(int,input().split())
d=[[10**18]*n for i in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split())
    if c<=l:
        d[a-1][b-1]=c
        d[b-1][a-1]=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])

for i in range(n):
    for j in range(n):
        if d[i][j]<=l:
            d[i][j]=1
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])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    s-=1
    t-=1
    print(d[s][t]-1 if d[s][t]-1<999999999999999999 else -1)

 n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [10**18]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [10**18]*n [10**18] 10**18 10 18 n d=[[10**18]*n for i in range(n)] d [[10**18]*n for i in range(n)] for _ in range(m):
    a,b,c=map(int,input().split())
    if c<=l:
        d[a-1][b-1]=c
        d[b-1][a-1]=c _ range(m) range m a,b,c=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c if c<=l:
        d[a-1][b-1]=c
        d[b-1][a-1]=c c<=l c l d[a-1][b-1]=c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1]=c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 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 for i in range(n):
    for j in range(n):
        if d[i][j]<=l:
            d[i][j]=1 i range(n) range n for j in range(n):
        if d[i][j]<=l:
            d[i][j]=1 j range(n) range n if d[i][j]<=l:
            d[i][j]=1 d[i][j]<=l d[i][j] [i] d i j l d[i][j]=1 d[i][j] [i] d i j 1 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 q=int(input()) q int(input()) int input() input for i in range(q):
    s,t=map(int,input().split())
    s-=1
    t-=1
    print(d[s][t]-1 if d[s][t]-1<999999999999999999 else -1) i range(q) range q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t s-=1 s 1 t-=1 t 1 print(d[s][t]-1 if d[s][t]-1<999999999999999999 else -1) print d[s][t]-1 if d[s][t]-1<999999999999999999 else -1 d[s][t]-1<999999999999999999 d[s][t]-1 d[s][t] [s] d s t 1 999999999999999999 d[s][t]-1 d[s][t] [s] d s t 1 -1 d=[[10**18]*n for i in range(n)] [[10**18]*n for i in range(n)] d s-=1 1 s b,c=map(int,input().split()) map(int,input().split()) b t=map(int,input().split()) map(int,input().split()) t n,m,l=map(int,input().split()) map(int,input().split()) n c=map(int,input().split()) map(int,input().split()) c l=map(int,input().split()) map(int,input().split()) l t-=1 1 t m,l=map(int,input().split()) map(int,input().split()) m s,t=map(int,input().split()) map(int,input().split()) s q=int(input()) int(input()) q a,b,c=map(int,input().split()) map(int,input().split()) a
n,m,l=map(int,input().split())
d=[[10**18]*n for i in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split())
    if c<=l:
        d[a-1][b-1]=c
        d[b-1][a-1]=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])

for i in range(n):
    for j in range(n):
        if d[i][j]<=l:
            d[i][j]=1
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])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    s-=1
    t-=1
    print(d[s][t]-1 if d[s][t]-1<999999999999999999 else -1)


