暴力暴力, 就26的数据量, 直接拓扑排序即可$O(n^2)$
#include <bits/stdc++.h>
#define se second
#define fi first
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef pair<int, int> PII;
const int N = 5e2 + 5;
int n, m, _, k;
vector<int> h[N];
int id[N >> 1], ans, deg[N];
bool v[N >> 1];
pair<PII, PII> paper[N >> 1];
bool check(int i, int x, int y) {
return x >= paper[i].fi.fi && x <= paper[i].fi.se && y >= paper[i].se.fi && y <= paper[i].se.se;
}
int main() {
IOS;
while (cin >> n, m = 0, n) {
rep(i, 1, n) h[i].resize(0), h[i + n].resize(0), id[i] = deg[i] = deg[i + n] = v[i + n] = 0;
rep(i, 1, n) cin >> paper[i].fi.fi >> paper[i].fi.se >> paper[i].se.fi >> paper[i].se.se;
rep(i, 1, n) {
int x, y; cin >> x >> y;
rep(j, 1, n) if (check(j, x, y)) h[i + n].push_back(j), h[j].push_back(i + n), ++deg[j], ++deg[i + n];
}
while (1) {
int c = 0;
rep(i, 1, n << 1) if (deg[i] == 1) { c = i; break; }
if (!c) break; --deg[c]; ++m;
if (c <= n) for (auto &y : h[c]) { if (!v[y]) { id[c] = y - n, v[c = y] = 1; break; } }
else for (auto &y : h[c]) if (!id[y]) { id[y] = c - n, v[c = y] = 1; break; }
for (auto &y : h[c]) --deg[y];
}
cout << "Heap " << ++_ << '\n';
if (m) rep(i, 1, n) { if (id[i]) cout << '(' << char('A' + i - 1) << ',' << id[i] << ") "; }
else cout << "none"; cout << '\n' << '\n';
}
return 0;
}