#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
const db eps=1e-6;
const ll md=1e9+7;
// const ll md=119<<23|1;
template<class T, class U> inline T chmn(T &x, const U y){ return x=min(x,y); }
template<class T, class U> inline T chmx(T &x, const U y){ return x=max(x,y); }
template<class T, class U> inline auto add(const T &x, const U &y){ return ((x+y)%md+md)%md; }
template<class T, class U> inline auto mul(const T &x, const U &y){ return ((x*y)%md+md)%md; }
template<class T, class U> inline auto Add(T &x, const U &y){ return x=add(x,y); }
template<class T, class U> inline auto Mul(T &x, const U &y){ return x=mul(x,y); }
using i3 = array<ll,3>;
i3 a[2005];
vector<i3> edges;
int p[2005];
int fSet(int u){
return p[u]==u?u:p[u]=fSet(p[u]);
}
bool uSet(int u, int v){
u=fSet(u), v=fSet(v);
if(u==v) return false;
p[u]=v; return true;
}
ll f(const i3 &x, const i3 &y){
return sqrt((x[0]-y[0])*(x[0]-y[0])+(x[1]-y[1])*(x[1]-y[1])) - x[2] - y[2];
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n,Q; cin>>n>>Q;
ll w,h; cin>>w>>h;
for(int i=0;i<n;++i){
for(int j=0;j<3;++j) cin>>a[i][j];
edges.eb(i3{i,n,a[i][0]-a[i][2]});
edges.eb(i3{i,n+1,a[i][1]-a[i][2]});
edges.eb(i3{i,n+2,w-a[i][0]-a[i][2]});
edges.eb(i3{i,n+3,h-a[i][1]-a[i][2]});
}
for(int i=0;i<n;++i) for(int j=i+1;j<n;++j) edges.eb(i3{i,j,f(a[i],a[j])});
sort(edges.begin(),edges.end(),[](const i3 &x, const i3 &y){ return x[2]<y[2]; });
vector<i3> qrs(Q);
vector<string> ans(Q);
for(int i=0;i<Q;++i){
cin>>qrs[i][0]>>qrs[i][1];
qrs[i][2]=i;
}
sort(qrs.begin(),qrs.end(),[](const i3 &x, const i3 &y){ return x[0]<y[0]; });
iota(p,p+n+4,0);
int pt=0;
for(auto &e:qrs){
while(pt<sz(edges) && edges[pt][2]<e[0]<<1) uSet(edges[pt][0],edges[pt][1]), ++pt;
bool b1 = fSet(n)==fSet(n+1);
bool b2 = fSet(n)==fSet(n+2);
bool b3 = fSet(n)==fSet(n+3);
bool b4 = fSet(n+1)==fSet(n+2);
bool b5 = fSet(n+1)==fSet(n+3);
bool b6 = fSet(n+2)==fSet(n+3);
bool x1=0,x2=0,x3=0,x4=0;
if(e[1]==1){
x1 = 1;
x2 = !(b1||b4||b5);
x3 = !(b1||b2||b5||b6);
x4 = !(b1||b2||b3);
}else if(e[1]==2){
x1 = !(b1||b4||b5);
x2 = 1;
x3 = !(b2||b4||b6);
x4 = !(b2||b3||b4||b5);
}else if(e[1]==3){
x1 = !(b1||b2||b5||b6);
x2 = !(b2||b4||b6);
x3 = 1;
x4 = !(b3||b5||b6);
}else if(e[1]==4){
x1 = !(b1||b2||b3);
x2 = !(b2||b3||b4||b5);
x3 = !(b3||b5||b6);
x4 = 1;
}
if(x1) ans[e[2]]+='1';
if(x2) ans[e[2]]+='2';
if(x3) ans[e[2]]+='3';
if(x4) ans[e[2]]+='4';
}
for(const auto &s:ans) cout<<s<<'\n';
}
//