import sys
input = sys.stdin.readline

n,m,l = map(int,input().split())
town = [list(map(int,input().split())) for _ in range(m)]
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]

inf = (l+1)*n
d = [[inf]*n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for a,b,c in town:
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
    
def warshall_floyd(d,n):
    for k in range(n):
        for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])

warshall_floyd(d,n)

d2 = [None]*n
for i,row in enumerate(d):
    d2[i] = [1 if val<=l else inf for val in row]
    d2[i][i] = 0

warshall_floyd(d2,n)
 
for s,t in query:
    s -= 1
    t -= 1
    count = (d2[s][t]%inf)-1
    print(count) 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 list(map(int,input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split town = [list(map(int,input().split())) for _ in range(m)] town [list(map(int,input().split())) for _ in range(m)] q = int(input()) q int(input()) int input() input list(map(int,input().split())) for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split query = [list(map(int,input().split())) for _ in range(q)] query [list(map(int,input().split())) for _ in range(q)] inf = (l+1)*n inf (l+1)*n l+1 l 1 n [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 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 a,b,c in town:
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
     a b c town a -= 1 a 1 b -= 1 b 1 d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c def warshall_floyd(d,n):
    for k in range(n):
        for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]) warshall_floyd for k in range(n):
        for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]) k range(n) range n for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]) j range(n) range n for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]) i 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 d d n n warshall_floyd(d,n) warshall_floyd d n d2 = [None]*n d2 [None]*n [None] None n for i,row in enumerate(d):
    d2[i] = [1 if val<=l else inf for val in row]
    d2[i][i] = 0 i row enumerate(d) enumerate d 1 if val<=l else inf for val in row for val in row val row for val in row 1 if val<=l else inf val<=l val l 1 inf d2[i] = [1 if val<=l else inf for val in row] d2[i] d2 i [1 if val<=l else inf for val in row] d2[i][i] = 0 d2[i][i] [i] d2 i i 0 warshall_floyd(d2,n) warshall_floyd d2 n for s,t in query:
    s -= 1
    t -= 1
    count = (d2[s][t]%inf)-1
    print(count) s t query s -= 1 s 1 t -= 1 t 1 count = (d2[s][t]%inf)-1 count (d2[s][t]%inf)-1 d2[s][t]%inf d2[s][t] [s] d2 s t inf 1 print(count) print count a -= 1 1 a t -= 1 1 t inf = (l+1)*n (l+1)*n inf m,l = map(int,input().split()) map(int,input().split()) m q = int(input()) int(input()) q input = sys.stdin.readline sys.stdin.readline input s -= 1 1 s def warshall_floyd(d,n):
    for k in range(n):
        for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]) def warshall_floyd(d,n):
    for k in range(n):
        for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]) warshall_floyd town = [list(map(int,input().split())) for _ in range(m)] [list(map(int,input().split())) for _ in range(m)] town d = [[inf]*n for _ in range(n)] [[inf]*n for _ in range(n)] d query = [list(map(int,input().split())) for _ in range(q)] [list(map(int,input().split())) for _ in range(q)] query b -= 1 1 b l = map(int,input().split()) map(int,input().split()) l n,m,l = map(int,input().split()) map(int,input().split()) n d2 = [None]*n [None]*n d2 count = (d2[s][t]%inf)-1 (d2[s][t]%inf)-1 count
import sys
input = sys.stdin.readline

n,m,l = map(int,input().split())
town = [list(map(int,input().split())) for _ in range(m)]
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]

inf = (l+1)*n
d = [[inf]*n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for a,b,c in town:
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
    
def warshall_floyd(d,n):
    for k in range(n):
        for j in range(n):
            for i in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])

warshall_floyd(d,n)

d2 = [None]*n
for i,row in enumerate(d):
    d2[i] = [1 if val<=l else inf for val in row]
    d2[i][i] = 0

warshall_floyd(d2,n)
 
for s,t in query:
    s -= 1
    t -= 1
    count = (d2[s][t]%inf)-1
    print(count)
