#juppy's code for testing run time only. 
def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    d = [[10**12]*n for _ in [0]*n]
    for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
    for i in range(n):
        d[i][i] = 0
 
    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])
 
    edge = [[10**12]*n for _ in [0]*n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
    q = int(input())
    for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
 
if __name__ == '__main__':
    main() def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    d = [[10**12]*n for _ in [0]*n]
    for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
    for i in range(n):
        d[i][i] = 0
 
    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])
 
    edge = [[10**12]*n for _ in [0]*n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
    q = int(input())
    for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
  main import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [10**12]*n for _ in [0]*n for _ in [0]*n _ [0]*n [0] 0 n for _ in [0]*n [10**12]*n [10**12] 10**12 10 12 n d = [[10**12]*n for _ in [0]*n] d [[10**12]*n for _ in [0]*n] for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = 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 if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
     l >= c l c d[a-1][b-1] = d[b-1][a-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 for i in range(n):
        d[i][i] = 0
 
     i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 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 [10**12]*n for _ in [0]*n for _ in [0]*n _ [0]*n [0] 0 n for _ in [0]*n [10**12]*n [10**12] 10**12 10 12 n edge = [[10**12]*n for _ in [0]*n] edge [[10**12]*n for _ in [0]*n] for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
     i range(n) range n for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
     j range(n) range n if d[i][j] <= l:
                edge[i][j] = 1
 
     d[i][j] <= l d[i][j] [i] d i j l edge[i][j] = 1 edge[i][j] [i] edge i j 1 for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
     k range(n) range n for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
     i range(n) range n for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
     j range(n) range n edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j]) edge[i][j] [i] edge i j min(edge[i][j],edge[i][k] + edge[k][j]) min edge[i][j] [i] edge i j edge[i][k] + edge[k][j] edge[i][k] [i] edge i k edge[k][j] [k] edge k j q = int(input()) q int(input()) int input() input for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
  _ [0]*q [0] 0 q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
  edge[s-1][t-1] >= 10**12 edge[s-1][t-1] [s-1] edge s-1 s 1 t-1 t 1 10**12 10 12 print(-1) print -1 print(edge[s-1][t-1]-1) print edge[s-1][t-1]-1 edge[s-1][t-1] [s-1] edge s-1 s 1 t-1 t 1 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    d = [[10**12]*n for _ in [0]*n]
    for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
    for i in range(n):
        d[i][i] = 0
 
    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])
 
    edge = [[10**12]*n for _ in [0]*n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
    q = int(input())
    for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
  def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    d = [[10**12]*n for _ in [0]*n]
    for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
    for i in range(n):
        d[i][i] = 0
 
    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])
 
    edge = [[10**12]*n for _ in [0]*n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
    q = int(input())
    for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
  main
#juppy's code for testing run time only. 
def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    d = [[10**12]*n for _ in [0]*n]
    for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
    for i in range(n):
        d[i][i] = 0
 
    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])
 
    edge = [[10**12]*n for _ in [0]*n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1
 
    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])
 
    q = int(input())
    for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)
 
if __name__ == '__main__':
    main()