MOD = 10 **9 + 7
INF = 10 ** 10

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)       
if __name__ == '__main__':
    main() MOD = 10 **9 + 7 MOD 10 **9 + 7 10 **9 10 9 7 INF = 10 ** 10 INF 10 ** 10 10 10 def main():
    n,m,l = map(int,input().split())
    dist = [[INF] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)        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 dist = [[INF] * n for _ in range(n)] dist [[INF] * n for _ in range(n)] for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][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 a -= 1 a 1 b -= 1 b 1 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

     k range(n) range n for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

     i range(n) range n for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

     j range(n) range n dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j],dist[i][k] + dist[k][j]) min dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j [INF] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF] * n [INF] INF n cnt = [[INF] * n for _ in range(n)] cnt [[INF] * n for _ in range(n)] for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                cnt[i][j] = 1

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

     j range(n) range n if dist[i][j] <= l:
                cnt[i][j] = 1

     dist[i][j] <= l dist[i][j] [i] dist i j l cnt[i][j] = 1 cnt[i][j] [i] cnt i j 1 for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
     k range(n) range n for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
     i range(n) range n for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
     j range(n) range n cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j]) cnt[i][j] [i] cnt i j min(cnt[i][j],cnt[i][k] + cnt[k][j]) min cnt[i][j] [i] cnt i j cnt[i][k] + cnt[k][j] cnt[i][k] [i] cnt i k cnt[k][j] [k] cnt k j q = int(input()) q int(input()) int input() input for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)        _ range(q) range q 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(cnt[s][t] - 1 if cnt[s][t] != INF  else -1) print cnt[s][t] - 1 if cnt[s][t] != INF  else -1 cnt[s][t] != INF cnt[s][t] [s] cnt s t INF cnt[s][t] - 1 cnt[s][t] [s] cnt s t 1 -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main MOD = 10 **9 + 7 10 **9 + 7 MOD INF = 10 ** 10 10 ** 10 INF def main():
    n,m,l = map(int,input().split())
    dist = [[INF] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)        def main():
    n,m,l = map(int,input().split())
    dist = [[INF] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)        main
MOD = 10 **9 + 7
INF = 10 ** 10

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

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

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)       
if __name__ == '__main__':
    main()