n,m,l = map(int,input().split())
g = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    a-=1
    b-=1
    g[a][b] = c
    g[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j],g[i][k] + g[k][j])
h = [[float('inf')]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j]<=l:
            h[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j],h[i][k] + h[k][j])
Q = int(input())
for _ in range(Q):
    s,t = map(int,input().split())
    s -=1
    t-=1
    if h[s][t] ==float('inf'):
        print(-1)
    else:
        print(h[s][t]-1) n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [float('inf')]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')]*n [float('inf')] float('inf') float 'inf' n g = [[float('inf')]*n for _ in range(n)] g [[float('inf')]*n for _ in range(n)] for _ in range(m):
    a,b,c = map(int,input().split())
    a-=1
    b-=1
    g[a][b] = c
    g[b][a] = 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 a-=1 a 1 b-=1 b 1 g[a][b] = c g[a][b] [a] g a b c g[b][a] = c g[b][a] [b] g b a c for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j],g[i][k] + g[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j],g[i][k] + g[k][j]) i range(n) range n for j in range(n):
            g[i][j] = min(g[i][j],g[i][k] + g[k][j]) j range(n) range n g[i][j] = min(g[i][j],g[i][k] + g[k][j]) g[i][j] [i] g i j min(g[i][j],g[i][k] + g[k][j]) min g[i][j] [i] g i j g[i][k] + g[k][j] g[i][k] [i] g i k g[k][j] [k] g k j [float('inf')]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf')]*n [float('inf')] float('inf') float 'inf' n h = [[float('inf')]*n for _ in range(n)] h [[float('inf')]*n for _ in range(n)] for i in range(n):
    for j in range(n):
        if g[i][j]<=l:
            h[i][j] = 1 i range(n) range n for j in range(n):
        if g[i][j]<=l:
            h[i][j] = 1 j range(n) range n if g[i][j]<=l:
            h[i][j] = 1 g[i][j]<=l g[i][j] [i] g i j l h[i][j] = 1 h[i][j] [i] h i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j],h[i][k] + h[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j],h[i][k] + h[k][j]) i range(n) range n for j in range(n):
            h[i][j] = min(h[i][j],h[i][k] + h[k][j]) j range(n) range n h[i][j] = min(h[i][j],h[i][k] + h[k][j]) h[i][j] [i] h i j min(h[i][j],h[i][k] + h[k][j]) min h[i][j] [i] h i j h[i][k] + h[k][j] h[i][k] [i] h i k h[k][j] [k] h k j Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s,t = map(int,input().split())
    s -=1
    t-=1
    if h[s][t] ==float('inf'):
        print(-1)
    else:
        print(h[s][t]-1) _ 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 if h[s][t] ==float('inf'):
        print(-1)
    else:
        print(h[s][t]-1) h[s][t] ==float('inf') h[s][t] [s] h s t float('inf') float 'inf' print(-1) print -1 print(h[s][t]-1) print h[s][t]-1 h[s][t] [s] h s t 1 b,c = map(int,input().split()) map(int,input().split()) b h = [[float('inf')]*n for _ in range(n)] [[float('inf')]*n for _ in range(n)] h s -=1 1 s a-=1 1 a t-=1 1 t n,m,l = map(int,input().split()) map(int,input().split()) n m,l = map(int,input().split()) map(int,input().split()) m t = map(int,input().split()) map(int,input().split()) t l = map(int,input().split()) map(int,input().split()) l b-=1 1 b s,t = map(int,input().split()) map(int,input().split()) s a,b,c = map(int,input().split()) map(int,input().split()) a c = map(int,input().split()) map(int,input().split()) c g = [[float('inf')]*n for _ in range(n)] [[float('inf')]*n for _ in range(n)] g Q = int(input()) int(input()) Q
n,m,l = map(int,input().split())
g = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    a-=1
    b-=1
    g[a][b] = c
    g[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j],g[i][k] + g[k][j])
h = [[float('inf')]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j]<=l:
            h[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            h[i][j] = min(h[i][j],h[i][k] + h[k][j])
Q = int(input())
for _ in range(Q):
    s,t = map(int,input().split())
    s -=1
    t-=1
    if h[s][t] ==float('inf'):
        print(-1)
    else:
        print(h[s][t]-1)
