def warshall_floid(d):
    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())
d = [[10**13]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1) def warshall_floid(d):
    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 warshall_floid 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 d d n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [10**13]*(n+1) for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [10**13]*(n+1) [10**13] 10**13 10 13 n+1 n 1 d = [[10**13]*(n+1) for i in range(n+1)] d [[10**13]*(n+1) for i in range(n+1)] for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = 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 d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c for i in range(1,n+1):
    d[i][i] = 0 i range(1,n+1) range 1 n+1 n 1 d[i][i] = 0 d[i][i] [i] d i i 0 d = warshall_floid(d) d warshall_floid(d) warshall_floid d for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13 i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13 j range(1,n+1) range 1 n+1 n 1 if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13 d[i][j] <= l d[i][j] [i] d i j l d[i][j] = 1 d[i][j] [i] d i j 1 d[i][j] = 10**13 d[i][j] [i] d i j 10**13 10 13 d = warshall_floid(d) d warshall_floid(d) warshall_floid d q = int(input()) q int(input()) int input() input for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1) i range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1) d[s][t] >= 10**13 d[s][t] [s] d s t 10**13 10 13 print(-1) print -1 print(d[s][t]-1) print d[s][t]-1 d[s][t] [s] d s t 1 l = map(int,input().split()) map(int,input().split()) l d = warshall_floid(d) warshall_floid(d) d c = map(int,input().split()) map(int,input().split()) c t = map(int,input().split()) map(int,input().split()) t m,l = map(int,input().split()) map(int,input().split()) m def warshall_floid(d):
    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 warshall_floid(d):
    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 warshall_floid q = int(input()) int(input()) q b,c = map(int,input().split()) map(int,input().split()) b s,t = map(int,input().split()) map(int,input().split()) s a,b,c = map(int,input().split()) map(int,input().split()) a d = [[10**13]*(n+1) for i in range(n+1)] [[10**13]*(n+1) for i in range(n+1)] d d = warshall_floid(d) warshall_floid(d) d n,m,l = map(int,input().split()) map(int,input().split()) n
def warshall_floid(d):
    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())
d = [[10**13]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1)
