import sys,collections as cl,bisect as bs
Max = 10**18
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())

def wa(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

def on():
    N,M,L = m()

    e = [[Max for i in range(N)]for j in range(N)]

    for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

    for i in range(N):
        e[i][i] = 0

    d = wa(e)


    E = [[Max for i in range(N)]for j in range(N)]

    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

    for i in range(N):
        E[i][i] = 0

    E = wa(E)
    q = onem()
    for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1)

if __name__ == "__main__":
    on()

 import sys,collections as cl,bisect as bs sys collections bisect Max = 10**18 Max 10**18 10 18 def l(): #intのlist
    return list(map(int,input().split())) l return list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def m(): #複数文字
    return map(int,input().split()) m return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def onem(): #Nとかの取得
    return int(input()) onem return int(input()) int(input()) int input() input def wa(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d wa for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
     k range(len(d)) range len(d) len d for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
     i range(len(d)) range len(d) len d for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
     j range(len(d)) range len(d) len d 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 def on():
    N,M,L = m()

    e = [[Max for i in range(N)]for j in range(N)]

    for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

    for i in range(N):
        e[i][i] = 0

    d = wa(e)


    E = [[Max for i in range(N)]for j in range(N)]

    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

    for i in range(N):
        E[i][i] = 0

    E = wa(E)
    q = onem()
    for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1) on N,M,L = m() N m() m M L [Max for i in range(N)]for j in range(N) for j in range(N) j range(N) range N for j in range(N) [Max for i in range(N)] e = [[Max for i in range(N)]for j in range(N)] e [[Max for i in range(N)]for j in range(N)] for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

     i range(M) range M a,b,c = m() a m() m b c e[a-1][b-1] = c e[a-1][b-1] [a-1] e a-1 a 1 b-1 b 1 c e[b-1][a-1] = c e[b-1][a-1] [b-1] e b-1 b 1 a-1 a 1 c for i in range(N):
        e[i][i] = 0

     i range(N) range N e[i][i] = 0 e[i][i] [i] e i i 0 d = wa(e) d wa(e) wa e [Max for i in range(N)]for j in range(N) for j in range(N) j range(N) range N for j in range(N) [Max for i in range(N)] E = [[Max for i in range(N)]for j in range(N)] E [[Max for i in range(N)]for j in range(N)] for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

     i range(N) range N for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

     j range(N) range N if d[i][j] <= L:
                E[i][j] = 1

     d[i][j] <= L d[i][j] [i] d i j L E[i][j] = 1 E[i][j] [i] E i j 1 for i in range(N):
        E[i][i] = 0

     i range(N) range N E[i][i] = 0 E[i][i] [i] E i i 0 E = wa(E) E wa(E) wa E q = onem() q onem() onem for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1) i range(q) range q s,t = m() s m() m t if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1) E[s-1][t-1] == Max E[s-1][t-1] [s-1] E s-1 s 1 t-1 t 1 Max print(-1) print -1 print(E[s-1][t-1]-1) print E[s-1][t-1]-1 E[s-1][t-1] [s-1] E s-1 s 1 t-1 t 1 1 if __name__ == "__main__":
    on() __name__ == "__main__" __name__ "__main__" on() on def m(): #複数文字
    return map(int,input().split()) def m(): #複数文字
    return map(int,input().split()) m def on():
    N,M,L = m()

    e = [[Max for i in range(N)]for j in range(N)]

    for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

    for i in range(N):
        e[i][i] = 0

    d = wa(e)


    E = [[Max for i in range(N)]for j in range(N)]

    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

    for i in range(N):
        E[i][i] = 0

    E = wa(E)
    q = onem()
    for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1) def on():
    N,M,L = m()

    e = [[Max for i in range(N)]for j in range(N)]

    for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

    for i in range(N):
        e[i][i] = 0

    d = wa(e)


    E = [[Max for i in range(N)]for j in range(N)]

    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

    for i in range(N):
        E[i][i] = 0

    E = wa(E)
    q = onem()
    for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1) on def onem(): #Nとかの取得
    return int(input()) def onem(): #Nとかの取得
    return int(input()) onem Max = 10**18 10**18 Max def l(): #intのlist
    return list(map(int,input().split())) def l(): #intのlist
    return list(map(int,input().split())) l def wa(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d def wa(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d wa
import sys,collections as cl,bisect as bs
Max = 10**18
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())

def wa(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

def on():
    N,M,L = m()

    e = [[Max for i in range(N)]for j in range(N)]

    for i in range(M):
        a,b,c = m()
        e[a-1][b-1] = c
        e[b-1][a-1] = c

    for i in range(N):
        e[i][i] = 0

    d = wa(e)


    E = [[Max for i in range(N)]for j in range(N)]

    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                E[i][j] = 1

    for i in range(N):
        E[i][i] = 0

    E = wa(E)
    q = onem()
    for i in range(q):
        s,t = m()
        if E[s-1][t-1] == Max:
            print(-1)
        else:
            print(E[s-1][t-1]-1)

if __name__ == "__main__":
    on()


