#!/usr/bin/pypy
# coding: utf-8

N,M,L=map(int, raw_input().split())
RG=[[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)]

for i in xrange(M):
    f,t,c = map(int, raw_input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

for k in xrange(N):
    for i in xrange(N):
        for j in xrange(i, N):
            t = RG[i][k] + RG[k][j]
            if RG[i][j] > t:
                RG[i][j] = t
                RG[j][i] = t

FG=[[float('inf') for i in range(N)] for j in range(N)]
for i in xrange(N):
    for j in xrange(i, N):
        if RG[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

for k in xrange(N):
    for i in xrange(N):
        for j in xrange(i, N):
            t = FG[i][k] + FG[k][j]
            if FG[i][j] > t:
                FG[i][j] = t
                FG[j][i] = t

Q=int(raw_input())
for i in xrange(Q):
    s, t = map(int, raw_input().split())
    v = FG[s-1][t-1]
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1))) N,M,L=map(int, raw_input().split()) N map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split M L [ 0 if i==j else float('inf') for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [ 0 if i==j else float('inf') for i in range(N)] RG=[[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)] RG [[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)] for i in xrange(M):
    f,t,c = map(int, raw_input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c i xrange(M) xrange M f,t,c = map(int, raw_input().split()) f map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split t c if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c c <= L c L RG[f-1][t-1] = c RG[f-1][t-1] [f-1] RG f-1 f 1 t-1 t 1 c RG[t-1][f-1] = c RG[t-1][f-1] [t-1] RG t-1 t 1 f-1 f 1 c for k in xrange(N):
    for i in xrange(N):
        for j in xrange(i, N):
            t = RG[i][k] + RG[k][j]
            if RG[i][j] > t:
                RG[i][j] = t
                RG[j][i] = t k xrange(N) xrange N for i in xrange(N):
        for j in xrange(i, N):
            t = RG[i][k] + RG[k][j]
            if RG[i][j] > t:
                RG[i][j] = t
                RG[j][i] = t i xrange(N) xrange N for j in xrange(i, N):
            t = RG[i][k] + RG[k][j]
            if RG[i][j] > t:
                RG[i][j] = t
                RG[j][i] = t j xrange(i, N) xrange i N t = RG[i][k] + RG[k][j] t RG[i][k] + RG[k][j] RG[i][k] [i] RG i k RG[k][j] [k] RG k j if RG[i][j] > t:
                RG[i][j] = t
                RG[j][i] = t RG[i][j] > t RG[i][j] [i] RG i j t RG[i][j] = t RG[i][j] [i] RG i j t RG[j][i] = t RG[j][i] [j] RG j i t [float('inf') for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [float('inf') for i in range(N)] FG=[[float('inf') for i in range(N)] for j in range(N)] FG [[float('inf') for i in range(N)] for j in range(N)] for i in xrange(N):
    for j in xrange(i, N):
        if RG[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1 i xrange(N) xrange N for j in xrange(i, N):
        if RG[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1 j xrange(i, N) xrange i N if RG[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1 RG[i][j] <= L RG[i][j] [i] RG i j L FG[i][j] = 1 FG[i][j] [i] FG i j 1 FG[j][i] = 1 FG[j][i] [j] FG j i 1 for k in xrange(N):
    for i in xrange(N):
        for j in xrange(i, N):
            t = FG[i][k] + FG[k][j]
            if FG[i][j] > t:
                FG[i][j] = t
                FG[j][i] = t k xrange(N) xrange N for i in xrange(N):
        for j in xrange(i, N):
            t = FG[i][k] + FG[k][j]
            if FG[i][j] > t:
                FG[i][j] = t
                FG[j][i] = t i xrange(N) xrange N for j in xrange(i, N):
            t = FG[i][k] + FG[k][j]
            if FG[i][j] > t:
                FG[i][j] = t
                FG[j][i] = t j xrange(i, N) xrange i N t = FG[i][k] + FG[k][j] t FG[i][k] + FG[k][j] FG[i][k] [i] FG i k FG[k][j] [k] FG k j if FG[i][j] > t:
                FG[i][j] = t
                FG[j][i] = t FG[i][j] > t FG[i][j] [i] FG i j t FG[i][j] = t FG[i][j] [i] FG i j t FG[j][i] = t FG[j][i] [j] FG j i t Q=int(raw_input()) Q int(raw_input()) int raw_input() raw_input for i in xrange(Q):
    s, t = map(int, raw_input().split())
    v = FG[s-1][t-1]
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1))) i xrange(Q) xrange Q s, t = map(int, raw_input().split()) s map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split t v = FG[s-1][t-1] v FG[s-1][t-1] [s-1] FG s-1 s 1 t-1 t 1 if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1))) v == float('inf') v float('inf') float 'inf' print (str(-1)) print str(-1) str -1 print (str(int(v-1))) print str(int(v-1)) str int(v-1) int v-1 v 1 RG=[[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)] [[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)] RG c = map(int, raw_input().split()) map(int, raw_input().split()) c Q=int(raw_input()) int(raw_input()) Q s, t = map(int, raw_input().split()) map(int, raw_input().split()) s f,t,c = map(int, raw_input().split()) map(int, raw_input().split()) f M,L=map(int, raw_input().split()) map(int, raw_input().split()) M t,c = map(int, raw_input().split()) map(int, raw_input().split()) t FG=[[float('inf') for i in range(N)] for j in range(N)] [[float('inf') for i in range(N)] for j in range(N)] FG t = map(int, raw_input().split()) map(int, raw_input().split()) t v = FG[s-1][t-1] FG[s-1][t-1] v L=map(int, raw_input().split()) map(int, raw_input().split()) L t = RG[i][k] + RG[k][j] RG[i][k] + RG[k][j] t t = FG[i][k] + FG[k][j] FG[i][k] + FG[k][j] t N,M,L=map(int, raw_input().split()) map(int, raw_input().split()) N
#!/usr/bin/pypy
# coding: utf-8

N,M,L=map(int, raw_input().split())
RG=[[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)]

for i in xrange(M):
    f,t,c = map(int, raw_input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

for k in xrange(N):
    for i in xrange(N):
        for j in xrange(i, N):
            t = RG[i][k] + RG[k][j]
            if RG[i][j] > t:
                RG[i][j] = t
                RG[j][i] = t

FG=[[float('inf') for i in range(N)] for j in range(N)]
for i in xrange(N):
    for j in xrange(i, N):
        if RG[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

for k in xrange(N):
    for i in xrange(N):
        for j in xrange(i, N):
            t = FG[i][k] + FG[k][j]
            if FG[i][j] > t:
                FG[i][j] = t
                FG[j][i] = t

Q=int(raw_input())
for i in xrange(Q):
    s, t = map(int, raw_input().split())
    v = FG[s-1][t-1]
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))