#全点対間最短経路を求めるアルゴリズム

def warshall_floyd(d):
    #d[i][j]:iからjに行く最短経路
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)

n, m , l = map(int, input().split())

INF = 10 ** 11
d = [[INF]*(n+1) for _ in range(n+1)]
for i in range(m):
        x, y, z = map(int, input().split())
        if z <= l:
            d[x][y] = z
            d[y][x] = z #無向グラフならつける

for i in range(1,n+1):
    d[i][i] = 0

    

ss = warshall_floyd(d)



for i in range(1,n+1):
    for j in range(1,n+1):
        if ss[i][j] <= l:
            ss[i][j] = 1


#補給回数
vv = warshall_floyd(ss)

for i in range(1,n+1):
    for j in range(1,n+1):
        if vv[i][j] == INF:
            vv[i][j] = -1

q = int(input())
for _ in range(q):
    x, y = map(int, input().split())
    if vv[x][y] != -1:
    	print(vv[x][y]-1)
    else:
      	print(vv[x][y]) def warshall_floyd(d):
    #d[i][j]:iからjに行く最短経路
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d warshall_floyd for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     k range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     j range(1,n+1) range 1 n+1 n 1 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 import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 n, m , l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l INF = 10 ** 11 INF 10 ** 11 10 11 [INF]*(n+1) for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [INF]*(n+1) [INF] INF n+1 n 1 d = [[INF]*(n+1) for _ in range(n+1)] d [[INF]*(n+1) for _ in range(n+1)] for i in range(m):
        x, y, z = map(int, input().split())
        if z <= l:
            d[x][y] = z
            d[y][x] = z #無向グラフならつける i range(m) range m x, y, z = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y z if z <= l:
            d[x][y] = z
            d[y][x] = z #無向グラフならつける z <= l z l d[x][y] = z d[x][y] [x] d x y z d[y][x] = z d[y][x] [y] d y x z for i in range(1,n+1):
    d[i][i] = 0

     i range(1,n+1) range 1 n+1 n 1 d[i][i] = 0 d[i][i] [i] d i i 0 ss = warshall_floyd(d) ss warshall_floyd(d) warshall_floyd d for i in range(1,n+1):
    for j in range(1,n+1):
        if ss[i][j] <= l:
            ss[i][j] = 1


#補給回数 i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
        if ss[i][j] <= l:
            ss[i][j] = 1


#補給回数 j range(1,n+1) range 1 n+1 n 1 if ss[i][j] <= l:
            ss[i][j] = 1


#補給回数 ss[i][j] <= l ss[i][j] [i] ss i j l ss[i][j] = 1 ss[i][j] [i] ss i j 1 vv = warshall_floyd(ss) vv warshall_floyd(ss) warshall_floyd ss for i in range(1,n+1):
    for j in range(1,n+1):
        if vv[i][j] == INF:
            vv[i][j] = -1 i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
        if vv[i][j] == INF:
            vv[i][j] = -1 j range(1,n+1) range 1 n+1 n 1 if vv[i][j] == INF:
            vv[i][j] = -1 vv[i][j] == INF vv[i][j] [i] vv i j INF vv[i][j] = -1 vv[i][j] [i] vv i j -1 q = int(input()) q int(input()) int input() input for _ in range(q):
    x, y = map(int, input().split())
    if vv[x][y] != -1:
    	print(vv[x][y]-1)
    else:
      	print(vv[x][y]) _ range(q) range q x, y = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y if vv[x][y] != -1:
    	print(vv[x][y]-1)
    else:
      	print(vv[x][y]) vv[x][y] != -1 vv[x][y] [x] vv x y -1 print(vv[x][y]-1) print vv[x][y]-1 vv[x][y] [x] vv x y 1 print(vv[x][y]) print vv[x][y] [x] vv x y x, y = map(int, input().split()) map(int, input().split()) x y, z = map(int, input().split()) map(int, input().split()) y l = map(int, input().split()) map(int, input().split()) l x, y, z = map(int, input().split()) map(int, input().split()) x y = map(int, input().split()) map(int, input().split()) y d = [[INF]*(n+1) for _ in range(n+1)] [[INF]*(n+1) for _ in range(n+1)] d input = sys.stdin.buffer.readline sys.stdin.buffer.readline input q = int(input()) int(input()) q z = map(int, input().split()) map(int, input().split()) z m , l = map(int, input().split()) map(int, input().split()) m n, m , l = map(int, input().split()) map(int, input().split()) n def warshall_floyd(d):
    #d[i][j]:iからjに行く最短経路
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                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(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d warshall_floyd INF = 10 ** 11 10 ** 11 INF vv = warshall_floyd(ss) warshall_floyd(ss) vv ss = warshall_floyd(d) warshall_floyd(d) ss
#全点対間最短経路を求めるアルゴリズム

def warshall_floyd(d):
    #d[i][j]:iからjに行く最短経路
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)

n, m , l = map(int, input().split())

INF = 10 ** 11
d = [[INF]*(n+1) for _ in range(n+1)]
for i in range(m):
        x, y, z = map(int, input().split())
        if z <= l:
            d[x][y] = z
            d[y][x] = z #無向グラフならつける

for i in range(1,n+1):
    d[i][i] = 0

    

ss = warshall_floyd(d)



for i in range(1,n+1):
    for j in range(1,n+1):
        if ss[i][j] <= l:
            ss[i][j] = 1


#補給回数
vv = warshall_floyd(ss)

for i in range(1,n+1):
    for j in range(1,n+1):
        if vv[i][j] == INF:
            vv[i][j] = -1

q = int(input())
for _ in range(q):
    x, y = map(int, input().split())
    if vv[x][y] != -1:
    	print(vv[x][y]-1)
    else:
      	print(vv[x][y])