Buggy python submission (verdict: Runtime Error):
INF=10**18
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                d[i][j]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
ans=[]
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    dis=d[s-1][t-1]
    if dis==INF:
        ans.append(-1)
    else:
        ans.append(dis-1)

for a in ans:
    print(int(a))


Fixed submission:
INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
INF=10**18
N,M,L=map(int,input().split())
d=np.zeros((N,N))
d[:,:]=INF
for i in range(N):
    d[i,i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1,B-1]=C
    d[B-1,A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i,j]=min(d[i,j],d[i,k]+d[k,j])
for i in range(N):
        for j in range(N):
            if d[i,j]<=L:
                d[i,j]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i,j]=min(d[i,j],d[i,k]+d[k,j])
ans=[]
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    dis=d[s-1,t-1]
    if dis==INF:
        ans.append(-1)
    else:
        ans.append(dis-1)

for a in ans:
    print(int(a))


Fixed submission:
INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
INF=10**18
N,M,L=map(int,input().split())
d=np.zeros((N,N))
d[:,:]=INF
for i in range(N):
    d[i,i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1,B-1]=C
    d[B-1,A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i,j]=min(d[i,j],d[i,k]+d[k,j])
for i in range(N):
        for j in range(N):
            if d[i,j]<=L:
                d[i,j]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i,j]=min(d[i,j],d[i,k]+d[k,j])
ans=[]
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    dis=d[s-1,t-1]
    if dis==INF:
        ans.append(-1)
    else:
        ans.append(dis-1)

for a in ans:
    print(int(a))


Fixed submission:
INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
INF=10**18
N,M,L=map(int,input().split())
d=np.zeros((N,N))
d[:,:]=INF
for i in range(N):
    d[i,i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1,B-1]=C
    d[B-1,A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i,j]=min(d[i,j],d[i,k]+d[k,j])
for i in range(N):
        for j in range(N):
            if d[i,j]<=L:
                d[i,j]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i,j]=min(d[i,j],d[i,k]+d[k,j])
ans=[]
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    dis=d[s-1,t-1]
    if dis==INF:
        ans.append(-1)
    else:
        ans.append(dis-1)

for a in ans:
    print(int(a))


Fixed submission:
INF=10**15
N,M,L=map(int,input().split())
d=[[INF for i in range(N)] for j in range(N)]
d1=[[INF for i in range(N)] for j in range(N)]
for i in range(N):
    d[i][i]=0
for m in range(M):
    A,B,C=map(int,input().split())
    d[A-1][B-1]=C
    d[B-1][A-1]=C

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in range(N):
        for j in range(N):
            if i!=j and d[i][j]<=L:
                d1[i][j]=1
                d1[j][i]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j])

Q=int(input())
for _ in range(Q):
    s,t=map(int,input().split())
    dis=d1[s-1][t-1]
    if dis==INF:
        print(-1)
    else:
        print(dis-1)