#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long double dd;
typedef long long ll;

const int MAXN=2048;
const dd eps=1e-8;
dd line[2005][2]; //[0] is m, [1] is b
ll interf[2005];
vector<dd> crosses[2005];
ll segTree[2005][2*MAXN];
int rightEnd,queryWidth,p,q;
dd cross(int i,int j){
    if (line[i][0]==line[j][0]) return -1;
    dd ans=line[j][1]-line[i][1];
    ans/=(line[i][0]-line[j][0]);
    if ((ans<0)||(ans>rightEnd)) return -1;
    return ans;
}
void build(int x){
    for (int j=MAXN/2;j>0;j/=2) for (int i=j;i<2*j;i++) segTree[x][i]=max(segTree[x][2*i],segTree[x][2*i+1]);
}
ll query(int x, int y, int i, int l, int r, int node){
    //cout<<x<<' '<<y<<' '<<l<<' '<<r<<' '<<node<<endl;
    if ((r<x)||(l>y)) return -1;
    if ((x<=l)&&(r<=y)) return segTree[i][node];
    int mid=(l+r)/2;
    return max(query(x,y,i,l,mid,2*node),query(x,y,i,mid+1,r,2*node+1));
}
int main(){
    //freopen("readable.txt","w",stdout);
    scanf("%i%i%i%i",&rightEnd,&queryWidth,&p,&q);
    for (int i=1;i<=p;i++){
        dd asd;
        scanf("%Lf%Lf%lld",line[i]+1,&asd,interf+i);
        line[i][0]=(asd-line[i][1])/rightEnd;
    }
    //Build seg trees
    for (int curr=1;curr<=p;curr++){
        vector<pair<dd,ll>> pts;
        ll above=0;
        for (int i=1;i<=p;i++){
            if (i!=curr) {
                if (line[i][1]>line[curr][1]) above+=interf[i];
                dd x=cross(curr,i);
                if (x>0){
                    if (line[i][0]>line[curr][0]) pts.push_back({x,interf[i]});
                    else pts.push_back({x,0-interf[i]});
                }
            }
        }
        sort(pts.begin(),pts.end());
        segTree[curr][MAXN]=above;
        ll now=above;
        crosses[curr].push_back(0);
        dd here=0;
        int count=1;
        for (int i=0;i<pts.size();i++) {
            if (abs(pts[i].first-here)>1e-6){
                segTree[curr][MAXN+count]=now;
                crosses[curr].push_back(here);
                here=pts[i].first;
                count++;
            }
            now+=pts[i].second;
        }
        segTree[curr][MAXN+count]=now;
        crosses[curr].push_back(here);
        build(curr);
    }
    /*for (int i=18;i<=18;i++){
        cout<<i<<": ";
        for (int j=0;j<200;j++) cout<<segTree[i][MAXN+j]<<' ';
        cout<<endl;
    }*/
    //queries
    int plane,left;
    for (int i=0;i<q;i++){
        scanf("%i%i",&plane,&left);
        int l=lower_bound(crosses[plane].begin(),crosses[plane].end(),left+eps)-crosses[plane].begin();
        l--;
        int r=lower_bound(crosses[plane].begin(),crosses[plane].end(),left+queryWidth-eps)-crosses[plane].begin();
        r--;
        printf("%lld\n",query(l,r,plane,0,MAXN-1,1));
    }
    return 0;
}