def w(d):
    n=len(d)
    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])
    return d
N,M,L = map(int, input().split())
inf=float('inf')
fuel=[[inf]*N for _ in range(N)]
for i in range(N):
    fuel[i][i]=0
for _ in range(M):
    a,b,c=map(int,input().split())
    fuel[a-1][b-1]=fuel[b-1][a-1]=c
Q=int(input())
ST=[list(map(int, input().split())) for _ in range(Q)]
fuel = w(fuel)
for i in range(N):
    for j in range(N):
        if 0 < fuel[i][j] <= L:
            fuel[i][j]=1
        elif fuel[i][j] != 0:
            fuel[i][j] = inf
fuel = w(fuel)
for st in ST:
    print(fuel[st[0]-1][st[1]-1]-1 if fuel[st[0]-1][st[1]-1] != inf else -1) def w(d):
    n=len(d)
    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])
    return d w n=len(d) n len(d) len d 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])
     k range(n) 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])
     i range(n) range n for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
     j range(n) range n d[i][j]=min(d[i][j],d[i][k]+d[k][j]) d[i][j] [i] d i j min(d[i][j],d[i][k]+d[k][j]) min d[i][j] [i] d i j d[i][k]+d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d 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 _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [inf]*N [inf] inf N fuel=[[inf]*N for _ in range(N)] fuel [[inf]*N for _ in range(N)] for i in range(N):
    fuel[i][i]=0 i range(N) range N fuel[i][i]=0 fuel[i][i] [i] fuel i i 0 for _ in range(M):
    a,b,c=map(int,input().split())
    fuel[a-1][b-1]=fuel[b-1][a-1]=c _ 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 fuel[a-1][b-1]=fuel[b-1][a-1]=c fuel[a-1][b-1] [a-1] fuel a-1 a 1 b-1 b 1 c =fuel[b-1][a-1]=c fuel[b-1][a-1] [b-1] fuel b-1 b 1 a-1 a 1 c Q=int(input()) Q int(input()) int input() input list(map(int, input().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ST=[list(map(int, input().split())) for _ in range(Q)] ST [list(map(int, input().split())) for _ in range(Q)] fuel = w(fuel) fuel w(fuel) w fuel for i in range(N):
    for j in range(N):
        if 0 < fuel[i][j] <= L:
            fuel[i][j]=1
        elif fuel[i][j] != 0:
            fuel[i][j] = inf i range(N) range N for j in range(N):
        if 0 < fuel[i][j] <= L:
            fuel[i][j]=1
        elif fuel[i][j] != 0:
            fuel[i][j] = inf j range(N) range N if 0 < fuel[i][j] <= L:
            fuel[i][j]=1
        elif fuel[i][j] != 0:
            fuel[i][j] = inf 0 < fuel[i][j] <= L 0 < fuel[i][j] 0 fuel[i][j] [i] fuel i j L fuel[i][j]=1 fuel[i][j] [i] fuel i j 1 elif fuel[i][j] != 0:
            fuel[i][j] = inf fuel[i][j] != 0 fuel[i][j] [i] fuel i j 0 fuel[i][j] = inf fuel[i][j] [i] fuel i j inf fuel = w(fuel) fuel w(fuel) w fuel for st in ST:
    print(fuel[st[0]-1][st[1]-1]-1 if fuel[st[0]-1][st[1]-1] != inf else -1) st ST print(fuel[st[0]-1][st[1]-1]-1 if fuel[st[0]-1][st[1]-1] != inf else -1) print fuel[st[0]-1][st[1]-1]-1 if fuel[st[0]-1][st[1]-1] != inf else -1 fuel[st[0]-1][st[1]-1] != inf fuel[st[0]-1][st[1]-1] [st[0]-1] fuel st[0]-1 st[0] st 0 1 st[1]-1 st[1] st 1 1 inf fuel[st[0]-1][st[1]-1]-1 fuel[st[0]-1][st[1]-1] [st[0]-1] fuel st[0]-1 st[0] st 0 1 st[1]-1 st[1] st 1 1 1 -1 fuel=[[inf]*N for _ in range(N)] [[inf]*N for _ in range(N)] fuel b,c=map(int,input().split()) map(int,input().split()) b c=map(int,input().split()) map(int,input().split()) c M,L = map(int, input().split()) map(int, input().split()) M N,M,L = map(int, input().split()) map(int, input().split()) N fuel = w(fuel) w(fuel) fuel inf=float('inf') float('inf') inf def w(d):
    n=len(d)
    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])
    return d def w(d):
    n=len(d)
    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])
    return d w Q=int(input()) int(input()) Q L = map(int, input().split()) map(int, input().split()) L a,b,c=map(int,input().split()) map(int,input().split()) a fuel = w(fuel) w(fuel) fuel ST=[list(map(int, input().split())) for _ in range(Q)] [list(map(int, input().split())) for _ in range(Q)] ST
def w(d):
    n=len(d)
    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])
    return d
N,M,L = map(int, input().split())
inf=float('inf')
fuel=[[inf]*N for _ in range(N)]
for i in range(N):
    fuel[i][i]=0
for _ in range(M):
    a,b,c=map(int,input().split())
    fuel[a-1][b-1]=fuel[b-1][a-1]=c
Q=int(input())
ST=[list(map(int, input().split())) for _ in range(Q)]
fuel = w(fuel)
for i in range(N):
    for j in range(N):
        if 0 < fuel[i][j] <= L:
            fuel[i][j]=1
        elif fuel[i][j] != 0:
            fuel[i][j] = inf
fuel = w(fuel)
for st in ST:
    print(fuel[st[0]-1][st[1]-1]-1 if fuel[st[0]-1][st[1]-1] != inf else -1)
