import sys
input = sys.stdin.readline

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

# ワーシャルフロイド
def warshall_floyd(d,n):
    #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

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue
def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d

d = make_d_matrix(n,m)
d = warshall_floyd(d,n)

inf = 10**3
for i in range(n):
    for j in range(n):
        d[i][j] = 1 if (d[i][j] <= l) else inf

d = warshall_floyd(d,n)

q = int(input())

for _ in range(q):
    s,t = map(int, input().split())
    tmp = d[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(tmp-1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l def warshall_floyd(d,n):
    #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

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue 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 n def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d make_d_matrix inf = 10**13 inf 10**13 10 13 [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)] if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
     directed for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-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 d[a-1][b-1] = c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c for _ in range(m):
            a,b,c = map(int, input().split())
            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 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 return d d n n m m directed=False directed False d = make_d_matrix(n,m) d make_d_matrix(n,m) make_d_matrix n m d = warshall_floyd(d,n) d warshall_floyd(d,n) warshall_floyd d n inf = 10**3 inf 10**3 10 3 for i in range(n):
    for j in range(n):
        d[i][j] = 1 if (d[i][j] <= l) else inf i range(n) range n for j in range(n):
        d[i][j] = 1 if (d[i][j] <= l) else inf j range(n) range n d[i][j] = 1 if (d[i][j] <= l) else inf d[i][j] [i] d i j 1 if (d[i][j] <= l) else inf d[i][j] <= l d[i][j] [i] d i j l 1 inf d = warshall_floyd(d,n) d warshall_floyd(d,n) warshall_floyd d n q = int(input()) q int(input()) int input() input for _ in range(q):
    s,t = map(int, input().split())
    tmp = d[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(tmp-1) _ range(q) range q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t tmp = d[s-1][t-1] tmp d[s-1][t-1] [s-1] d s-1 s 1 t-1 t 1 if(tmp >= inf):
        print(-1)
    else:
        print(tmp-1) tmp >= inf tmp inf print(-1) print -1 print(tmp-1) print tmp-1 tmp 1 l = map(int,input().split()) map(int,input().split()) l d = warshall_floyd(d,n) warshall_floyd(d,n) d n,m,l = map(int,input().split()) map(int,input().split()) n tmp = d[s-1][t-1] d[s-1][t-1] tmp s,t = map(int, input().split()) map(int, input().split()) s d = make_d_matrix(n,m) make_d_matrix(n,m) d input = sys.stdin.readline sys.stdin.readline input m,l = map(int,input().split()) map(int,input().split()) m def warshall_floyd(d,n):
    #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

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue def warshall_floyd(d,n):
    #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

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue warshall_floyd def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d make_d_matrix inf = 10**3 10**3 inf q = int(input()) int(input()) q d = warshall_floyd(d,n) warshall_floyd(d,n) d t = map(int, input().split()) map(int, input().split()) t
import sys
input = sys.stdin.readline

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

# ワーシャルフロイド
def warshall_floyd(d,n):
    #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

# m行の入力から距離を値に持つ隣接行列を作成 0-indexed
# directed:無向グラフならFalse、有向グラフならTrue
def make_d_matrix(n,m,directed=False):
    inf = 10**13
    d = [[inf] * n for _ in range(n)]
    if(directed):
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
    else:
        for _ in range(m):
            a,b,c = map(int, input().split())
            d[a-1][b-1] = c
            d[b-1][a-1] = c
    return d

d = make_d_matrix(n,m)
d = warshall_floyd(d,n)

inf = 10**3
for i in range(n):
    for j in range(n):
        d[i][j] = 1 if (d[i][j] <= l) else inf

d = warshall_floyd(d,n)

q = int(input())

for _ in range(q):
    s,t = map(int, input().split())
    tmp = d[s-1][t-1]
    if(tmp >= inf):
        print(-1)
    else:
        print(tmp-1)