// 贪心
#include <bits/stdc++.h>
using namespace std;

int main() {
    unordered_map<int, int> row_cnt, col_cnt;
    vector<pair<int, int>> row, col;
    int n, m, k, l, d;
    cin >> n >> m >> k >> l >> d;
    int xi, yi, pi, qi;
    while (d--) {
        cin >> xi >> yi >> pi >> qi;
        if (xi == pi) {
            row_cnt[min(yi, qi)]++;
        }
        if (yi == qi) {
            col_cnt[min(xi, pi)]++;
        }
    }
    for (auto& [k, n] : col_cnt) {
        col.emplace_back(k, n);
    }
    for (auto& [k, n] : row_cnt) {
        row.emplace_back(k, n);
    }
    sort(col.begin(), col.end(),[](const pair<int, int>& a,const pair<int, int>& b) {
        if (a.second != b.second) {
            return a.second > b.second;
        }
        return a.first < b.first;
    });
    sort(row.begin(), row.end(),[](const pair<int, int>& a,const pair<int, int>& b) {
        if (a.second != b.second) {
            return a.second > b.second;
        }
        return a.first < b.first;
    });
    vector<int> rows, cols;
    for (int i = 0; i < k; i++) {
        cols.emplace_back(col[i].first);
    }
    for (int i = 0; i < l; i++) {
        rows.emplace_back(row[i].first);
    }
    sort(cols.begin(), cols.end());
    sort(rows.begin(), rows.end());
    for (int i = 0; i < k; i++) {
        cout << cols[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < l; i++) {
        cout << rows[i] << " ";
    }
}

贪心