import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d
n,m,l = map(int,readline().split())
d = [[10**12]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,readline().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**12
d = warshall_floid(d)
q = int(readline())
for i in range(q):
    s,t = map(int,readline().split())
    if d[s][t] >= 10**12:
        print(-1)
    else:
        print(d[s][t]-1) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d warshall_floid for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
     k range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
     i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
     j range(1,n+1) range 1 n+1 n 1 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,readline().split()) n map(int,readline().split()) map int readline().split() ().split () readline split m l [10**12]*(n+1) for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [10**12]*(n+1) [10**12] 10**12 10 12 n+1 n 1 d = [[10**12]*(n+1) for i in range(n+1)] d [[10**12]*(n+1) for i in range(n+1)] for i in range(m):
    a,b,c = map(int,readline().split())
    d[a][b] = c
    d[b][a] = c i range(m) range m a,b,c = map(int,readline().split()) a map(int,readline().split()) map int readline().split() ().split () readline split b c d[a][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c for i in range(1,n+1):
    d[i][i] = 0 i range(1,n+1) range 1 n+1 n 1 d[i][i] = 0 d[i][i] [i] d i i 0 d = warshall_floid(d) d warshall_floid(d) warshall_floid d for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**12 i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**12 j range(1,n+1) range 1 n+1 n 1 if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**12 d[i][j] <= l d[i][j] [i] d i j l d[i][j] = 1 d[i][j] [i] d i j 1 d[i][j] = 10**12 d[i][j] [i] d i j 10**12 10 12 d = warshall_floid(d) d warshall_floid(d) warshall_floid d q = int(readline()) q int(readline()) int readline() readline for i in range(q):
    s,t = map(int,readline().split())
    if d[s][t] >= 10**12:
        print(-1)
    else:
        print(d[s][t]-1) i range(q) range q s,t = map(int,readline().split()) s map(int,readline().split()) map int readline().split() ().split () readline split t if d[s][t] >= 10**12:
        print(-1)
    else:
        print(d[s][t]-1) d[s][t] >= 10**12 d[s][t] [s] d s t 10**12 10 12 print(-1) print -1 print(d[s][t]-1) print d[s][t]-1 d[s][t] [s] d s t 1 d = warshall_floid(d) warshall_floid(d) d s,t = map(int,readline().split()) map(int,readline().split()) s l = map(int,readline().split()) map(int,readline().split()) l a,b,c = map(int,readline().split()) map(int,readline().split()) a readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d warshall_floid m,l = map(int,readline().split()) map(int,readline().split()) m readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline b,c = map(int,readline().split()) map(int,readline().split()) b q = int(readline()) int(readline()) q c = map(int,readline().split()) map(int,readline().split()) c d = warshall_floid(d) warshall_floid(d) d n,m,l = map(int,readline().split()) map(int,readline().split()) n d = [[10**12]*(n+1) for i in range(n+1)] [[10**12]*(n+1) for i in range(n+1)] d read = sys.stdin.buffer.read sys.stdin.buffer.read read t = map(int,readline().split()) map(int,readline().split()) t
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d
n,m,l = map(int,readline().split())
d = [[10**12]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,readline().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**12
d = warshall_floid(d)
q = int(readline())
for i in range(q):
    s,t = map(int,readline().split())
    if d[s][t] >= 10**12:
        print(-1)
    else:
        print(d[s][t]-1)