/*******************
* what the sigma *
********************/
#pragma GCC optimize("O3","unroll-loops")
#include <iostream>
#include <vector>
#include <map>
#include <chrono>
#include <set>
#include <queue>
#include <algorithm>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
#define lgm cin.tie(0)->sync_with_stdio(0);
#define be(x) x.begin(),x.end()
#define ve vector
#define ll long long
#define ld long double
bool enabledb=0;
#define DB(CODE) cout<<'\t'<<CODE<<endl;
#define SP <<' '<<
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int, int>
#define tii tuple<int,int,int>
#define pll pair<ll,ll>
#define tll tuple<ll,ll,ll>
#define sz(x) ((int)x.size())
#define pb push_back
const ll mod = 998244353,maxn=2005,root=3;
const ll INF=(ll)2e18;
int pa[maxn+6];
int find(int u) {
if (pa[u]==u) return u;
return pa[u]=find(pa[u]);
}
void unite(int u,int v) {
u=find(u),v=find(v);
if (u==v) return;
pa[v]=u;
}
ll dist(pll x, pll y) {
return sqrtl((x.f-y.f)*(x.f-y.f)+(x.s-y.s)*(x.s-y.s));
}
int main() {
lgm;
int n,q;
cin >> n >> q;
int w,h;
cin >> w >> h;
ve<pair<pll,int>> tr(n+1);
for (int i=1;i<=n;i++) {
int x,y,r;
cin >> x >> y >> r;
tr[i]={{x,y},r};
}
ve<pair<ll,pll>> gap;
for (int i=1;i<=n;i++) {
for (int j=i+1;j<=n;j++) {
int d=dist(tr[i].f,tr[j].f);
d-=tr[i].s+tr[j].s;
gap.pb({d,{i,j}});
}
gap.pb({tr[i].f.f-tr[i].s,{maxn+1,i}});
gap.pb({tr[i].f.s-tr[i].s,{maxn+2,i}});
gap.pb({w-(tr[i].s+tr[i].f.f),{maxn+3,i}});
gap.pb({h-(tr[i].s+tr[i].f.s),{maxn+4,i}});
}
sort(be(gap));
for (int i=1;i<=maxn+4;i++) {
pa[i]=i;
}
ve<pair<pll,int>> qr(q);
for (int i=0;i<q;i++) {
int x,y;
cin >> x >> y;
qr[i]={{x,y},i};
}
sort(be(qr));
int idx=0;
ve<string> ans(q);
for (int i=0;i<q;i++) {
while (idx<sz(gap)&&gap[idx].f<2*qr[i].f.f) {
unite(gap[idx].s.f,gap[idx].s.s);
idx++;
}
int en=qr[i].f.s;
en--;
ve<int> border={find(maxn+1),find(maxn+2),find(maxn+3),find(maxn+4)};
// if find(border1)=find(border2) then that means we cant escape
if (border[en]==border[(en+1)%4]) {
ans[qr[i].s]=to_string(en+1);
continue;
}
ve<int> corner(4,1);
for (int j=0;j<4;j++) {
if (border[j]==border[(j+1)%4]) {
corner[j]=0;
}
}
if (border[en]==border[(en+2)%4]) {
corner[(en+2)%4]=0;
corner[(en+3)%4]=0;
}
if (border[(en+1)%4]==border[(en+3)%4]) {
corner[(en+1)%4]=0;
corner[(en+2)%4]=0;
}
for (int j=0;j<4;j++) {
if (corner[j]) ans[qr[i].s]+=to_string(j+1);
}
}
for (int i=0;i<q;i++) {
cout << ans[i] << '\n';
}
}