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

def warshall_floyd(d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
    return d

G = [[inf] * n for _ in range(n)] #重み付きグラフ
for i in range(n):
    G[i][i] = 0
for _ in range(m):
    a,b,c = map(int,input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c

G = warshall_floyd(G)
P = [[0] * n for _ in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            P[i][j] = 0
        elif G[i][j] <= l:
            P[i][j] = 1
        else:
            P[i][j] = inf

p = warshall_floyd(P)
q = int(input())

for _ in range(q):
    s,t = map(int,input().split())
    ans = p[s-1][t-1]-1
    print(ans if ans <= 10**9 else -1) inf = 10**10 inf 10**10 10 10 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):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
    return d warshall_floyd for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
     i range(n) range n for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
     j range(n) range n for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
     k range(n) range n d[j][k] = min(d[j][k],d[j][i]+d[i][k]) d[j][k] [j] d j k min(d[j][k],d[j][i]+d[i][k]) min d[j][k] [j] d j k d[j][i]+d[i][k] d[j][i] [j] d j i d[i][k] [i] d i k return d d d d [inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf] * n [inf] inf n G = [[inf] * n for _ in range(n)] G [[inf] * n for _ in range(n)] for i in range(n):
    G[i][i] = 0 i range(n) range n G[i][i] = 0 G[i][i] [i] G i i 0 for _ in range(m):
    a,b,c = map(int,input().split())
    G[a-1][b-1] = c
    G[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 G[a-1][b-1] = c G[a-1][b-1] [a-1] G a-1 a 1 b-1 b 1 c G[b-1][a-1] = c G[b-1][a-1] [b-1] G b-1 b 1 a-1 a 1 c G = warshall_floyd(G) G warshall_floyd(G) warshall_floyd G [0] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0] * n [0] 0 n P = [[0] * n for _ in range(n)] P [[0] * n for _ in range(n)] for i in range(n):
    for j in range(n):
        if i == j:
            P[i][j] = 0
        elif G[i][j] <= l:
            P[i][j] = 1
        else:
            P[i][j] = inf i range(n) range n for j in range(n):
        if i == j:
            P[i][j] = 0
        elif G[i][j] <= l:
            P[i][j] = 1
        else:
            P[i][j] = inf j range(n) range n if i == j:
            P[i][j] = 0
        elif G[i][j] <= l:
            P[i][j] = 1
        else:
            P[i][j] = inf i == j i j P[i][j] = 0 P[i][j] [i] P i j 0 elif G[i][j] <= l:
            P[i][j] = 1
         G[i][j] <= l G[i][j] [i] G i j l P[i][j] = 1 P[i][j] [i] P i j 1 P[i][j] = inf P[i][j] [i] P i j inf p = warshall_floyd(P) p warshall_floyd(P) warshall_floyd P q = int(input()) q int(input()) int input() input for _ in range(q):
    s,t = map(int,input().split())
    ans = p[s-1][t-1]-1
    print(ans if ans <= 10**9 else -1) _ range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t ans = p[s-1][t-1]-1 ans p[s-1][t-1]-1 p[s-1][t-1] [s-1] p s-1 s 1 t-1 t 1 1 print(ans if ans <= 10**9 else -1) print ans if ans <= 10**9 else -1 ans <= 10**9 ans 10**9 10 9 ans -1 n,m,l = map(int,input().split()) map(int,input().split()) n m,l = map(int,input().split()) map(int,input().split()) m q = int(input()) int(input()) q t = map(int,input().split()) map(int,input().split()) t l = map(int,input().split()) map(int,input().split()) l G = [[inf] * n for _ in range(n)] [[inf] * n for _ in range(n)] G ans = p[s-1][t-1]-1 p[s-1][t-1]-1 ans a,b,c = map(int,input().split()) map(int,input().split()) a G = warshall_floyd(G) warshall_floyd(G) G def warshall_floyd(d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
    return d def warshall_floyd(d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
    return d warshall_floyd p = warshall_floyd(P) warshall_floyd(P) p inf = 10**10 10**10 inf b,c = map(int,input().split()) map(int,input().split()) b s,t = map(int,input().split()) map(int,input().split()) s c = map(int,input().split()) map(int,input().split()) c P = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] P
inf = 10**10
n,m,l = map(int,input().split())

def warshall_floyd(d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k],d[j][i]+d[i][k])
    return d

G = [[inf] * n for _ in range(n)] #重み付きグラフ
for i in range(n):
    G[i][i] = 0
for _ in range(m):
    a,b,c = map(int,input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c

G = warshall_floyd(G)
P = [[0] * n for _ in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            P[i][j] = 0
        elif G[i][j] <= l:
            P[i][j] = 1
        else:
            P[i][j] = inf

p = warshall_floyd(P)
q = int(input())

for _ in range(q):
    s,t = map(int,input().split())
    ans = p[s-1][t-1]-1
    print(ans if ans <= 10**9 else -1)