import heapq

inp = open("trains.in", "r")
outp = open("trains.out", "w")

n, m, k = map(int, inp.readline().split())

arr = [[] for i in range(k)]

for i in range(m):
    s, t, a = map(int, inp.readline().split())
    s -= 1
    t -= 1
    a -= 1
    arr[a].append([s, t])

free = []

for i in range(k):
    arr[i].sort()

    prev = 0

    for p in arr[i]:
        if (prev < p[0]):
            free.append([prev, p[0]])
        prev = p[1]

    if (prev < n - 1):
        free.append([prev, n - 1])

scanline = []

for i in range(len(free)):
    scanline.append([free[i][0], 0, i])
    scanline.append([free[i][1], 1, i])

#print(free)

bd = 1
val = 1
while (val < len(free)):
    val *= 2
    bd += 1

binup = [[0] * len(free) for i in range(bd)]
start = [-1] * n

scanline.sort()
heap = []

c = 0

for i in range(len(scanline)):
    #print(scanline[i])
    #print(i, heap)
    
    while (c < scanline[i][0]):
        #print("c")
        if (len(heap)):
            start[c] = heap[0][1]
        c += 1
    
    
    while (len(heap) and free[heap[0][1]][1] <= scanline[i][0]):
        #print(free[heap[0][1]][1], scanline[i][0])
        heapq.heappop(heap)
    
    ind = scanline[i][2]
    if (scanline[i][1] == 0):
        heapq.heappush(heap, [-free[ind][1], ind])
    else:                
        if (len(heap)):
            binup[0][ind] = heap[0][1]
        else:
            binup[0][ind] = ind

for i in range(1, bd):
    for j in range(len(free)):
        binup[i][j] = binup[i - 1][binup[i - 1][j]]

q = int(inp.readline())

#print(start)

for i in range(q):
    s, t = map(int, inp.readline().split())
    s -= 1
    t -= 1
    pos = start[s]
    if (pos == -1):
        outp.write("-1\n")
    else:
        ans = 0
        for i in range(bd - 1, -1, -1):
            if (free[binup[i][pos]][1] < t):
                pos = binup[i][pos]
                ans += 2 ** i

        if (free[pos][1] < t):
            pos = binup[0][pos]
            ans += 1

        if (free[pos][1] < t):
            outp.write("-1\n")
        else:
            outp.write(str(ans + 1) + "\n")