INFTY = 10**12
def wf(H):
    d = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        d[i][i] = 0
        if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
    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
N,M,L = map(int,input().split())
G = {}
for _ in range(M):
    A,B,C = map(int,input().split())
    if A not in G:
        G[A] = []
    G[A].append((B,C))
    if B not in G:
        G[B] = []
    G[B].append((A,C))
d1 = wf(G)
F = {}
for i in range(1,N):
    for j in range(i+1,N+1):
        if d1[i][j]<=L:
            if i not in F:
                F[i] = []
            F[i].append((j,1))
            if j not in F:
                F[j] = []
            F[j].append((i,1))
d2 = wf(F)
Q = int(input())
for _ in range(Q):
    s,t = map(int,input().split())
    if d2[s][t]<INFTY:
        print(d2[s][t]-1)
    else:
        print(-1) INFTY = 10**12 INFTY 10**12 10 12 def wf(H):
    d = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        d[i][i] = 0
        if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
    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 wf [INFTY for _ in range(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) [INFTY for _ in range(N+1)] d = [[INFTY for _ in range(N+1)] for _ in range(N+1)] d [[INFTY for _ in range(N+1)] for _ in range(N+1)] for i in range(1,N+1):
        d[i][i] = 0
        if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
     i range(1,N+1) range 1 N+1 N 1 d[i][i] = 0 d[i][i] [i] d i i 0 if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
     i in H i H for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
     x H[i] H i j,c = x[0],x[1] j x[0] x 0 c x[1] x 1 d[i][j] = c d[i][j] [i] d i j c 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 H H N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L G = {} G {} for _ in range(M):
    A,B,C = map(int,input().split())
    if A not in G:
        G[A] = []
    G[A].append((B,C))
    if B not in G:
        G[B] = []
    G[B].append((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 if A not in G:
        G[A] = []
     A not in G A G G[A] = [] G[A] G A [] G[A].append((B,C)) [A].append [A] G A append (B,C) B C if B not in G:
        G[B] = []
     B not in G B G G[B] = [] G[B] G B [] G[B].append((A,C)) [B].append [B] G B append (A,C) A C d1 = wf(G) d1 wf(G) wf G F = {} F {} for i in range(1,N):
    for j in range(i+1,N+1):
        if d1[i][j]<=L:
            if i not in F:
                F[i] = []
            F[i].append((j,1))
            if j not in F:
                F[j] = []
            F[j].append((i,1)) i range(1,N) range 1 N for j in range(i+1,N+1):
        if d1[i][j]<=L:
            if i not in F:
                F[i] = []
            F[i].append((j,1))
            if j not in F:
                F[j] = []
            F[j].append((i,1)) j range(i+1,N+1) range i+1 i 1 N+1 N 1 if d1[i][j]<=L:
            if i not in F:
                F[i] = []
            F[i].append((j,1))
            if j not in F:
                F[j] = []
            F[j].append((i,1)) d1[i][j]<=L d1[i][j] [i] d1 i j L if i not in F:
                F[i] = []
             i not in F i F F[i] = [] F[i] F i [] F[i].append((j,1)) [i].append [i] F i append (j,1) j 1 if j not in F:
                F[j] = []
             j not in F j F F[j] = [] F[j] F j [] F[j].append((i,1)) [j].append [j] F j append (i,1) i 1 d2 = wf(F) d2 wf(F) wf F Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s,t = map(int,input().split())
    if d2[s][t]<INFTY:
        print(d2[s][t]-1)
    else:
        print(-1) _ range(Q) range Q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if d2[s][t]<INFTY:
        print(d2[s][t]-1)
    else:
        print(-1) d2[s][t]<INFTY d2[s][t] [s] d2 s t INFTY print(d2[s][t]-1) print d2[s][t]-1 d2[s][t] [s] d2 s t 1 print(-1) print -1 F = {} {} F def wf(H):
    d = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        d[i][i] = 0
        if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
    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 wf(H):
    d = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        d[i][i] = 0
        if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
    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 wf M,L = map(int,input().split()) map(int,input().split()) M G = {} {} G L = map(int,input().split()) map(int,input().split()) L d1 = wf(G) wf(G) d1 Q = int(input()) int(input()) Q s,t = map(int,input().split()) map(int,input().split()) s t = map(int,input().split()) map(int,input().split()) t N,M,L = map(int,input().split()) map(int,input().split()) N C = map(int,input().split()) map(int,input().split()) C A,B,C = map(int,input().split()) map(int,input().split()) A d2 = wf(F) wf(F) d2 B,C = map(int,input().split()) map(int,input().split()) B INFTY = 10**12 10**12 INFTY
INFTY = 10**12
def wf(H):
    d = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        d[i][i] = 0
        if i in H:
            for x in H[i]:
                j,c = x[0],x[1]
                d[i][j] = c
    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
N,M,L = map(int,input().split())
G = {}
for _ in range(M):
    A,B,C = map(int,input().split())
    if A not in G:
        G[A] = []
    G[A].append((B,C))
    if B not in G:
        G[B] = []
    G[B].append((A,C))
d1 = wf(G)
F = {}
for i in range(1,N):
    for j in range(i+1,N+1):
        if d1[i][j]<=L:
            if i not in F:
                F[i] = []
            F[i].append((j,1))
            if j not in F:
                F[j] = []
            F[j].append((i,1))
d2 = wf(F)
Q = int(input())
for _ in range(Q):
    s,t = map(int,input().split())
    if d2[s][t]<INFTY:
        print(d2[s][t]-1)
    else:
        print(-1)
