n,m,l=map(int,input().split())
g=[[999999999999 if i!=j else 0 for j in range(n)] for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    if c>l:
        continue
    g[a][b]=c
    g[b][a]=c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j]

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

for k in range(n):
    for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j]

for i in range(int(input())):
    s,t=map(int,input().split())
    s-=1
    t-=1
    print(g[s][t]-1 if g[s][t]-1<99999999999 else -1)
 n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [999999999999 if i!=j else 0 for j in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [999999999999 if i!=j else 0 for j in range(n)] g=[[999999999999 if i!=j else 0 for j in range(n)] for i in range(n)] g [[999999999999 if i!=j else 0 for j in range(n)] for i in range(n)] for i in range(m):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    if c>l:
        continue
    g[a][b]=c
    g[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,b=a-1,b-1 a a-1 a 1 b b-1 b 1 if c>l:
        continue
     c>l c l continue 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):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] k range(n) range n for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] i range(n) range n for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] j range(n) range n if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] g[i][j]>g[i][k]+g[k][j] 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 g[i][j] = g[i][k]+g[k][j] 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 for i in range(n):
    for j in range(n):
        if g[i][j]<=l:
            g[i][j]=1 i range(n) range n for j in range(n):
        if g[i][j]<=l:
            g[i][j]=1 j range(n) range n if g[i][j]<=l:
            g[i][j]=1 g[i][j]<=l g[i][j] [i] g i j l g[i][j]=1 g[i][j] [i] g i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] k range(n) range n for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] i range(n) range n for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] j range(n) range n if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j] g[i][j]>g[i][k]+g[k][j] 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 g[i][j] = g[i][k]+g[k][j] 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 for i in range(int(input())):
    s,t=map(int,input().split())
    s-=1
    t-=1
    print(g[s][t]-1 if g[s][t]-1<99999999999 else -1) i range(int(input())) range int(input()) int input() input 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(g[s][t]-1 if g[s][t]-1<99999999999 else -1) print g[s][t]-1 if g[s][t]-1<99999999999 else -1 g[s][t]-1<99999999999 g[s][t]-1 g[s][t] [s] g s t 1 99999999999 g[s][t]-1 g[s][t] [s] g s t 1 -1 l=map(int,input().split()) map(int,input().split()) l n,m,l=map(int,input().split()) map(int,input().split()) n c=map(int,input().split()) map(int,input().split()) c t-=1 1 t s-=1 1 s a,b=a-1,b-1 a-1 a b,c=map(int,input().split()) map(int,input().split()) b m,l=map(int,input().split()) map(int,input().split()) m g=[[999999999999 if i!=j else 0 for j in range(n)] for i in range(n)] [[999999999999 if i!=j else 0 for j in range(n)] for i in range(n)] g s,t=map(int,input().split()) map(int,input().split()) s b=a-1,b-1 b-1 b t=map(int,input().split()) map(int,input().split()) t a,b,c=map(int,input().split()) map(int,input().split()) a
n,m,l=map(int,input().split())
g=[[999999999999 if i!=j else 0 for j in range(n)] for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    if c>l:
        continue
    g[a][b]=c
    g[b][a]=c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j]

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

for k in range(n):
    for i in range(n):
        for j in range(n):
            if g[i][j]>g[i][k]+g[k][j]:
                g[i][j] = g[i][k]+g[k][j]

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

