def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    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])
    return d


n,m,l= map(int,input().split()) #n:頂点数　w:辺の数

d=[[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
warshall_floyd(d)

d2=[[float("inf") for i in range(n)] for i in range(n)] 
for i in range(n):
    for j in range(n):
        if d[i-1][j-1]<=l:
            d2[i-1][j-1]=1
            d2[j-1][i-1]=1
warshall_floyd(d2)
q=int(input())
l=[list(map(int, input().split())) for i in range(q)]
for i in range(q):
    if d2[l[i][0]-1][l[i][1]-1]-1!=float('inf'):
        print(d2[l[i][0]-1][l[i][1]-1]-1)
    else:
        print(-1) def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    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])
    return d warshall_floyd 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 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 [float("inf") for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("inf") for i in range(n)] d=[[float("inf") for i in range(n)] for i in range(n)] d [[float("inf") for i in range(n)] for i in range(n)] for i in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c i 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 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 warshall_floyd(d) warshall_floyd d [float("inf") for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [float("inf") for i in range(n)] d2=[[float("inf") for i in range(n)] for i in range(n)] d2 [[float("inf") for i in range(n)] for i in range(n)] for i in range(n):
    for j in range(n):
        if d[i-1][j-1]<=l:
            d2[i-1][j-1]=1
            d2[j-1][i-1]=1 i range(n) range n for j in range(n):
        if d[i-1][j-1]<=l:
            d2[i-1][j-1]=1
            d2[j-1][i-1]=1 j range(n) range n if d[i-1][j-1]<=l:
            d2[i-1][j-1]=1
            d2[j-1][i-1]=1 d[i-1][j-1]<=l d[i-1][j-1] [i-1] d i-1 i 1 j-1 j 1 l d2[i-1][j-1]=1 d2[i-1][j-1] [i-1] d2 i-1 i 1 j-1 j 1 1 d2[j-1][i-1]=1 d2[j-1][i-1] [j-1] d2 j-1 j 1 i-1 i 1 1 warshall_floyd(d2) warshall_floyd d2 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 l=[list(map(int, input().split())) for i in range(q)] l [list(map(int, input().split())) for i in range(q)] for i in range(q):
    if d2[l[i][0]-1][l[i][1]-1]-1!=float('inf'):
        print(d2[l[i][0]-1][l[i][1]-1]-1)
    else:
        print(-1) i range(q) range q if d2[l[i][0]-1][l[i][1]-1]-1!=float('inf'):
        print(d2[l[i][0]-1][l[i][1]-1]-1)
    else:
        print(-1) d2[l[i][0]-1][l[i][1]-1]-1!=float('inf') d2[l[i][0]-1][l[i][1]-1]-1 d2[l[i][0]-1][l[i][1]-1] [l[i][0]-1] d2 l[i][0]-1 l[i][0] [i] l i 0 1 l[i][1]-1 l[i][1] [i] l i 1 1 1 float('inf') float 'inf' print(d2[l[i][0]-1][l[i][1]-1]-1) print d2[l[i][0]-1][l[i][1]-1]-1 d2[l[i][0]-1][l[i][1]-1] [l[i][0]-1] d2 l[i][0]-1 l[i][0] [i] l i 0 1 l[i][1]-1 l[i][1] [i] l i 1 1 1 print(-1) print -1 d=[[float("inf") for i in range(n)] for i in range(n)] [[float("inf") for i in range(n)] for i in range(n)] d q=int(input()) int(input()) q n,m,l= map(int,input().split()) map(int,input().split()) n a,b,c = map(int,input().split()) map(int,input().split()) a def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    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])
    return d def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    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])
    return d warshall_floyd l= map(int,input().split()) map(int,input().split()) l b,c = map(int,input().split()) map(int,input().split()) b d2=[[float("inf") for i in range(n)] for i in range(n)] [[float("inf") for i in range(n)] for i in range(n)] d2 l=[list(map(int, input().split())) for i in range(q)] [list(map(int, input().split())) for i in range(q)] l m,l= map(int,input().split()) map(int,input().split()) m c = map(int,input().split()) map(int,input().split()) c
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    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])
    return d


n,m,l= map(int,input().split()) #n:頂点数　w:辺の数

d=[[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
warshall_floyd(d)

d2=[[float("inf") for i in range(n)] for i in range(n)] 
for i in range(n):
    for j in range(n):
        if d[i-1][j-1]<=l:
            d2[i-1][j-1]=1
            d2[j-1][i-1]=1
warshall_floyd(d2)
q=int(input())
l=[list(map(int, input().split())) for i in range(q)]
for i in range(q):
    if d2[l[i][0]-1][l[i][1]-1]-1!=float('inf'):
        print(d2[l[i][0]-1][l[i][1]-1]-1)
    else:
        print(-1)