def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
    return data
n,m,l=map(int,input().split())
inf=float("inf")
data=[[inf]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    data[a-1][b-1]=c
    data[b-1][a-1]=c
for i in range(n):
    data[i][i]=0
data=warshal(data)
for i in range(n):
    for j in range(n):
        if data[i][j]<=l:
            data[i][j]=1
        else:
            data[i][j]=inf
for i in range(n):
    data[i][i]=0
data=warshal(data)
q=int(input())
st=[]
for i in range(q):
    s,t=map(int,input().split())
    st.append([s-1,t-1])
for s,t in st:
    if data[s][t]==inf:
        print(-1)
    else:
        print(data[s][t]-1) def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
    return data warshal for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
     i range(n) range n for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
     j range(n) range n data[i][j]=min(data[i][j],data[i][k]+data[k][j]) data[i][j] [i] data i j min(data[i][j],data[i][k]+data[k][j]) min data[i][j] [i] data i j data[i][k]+data[k][j] data[i][k] [i] data i k data[k][j] [k] data k j return data data data data n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l inf=float("inf") inf float("inf") float "inf" [inf]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [inf]*n [inf] inf n data=[[inf]*n for i in range(n)] data [[inf]*n for i in range(n)] for i in range(m):
    a,b,c=map(int,input().split())
    data[a-1][b-1]=c
    data[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 data[a-1][b-1]=c data[a-1][b-1] [a-1] data a-1 a 1 b-1 b 1 c data[b-1][a-1]=c data[b-1][a-1] [b-1] data b-1 b 1 a-1 a 1 c for i in range(n):
    data[i][i]=0 i range(n) range n data[i][i]=0 data[i][i] [i] data i i 0 data=warshal(data) data warshal(data) warshal data for i in range(n):
    for j in range(n):
        if data[i][j]<=l:
            data[i][j]=1
        else:
            data[i][j]=inf i range(n) range n for j in range(n):
        if data[i][j]<=l:
            data[i][j]=1
        else:
            data[i][j]=inf j range(n) range n if data[i][j]<=l:
            data[i][j]=1
        else:
            data[i][j]=inf data[i][j]<=l data[i][j] [i] data i j l data[i][j]=1 data[i][j] [i] data i j 1 data[i][j]=inf data[i][j] [i] data i j inf for i in range(n):
    data[i][i]=0 i range(n) range n data[i][i]=0 data[i][i] [i] data i i 0 data=warshal(data) data warshal(data) warshal data q=int(input()) q int(input()) int input() input st=[] st [] for i in range(q):
    s,t=map(int,input().split())
    st.append([s-1,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 st.append([s-1,t-1]) st.append st append [s-1,t-1] s-1 s 1 t-1 t 1 for s,t in st:
    if data[s][t]==inf:
        print(-1)
    else:
        print(data[s][t]-1) s t st if data[s][t]==inf:
        print(-1)
    else:
        print(data[s][t]-1) data[s][t]==inf data[s][t] [s] data s t inf print(-1) print -1 print(data[s][t]-1) print data[s][t]-1 data[s][t] [s] data s t 1 q=int(input()) int(input()) q b,c=map(int,input().split()) map(int,input().split()) b n,m,l=map(int,input().split()) map(int,input().split()) n inf=float("inf") float("inf") inf c=map(int,input().split()) map(int,input().split()) c t=map(int,input().split()) map(int,input().split()) t s,t=map(int,input().split()) map(int,input().split()) s m,l=map(int,input().split()) map(int,input().split()) m def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
    return data def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
    return data warshal data=warshal(data) warshal(data) data st=[] [] st data=[[inf]*n for i in range(n)] [[inf]*n for i in range(n)] data data=warshal(data) warshal(data) data a,b,c=map(int,input().split()) map(int,input().split()) a l=map(int,input().split()) map(int,input().split()) l
def warshal(data):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                data[i][j]=min(data[i][j],data[i][k]+data[k][j])
    return data
n,m,l=map(int,input().split())
inf=float("inf")
data=[[inf]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    data[a-1][b-1]=c
    data[b-1][a-1]=c
for i in range(n):
    data[i][i]=0
data=warshal(data)
for i in range(n):
    for j in range(n):
        if data[i][j]<=l:
            data[i][j]=1
        else:
            data[i][j]=inf
for i in range(n):
    data[i][i]=0
data=warshal(data)
q=int(input())
st=[]
for i in range(q):
    s,t=map(int,input().split())
    st.append([s-1,t-1])
for s,t in st:
    if data[s][t]==inf:
        print(-1)
    else:
        print(data[s][t]-1)