n = int(input()) at = [list(map(int,input().split())) for i in range(n)] q = int(input()) qs = [list(map(int,input().split()))+[i] for i in range(q)] qs.sort() seg_len = 1<<19 # > 5*(10**5) seg = [0]*(2*seg_len) cnt = [0]*(2*seg_len) days = [0]*(2*seg_len) from collections import deque start =[] end = [] for i,(a,t) in enumerate(at): start.append((t,i+1)) end.append((a+t, i+1)) start.sort() end.sort() start = deque(start) end = deque(end) # 必要に応じて初期状態構築 for i in range(n): seg[i+1+seg_len] = at[i][0] for i in range(seg_len)[::-1]: seg[i] = seg[i*2] + seg[i*2+1] def update(pos,x,seg): pos += seg_len seg[pos] = x while True: pos >>= 1 if not pos: break seg[pos] = seg[pos<<1] + seg[pos<<1|1] def get_query(l,r,seg): l += seg_len; r += seg_len res = 0 while l < r: if l & 1: res += seg[l] l += 1 if r & 1: r -= 1 res += seg[r] l >>= 1; r >>= 1 return res ans = [0]*(q) for d,l,r,i in qs: if start: while start[0][0] <= d: x,y = start.popleft() update(y, 1, cnt) update(y, x-1, days) if not start: break if end: while end[0][0] <= d: x,y = end.popleft() update(y, 0, cnt) update(y, 0, days) update(y, 0, seg) if not end:break ans[i] = get_query(l, r+1, seg) - (get_query(l, r+1, cnt)*d-get_query(l, r+1, days)) print(*ans, sep = "\n")