from sys import stdin, setrecursionlimit from collections import deque import bisect input = stdin.readline readline = stdin.readline N,M=map(int, input().split()) kousa=[] syoko=[] for i in range(N): s,k=map(int,input().split()) kousa.append(k) syoko.append(s) def SuMD(i:int,p:int): if p==0: return 0 return syoko[i]*p+p*(p-1)//2*kousa[i] def f_i(i:int,x:int): if x<=syoko[i]: p=0 elif x>syoko[i]+kousa[i]*(M-1): p=M else: p=(x-syoko[i]-1)//kousa[i]+1 return (SuMD(i,M)-2*SuMD(i,p))+(2*p-M)*x def CH(i:int,j:int,k:int)->bool: L,R=0,10**9+1 while R-L>1: mid=(L+R)//2 if f_i(j,mid)<=f_i(k,mid): L=mid else: R=mid if f_i(i,R-1)<=f_i(j,R-1): return True else: return False d=deque() dlen=0 for i in range(N): while dlen>=2 and CH(d[-2],d[-1],i): d.pop() dlen-=1 d.append(i) dlen+=1 Q,X=map(int,input().split()) A=list(map(int, input().split())) AN=[0]*Q for q in range(Q): while dlen>=2 and f_i(d[0],X)>f_i(d[1],X): dlen-=1 d.popleft() AN[q]=d[0]+1 X+=A[AN[q]-1] if X>10**9+5: X=10**9+5 print(*AN)