n,m,l=map(int,input().split())
cost=[[10**9+1]*n for i in range(n)]
length=[[10**9]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    cost[a][b]=c
    cost[b][a]=c
q=int(input())
st=[map(int,input().split())for i in range(q)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
for i in range(n):
    length[i][i]=0
for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            length[i][j]=0
for k in range(n):
    for i in range(n):
        for j in range(n):
            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1)
for s,t in st:
    ch=min(length[s-1][t-1],length[t-1][s-1])
    print(-1 if ch>10**8 else ch) n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [10**9+1]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [10**9+1]*n [10**9+1] 10**9+1 10**9 10 9 1 n cost=[[10**9+1]*n for i in range(n)] cost [[10**9+1]*n for i in range(n)] [10**9]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [10**9]*n [10**9] 10**9 10 9 n length=[[10**9]*n for i in range(n)] length [[10**9]*n for i in range(n)] for i in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    cost[a][b]=c
    cost[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 a-=1 a 1 b-=1 b 1 cost[a][b]=c cost[a][b] [a] cost a b c cost[b][a]=c cost[b][a] [b] cost b a c q=int(input()) q int(input()) int input() input map(int,input().split())for i in range(q) for i in range(q) i range(q) range q for i in range(q) map(int,input().split()) map int input().split() ().split () input split st=[map(int,input().split())for i in range(q)] st [map(int,input().split())for i in range(q)] for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]) i range(n) range n for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]) j range(n) range n cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]) cost[i][j] [i] cost i j min(cost[i][j],cost[i][k]+cost[k][j]) min cost[i][j] [i] cost i j cost[i][k]+cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j for i in range(n):
    length[i][i]=0 i range(n) range n length[i][i]=0 length[i][i] [i] length i i 0 for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            length[i][j]=0 i range(n) range n for j in range(n):
        if cost[i][j]<=l:
            length[i][j]=0 j range(n) range n if cost[i][j]<=l:
            length[i][j]=0 cost[i][j]<=l cost[i][j] [i] cost i j l length[i][j]=0 length[i][j] [i] length i j 0 for k in range(n):
    for i in range(n):
        for j in range(n):
            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1) k range(n) range n for i in range(n):
        for j in range(n):
            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1) i range(n) range n for j in range(n):
            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1) j range(n) range n length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1) length[i][j] [i] length i j min(length[i][j],length[i][k]+length[k][j]+1) min length[i][j] [i] length i j length[i][k]+length[k][j]+1 length[i][k]+length[k][j] length[i][k] [i] length i k length[k][j] [k] length k j 1 for s,t in st:
    ch=min(length[s-1][t-1],length[t-1][s-1])
    print(-1 if ch>10**8 else ch) s t st ch=min(length[s-1][t-1],length[t-1][s-1]) ch min(length[s-1][t-1],length[t-1][s-1]) min length[s-1][t-1] [s-1] length s-1 s 1 t-1 t 1 length[t-1][s-1] [t-1] length t-1 t 1 s-1 s 1 print(-1 if ch>10**8 else ch) print -1 if ch>10**8 else ch ch>10**8 ch 10**8 10 8 -1 ch a,b,c=map(int,input().split()) map(int,input().split()) a st=[map(int,input().split())for i in range(q)] [map(int,input().split())for i in range(q)] st ch=min(length[s-1][t-1],length[t-1][s-1]) min(length[s-1][t-1],length[t-1][s-1]) ch q=int(input()) int(input()) q cost=[[10**9+1]*n for i in range(n)] [[10**9+1]*n for i in range(n)] cost b,c=map(int,input().split()) map(int,input().split()) b m,l=map(int,input().split()) map(int,input().split()) m l=map(int,input().split()) map(int,input().split()) l length=[[10**9]*n for i in range(n)] [[10**9]*n for i in range(n)] length c=map(int,input().split()) map(int,input().split()) c a-=1 1 a b-=1 1 b n,m,l=map(int,input().split()) map(int,input().split()) n
n,m,l=map(int,input().split())
cost=[[10**9+1]*n for i in range(n)]
length=[[10**9]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    cost[a][b]=c
    cost[b][a]=c
q=int(input())
st=[map(int,input().split())for i in range(q)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
for i in range(n):
    length[i][i]=0
for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            length[i][j]=0
for k in range(n):
    for i in range(n):
        for j in range(n):
            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1)
for s,t in st:
    ch=min(length[s-1][t-1],length[t-1][s-1])
    print(-1 if ch>10**8 else ch)