import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

n,m,l=map(int,input().split())
ans=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=[int(j) for j in input().split()]
    ans[a-1][b-1]=c
    ans[b-1][a-1]=c
q=int(input())
st=[]
for i in range(q):
    st.append([int(j)-1 for j in input().split()])

ans=floyd_warshall(ans)

for i in range(n):
    for j in range(n):
        if ans[i][j]<=l:
            ans[i][j]=1
        else:
            ans[i][j]=0

ans=floyd_warshall(ans)

for i,j in st:
    if ans[i][j]==float("inf"):
        print(-1)
    else:
        print(int(ans[i][j])-1)
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [0]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*n [0] 0 n ans=[[0]*n for i in range(n)] ans [[0]*n for i in range(n)] for i in range(m):
    a,b,c=[int(j) for j in input().split()]
    ans[a-1][b-1]=c
    ans[b-1][a-1]=c i range(m) range m int(j) for j in input().split() for j in input().split() j input().split() ().split () input split for j in input().split() int(j) int j a,b,c=[int(j) for j in input().split()] a [int(j) for j in input().split()] b c ans[a-1][b-1]=c ans[a-1][b-1] [a-1] ans a-1 a 1 b-1 b 1 c ans[b-1][a-1]=c ans[b-1][a-1] [b-1] ans b-1 b 1 a-1 a 1 c q=int(input()) q int(input()) int input() input st=[] st [] for i in range(q):
    st.append([int(j)-1 for j in input().split()]) i range(q) range q int(j)-1 for j in input().split() for j in input().split() j input().split() ().split () input split for j in input().split() int(j)-1 int(j) int j 1 st.append([int(j)-1 for j in input().split()]) st.append st append [int(j)-1 for j in input().split()] ans=floyd_warshall(ans) ans floyd_warshall(ans) floyd_warshall ans for i in range(n):
    for j in range(n):
        if ans[i][j]<=l:
            ans[i][j]=1
        else:
            ans[i][j]=0 i range(n) range n for j in range(n):
        if ans[i][j]<=l:
            ans[i][j]=1
        else:
            ans[i][j]=0 j range(n) range n if ans[i][j]<=l:
            ans[i][j]=1
        else:
            ans[i][j]=0 ans[i][j]<=l ans[i][j] [i] ans i j l ans[i][j]=1 ans[i][j] [i] ans i j 1 ans[i][j]=0 ans[i][j] [i] ans i j 0 ans=floyd_warshall(ans) ans floyd_warshall(ans) floyd_warshall ans for i,j in st:
    if ans[i][j]==float("inf"):
        print(-1)
    else:
        print(int(ans[i][j])-1) i j st if ans[i][j]==float("inf"):
        print(-1)
    else:
        print(int(ans[i][j])-1) ans[i][j]==float("inf") ans[i][j] [i] ans i j float("inf") float "inf" print(-1) print -1 print(int(ans[i][j])-1) print int(ans[i][j])-1 int(ans[i][j]) int ans[i][j] [i] ans i j 1 st=[] [] st ans=floyd_warshall(ans) floyd_warshall(ans) ans input = sys.stdin.readline sys.stdin.readline input m,l=map(int,input().split()) map(int,input().split()) m q=int(input()) int(input()) q ans=floyd_warshall(ans) floyd_warshall(ans) ans n,m,l=map(int,input().split()) map(int,input().split()) n ans=[[0]*n for i in range(n)] [[0]*n for i in range(n)] ans b,c=[int(j) for j in input().split()] [int(j) for j in input().split()] b l=map(int,input().split()) map(int,input().split()) l c=[int(j) for j in input().split()] [int(j) for j in input().split()] c a,b,c=[int(j) for j in input().split()] [int(j) for j in input().split()] a
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

n,m,l=map(int,input().split())
ans=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=[int(j) for j in input().split()]
    ans[a-1][b-1]=c
    ans[b-1][a-1]=c
q=int(input())
st=[]
for i in range(q):
    st.append([int(j)-1 for j in input().split()])

ans=floyd_warshall(ans)

for i in range(n):
    for j in range(n):
        if ans[i][j]<=l:
            ans[i][j]=1
        else:
            ans[i][j]=0

ans=floyd_warshall(ans)

for i,j in st:
    if ans[i][j]==float("inf"):
        print(-1)
    else:
        print(int(ans[i][j])-1)

