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