import sys class Node: __slots__ = ['left', 'right', 'sum'] def __init__(self, left=None, right=None, sum=0): self.left = left self.right = right self.sum = sum def main(): import sys sys.setrecursionlimit(1 << 25) input = sys.stdin.read data = input().split() ptr = 0 N = int(data[ptr]) ptr +=1 K = int(data[ptr]) ptr +=1 Q = int(data[ptr]) ptr +=1 operations = [] for _ in range(K): L = int(data[ptr]) ptr +=1 R = int(data[ptr]) ptr +=1 C = int(data[ptr]) ptr +=1 H = int(data[ptr]) ptr +=1 operations.append( (L, R, C, H) ) # Persistent segment tree setup roots = [None]*(K+1) # roots[0] is the initial empty tree roots[0] = Node() current_root = roots[0] for j in range(1, K+1): L, R, C, H = operations[j-1] # Function to apply the range add, creating a new root def add(node, a, b): if b < L or a > R: return node new_node = Node() if node is not None: new_node.left = node.left new_node.right = node.right new_node.sum = node.sum else: new_node.sum = 0 if L <= a and b <= R: new_node.sum += H return new_node mid = (a + b) // 2 new_node.left = add(new_node.left, a, mid) if new_node.left else add(Node(), a, mid) new_node.right = add(new_node.right, mid+1, b) if new_node.right else add(Node(), mid+1, b) return new_node new_root = add(current_root, 1, N) roots[j] = new_root current_root = new_root # Query function def query(root, a, b, i): if not root: return 0 res = root.sum if a == b: return res mid = (a + b) // 2 if i <= mid: res += query(root.left, a, mid, i) else: res += query(root.right, mid+1, b, i) return res # Process queries output = [] for _ in range(Q): I = int(data[ptr]) ptr +=1 X = int(data[ptr]) ptr +=1 x = X - 0.5 if K ==0: output.append(-1) continue sum_total = query(roots[K], 1, N, I) if sum_total < x: output.append(-1) continue # Binary search to find the earliest j low = 1 high = K answer = K while low <= high: mid = (low + high) //2 s = query(roots[mid], 1, N, I) if s >= x: answer = mid high = mid -1 else: low = mid +1 # Get the color L_j, R_j, C_j, H_j = operations[answer-1] output.append(C_j) print('\n'.join(map(str, output))) if __name__ == "__main__": main()