#include <bits/stdc++.h>
using namespace std;
struct DSU {
int parent[2005], rank[2005];
DSU(int n) {
iota(begin(parent), end(parent), 0);
memset(rank, 1, sizeof(rank));
}
int find(int u) { return parent[u] == u ? u : parent[u] = find(parent[u]); }
void merge(int u, int v) {
u = find(u);
v = find(v);
if(u == v) return;
if(rank[u] < rank[v]) swap(u, v);
parent[v] = u;
rank[u] += rank[v];
}
};
struct tree {
long long x, y, r;
long long gap(const tree& other) {
long long dx = x - other.x, dy = y - other.y;
return sqrt((long double)dx * dx + (long double)dy * dy) - r - other.r;
}
};
struct triplet {
long long val;
int a, b;
bool operator<(const triplet& other) const { return val < other.val; }
};
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
long long w, h;
cin >> n >> m >> w >> h;
vector<tree> a(n);
vector<triplet> events, q(m);
for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y >> a[i].r;
for(int i = 0; i < n; i++) {
int id = i + 4;
events.push_back({a[i].y - a[i].r, id, 0});
events.push_back({w - a[i].x - a[i].r, id, 1});
events.push_back({h - a[i].y - a[i].r, id, 2});
events.push_back({a[i].x - a[i].r, id, 3});
}
for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) events.push_back({a[i].gap(a[j]), i + 4, j + 4});
for(int i = 0; i < m; i++) {
long long r;
int e;
cin >> r >> e;
q[i] = {2 * r, --e, i};
}
sort(begin(events), end(events));
sort(begin(q), end(q));
static bool valid[100005][4];
memset(valid, true, sizeof(valid));
DSU dsu(n + 4);
int ptr = 0;
for(const triplet& curr : q) {
while(ptr < (int)events.size() && events[ptr].val < curr.val) {
dsu.merge(events[ptr].a, events[ptr].b);
ptr++;
}
bool conn[4][4];
for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) conn[i][j] = dsu.find(i) == dsu.find(j);
for(int i = 0; i < 4; i++) {
if(i == curr.a) continue;
if(conn[curr.a == 0 ? 3 : curr.a - 1][curr.a] || conn[i == 0 ? 3 : i - 1][i]) {
valid[curr.b][i] = false;
continue;
}
if(abs(curr.a - i) == 2) { if(conn[0][2] || conn[1][3]) valid[curr.b][i] = false; }
else if(curr.a + i == 3) { if(conn[1][3]) valid[curr.b][i] = false; }
else { if(conn[0][2]) valid[curr.b][i] = false; }
}
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < 4; j++) if(valid[i][j]) cout << (char)(j + '1');
cout << '\n';
}
return 0;
}