INF = 10**12

def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


def main():

    n,m,l = map(int, input().split())
    d = [ [INF]*(n) for _ in range(n) ]
    for _ in range(m):
        a,b,c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    warshall_floyd(d, n)

    d2 = [ [INF]*(n) for _ in range(n) ]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                d2[i][j] = 1

    warshall_floyd(d2,n)
    ans = []
    q = int(input())
    for _ in range(q):
        s,t = map(int, input().split())
        dist = d2[s-1][t-1]
        if dist == INF: dist = 0
        ans.append(dist-1)

    for a in ans:
        print(a)

if __name__ == "__main__":
    main() INF = 10**12 INF 10**12 10 12 def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d warshall_floyd for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     i range(n) range n for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
     j range(n) range n 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 d d n n def main():

    n,m,l = map(int, input().split())
    d = [ [INF]*(n) for _ in range(n) ]
    for _ in range(m):
        a,b,c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    warshall_floyd(d, n)

    d2 = [ [INF]*(n) for _ in range(n) ]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                d2[i][j] = 1

    warshall_floyd(d2,n)
    ans = []
    q = int(input())
    for _ in range(q):
        s,t = map(int, input().split())
        dist = d2[s-1][t-1]
        if dist == INF: dist = 0
        ans.append(dist-1)

    for a in ans:
        print(a) main n,m,l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [INF]*(n) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF]*(n) [INF] INF n d = [ [INF]*(n) for _ in range(n) ] d [ [INF]*(n) for _ in range(n) ] for _ in range(m):
        a,b,c = map(int, input().split())
        d[a-1][b-1] = c
        d[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 d[a-1][b-1] = c d[a-1][b-1] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1] = c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 c warshall_floyd(d, n) warshall_floyd d n [INF]*(n) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF]*(n) [INF] INF n d2 = [ [INF]*(n) for _ in range(n) ] d2 [ [INF]*(n) for _ in range(n) ] for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                d2[i][j] = 1

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

     j range(n) range n if d[i][j] <= l:
                d2[i][j] = 1

     d[i][j] <= l d[i][j] [i] d i j l d2[i][j] = 1 d2[i][j] [i] d2 i j 1 warshall_floyd(d2,n) warshall_floyd d2 n ans = [] ans [] q = int(input()) q int(input()) int input() input for _ in range(q):
        s,t = map(int, input().split())
        dist = d2[s-1][t-1]
        if dist == INF: dist = 0
        ans.append(dist-1)

     _ range(q) range q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t dist = d2[s-1][t-1] dist d2[s-1][t-1] [s-1] d2 s-1 s 1 t-1 t 1 if dist == INF: dist = 0
         dist == INF dist INF ans.append(dist-1) ans.append ans append dist-1 dist 1 for a in ans:
        print(a) a ans print(a) print a if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main INF = 10**12 10**12 INF def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d warshall_floyd def main():

    n,m,l = map(int, input().split())
    d = [ [INF]*(n) for _ in range(n) ]
    for _ in range(m):
        a,b,c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    warshall_floyd(d, n)

    d2 = [ [INF]*(n) for _ in range(n) ]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                d2[i][j] = 1

    warshall_floyd(d2,n)
    ans = []
    q = int(input())
    for _ in range(q):
        s,t = map(int, input().split())
        dist = d2[s-1][t-1]
        if dist == INF: dist = 0
        ans.append(dist-1)

    for a in ans:
        print(a) def main():

    n,m,l = map(int, input().split())
    d = [ [INF]*(n) for _ in range(n) ]
    for _ in range(m):
        a,b,c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    warshall_floyd(d, n)

    d2 = [ [INF]*(n) for _ in range(n) ]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                d2[i][j] = 1

    warshall_floyd(d2,n)
    ans = []
    q = int(input())
    for _ in range(q):
        s,t = map(int, input().split())
        dist = d2[s-1][t-1]
        if dist == INF: dist = 0
        ans.append(dist-1)

    for a in ans:
        print(a) main
INF = 10**12

def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


def main():

    n,m,l = map(int, input().split())
    d = [ [INF]*(n) for _ in range(n) ]
    for _ in range(m):
        a,b,c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    warshall_floyd(d, n)

    d2 = [ [INF]*(n) for _ in range(n) ]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                d2[i][j] = 1

    warshall_floyd(d2,n)
    ans = []
    q = int(input())
    for _ in range(q):
        s,t = map(int, input().split())
        dist = d2[s-1][t-1]
        if dist == INF: dist = 0
        ans.append(dist-1)

    for a in ans:
        print(a)

if __name__ == "__main__":
    main()