#include <bits/stdtr1c++.h>

using namespace std;

typedef double ld;
typedef long long ll;
typedef complex<ld> pt;

const ld EPS = 1e-8;
ld cp(const pt& a, const pt& b) { return imag(conj(a)*b); }
ld dp(const pt& a, const pt& b) { return real(conj(a)*b); }
inline ld sgn(const ld& x) { return abs(x) < EPS ? 0 : x/abs(x); }
inline bool cmp_lex(const pt& a, const pt& b) {
  return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag()); }
inline bool cmp_lex_i(const pt& a, const pt& b) {
  return a.imag() < b.imag() || (a.imag() == b.imag() && a.real() < b.real()); }
// handles ALL cases, change occurences of <= to < to exclude endpoints
bool seg_x_seg(pt a1, pt a2, pt b1, pt b2) {
  //if (a1==a2 || b1==b2) return false; // uncomment to exclude endpoints
  int s1 = sgn(cp(a2 - a1, b1 - a1)), s2 = sgn(cp(a2 - a1, b2 - a1));
  int s3 = sgn(cp(b2 - b1, a1 - b1)), s4 = sgn(cp(b2 - b1, a2 - b1));
  if(!s1 && !s2 && !s3) { // collinear
    if (cmp_lex(a2, a1)) swap(a1, a2); if (cmp_lex(b2, b1)) swap(b1, b2);
    //return cmp_lex(a1, b2) && cmp_lex(b1, a2);//uncomment to exclude endpoints
    return !cmp_lex(b2, a1) && !cmp_lex(a2, b1);
  } return s1*s2 <= 0 && s3*s4 <= 0; }

inline pt line_inter(const pt &a, const pt &b, const pt &c, const pt &d) {
  return a + cp(c - a, d - c) / cp(b - a, d - c) * (b - a); }
  
ld X, K; int N, Q;
ll c[2005], perm[2005], iperm[2005];
pt s[2005], e[2005];

ld eval(const pt& a, const pt& b, ld x) {
	return a.imag() + (b.imag() - a.imag())/X * x;
}

struct by_y {
	ld x;
	by_y(ld x) : x(x) {}
	bool operator()(const int& i, const int& j) const {
		return eval(s[i], e[i], x) > eval(s[j], e[j], x);
	}
};

struct inter {
	pt p;
	int i, j;
};

inline bool cmp_inter(const inter& a, const inter& b) { return cmp_lex(a.p, b.p); }

int main() {
	scanf("%lf%lf%d%d", &X, &K, &N, &Q);
	for (int i = 0; i < N; i++) {
		ld a, b;
		scanf("%lf%lf%ld", &a, &b, c+i);
		s[i] = pt(0, a);
		e[i] = pt(X, b);
		perm[i] = i;
	}
	
	vector<inter> isect[N];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) continue;
			if (!seg_x_seg(s[i], e[i], s[j], e[j])) continue;
			isect[i].push_back({line_inter(s[i], e[i], s[j], e[j]), i, j});
		}
	}
	for (int i = 0; i < N; i++) {
		isect[i].push_back({pt(0,0), 0, 0});
	}
	
	ll** val = new ll*[N];
	ll M[N];
	for (int i = 0; i < N; i++) {
		sort(isect[i].begin(), isect[i].end(), cmp_inter);
		M[i] = isect[i].size();
		val[i] = new ll[2 * M[i]];
	}
	
	vector<ld> xc[N];
	for (int i = 0; i < N; i++) {
		int j = 0;
		sort(perm, perm+N, by_y(0));
		for (int k = 0; k < N; k++) {
			iperm[perm[k]] = k;
		}
		
		set<int> inside;
		ll res = 0;
		for (int k = 0; k < N; k++) {
			if (perm[k] == i) break;
			inside.insert(perm[k]);
			res += c[perm[k]];
		}
		
		for (const auto& p : isect[i]) {
			if (p.i != p.j) {
				int o = perm[iperm[p.j]];
				if (inside.count(o)) res -= c[o];
				else res += c[o];
			}
			
			swap(perm[iperm[p.i]], perm[iperm[p.j]]);
			swap(iperm[p.i], iperm[p.j]);
			
			//cerr << "on xcoord: " << p.p.real() << endl;
			xc[i].push_back(p.p.real());
			//cerr << "ordering: ";
			//for (int i = 0; i < N; i++) cerr << perm[i] << " ";
			//cerr << endl;
			//cerr << "val: " << j << " " << res << endl;
			val[i][M[i]+j] = res;
			j++;
		}
		//cerr << endl;
	}
	
	// build the tree
	for (int j = 0; j < N; j++) {
		for (int i = M[j] - 1; i > 0; --i) {
			val[j][i] = max(val[j][i<<1], val[j][i<<1|1]);
		}
	}
	
	// query the tree
	auto query = [&](const int i, int l, int r) {
		ll res = 0;
		for (l += M[i], r += M[i]; l < r; l >>= 1, r >>= 1) {
			if (l&1) res = max(res, val[i][l++]);
			if (r&1) res = max(res, val[i][--r]);
		}
		return res;
	};
	
	while (Q--) {
		int id; ld x;
		scanf("%d%lf", &id, &x);
		id--;
		
		int l = lower_bound(xc[id].begin(), xc[id].end(), x + EPS) - xc[id].begin();
		l = max(l-1, 0);
		
		int r = lower_bound(xc[id].begin(), xc[id].end(), x + K + EPS) - xc[id].begin();
		printf("%ld\n", query(id, l, r));
		
		/*
		cerr << "bounds: " << l << " " << r << " : " << x << " " << x+K << endl;
		cerr << "vals: " << endl;
		for (int i = l; i < r; i++) {
			cerr << val[id][M[id] + i] << " ";
		}
		cerr << endl;
		*/
	}
	return 0;
}