def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist

n,m,l = map(int,input().split())
inf = 10**18
dist = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    dist[i][i] = 0

for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    if c <= l:
        dist[a][b] = c
        dist[b][a] = c

dist = Warshall_Floyd(dist,n)
route = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1

route = Warshall_Floyd(route,n)

q = int(input())


for i in range(q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    print(route[s][t]-1 if route[s][t] < inf else -1) def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist Warshall_Floyd [j for j in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [j for j in range(n)] next_point = [[j for j in range(n)] for _ in range(n)] next_point [[j for j in range(n)] for _ in range(n)] for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
     i range(n) range n for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
     j range(n) range n for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
     k range(n) range n if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
     dist[j][k] > dist[j][i] + dist[i][k] dist[j][k] [j] dist j k dist[j][i] + dist[i][k] dist[j][i] [j] dist j i dist[i][k] [i] dist i k next_point[j][k] = next_point[j][i] next_point[j][k] [j] next_point j k next_point[j][i] [j] next_point j i dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) dist[j][k] [j] dist j k min(dist[j][k], dist[j][i] + dist[i][k]) min dist[j][k] [j] dist j k dist[j][i] + dist[i][k] dist[j][i] [j] dist j i dist[i][k] [i] dist i k if restoration:
        return dist,next_point
    else:
        return dist restoration return dist,next_point return dist,next_point dist next_point return dist dist dist dist n n restoration=False restoration False n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l inf = 10**18 inf 10**18 10 18 [inf for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [inf for i in range(n)] dist = [[inf for i in range(n)] for j in range(n)] dist [[inf for i in range(n)] for j in range(n)] for i in range(n):
    dist[i][i] = 0 i range(n) range n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    if c <= l:
        dist[a][b] = c
        dist[b][a] = 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 a -= 1 a 1 b -= 1 b 1 if c <= l:
        dist[a][b] = c
        dist[b][a] = c c <= l c l dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c dist = Warshall_Floyd(dist,n) dist Warshall_Floyd(dist,n) Warshall_Floyd dist n [inf for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [inf for i in range(n)] route = [[inf for i in range(n)] for j in range(n)] route [[inf for i in range(n)] for j in range(n)] for i in range(n):
    for j in range(n):
        if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1 i range(n) range n for j in range(n):
        if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1 j range(n) range n if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1 i == j i j route[i][j] = 0 route[i][j] [i] route i j 0 elif dist[i][j] <= l:
            route[i][j] = 1 dist[i][j] <= l dist[i][j] [i] dist i j l route[i][j] = 1 route[i][j] [i] route i j 1 route = Warshall_Floyd(route,n) route Warshall_Floyd(route,n) Warshall_Floyd route n 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(route[s][t]-1 if route[s][t] < inf 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(route[s][t]-1 if route[s][t] < inf else -1) print route[s][t]-1 if route[s][t] < inf else -1 route[s][t] < inf route[s][t] [s] route s t inf route[s][t]-1 route[s][t] [s] route s t 1 -1 b,c = map(int,input().split()) map(int,input().split()) b a -= 1 1 a dist = Warshall_Floyd(dist,n) Warshall_Floyd(dist,n) dist a,b,c = map(int,input().split()) map(int,input().split()) a m,l = map(int,input().split()) map(int,input().split()) m t = map(int,input().split()) map(int,input().split()) t route = [[inf for i in range(n)] for j in range(n)] [[inf for i in range(n)] for j in range(n)] route q = int(input()) int(input()) q s -= 1 1 s s,t = map(int,input().split()) map(int,input().split()) s def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist Warshall_Floyd route = Warshall_Floyd(route,n) Warshall_Floyd(route,n) route inf = 10**18 10**18 inf n,m,l = map(int,input().split()) map(int,input().split()) n t -= 1 1 t l = map(int,input().split()) map(int,input().split()) l dist = [[inf for i in range(n)] for j in range(n)] [[inf for i in range(n)] for j in range(n)] dist c = map(int,input().split()) map(int,input().split()) c b -= 1 1 b
def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist

n,m,l = map(int,input().split())
inf = 10**18
dist = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    dist[i][i] = 0

for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    if c <= l:
        dist[a][b] = c
        dist[b][a] = c

dist = Warshall_Floyd(dist,n)
route = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1

route = Warshall_Floyd(route,n)

q = int(input())


for i in range(q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    print(route[s][t]-1 if route[s][t] < inf else -1)