#include <iostream>
#include <algorithm>

const int MAX = 1e3 + 10;

struct gate {
    int pos;
    int n;
};

gate r[MAX], c[MAX];

bool cmp1(gate a, gate b) {
    return a.n > b.n;
}

bool cmp2(gate a, gate b) {
    return a.pos < b.pos;
}

int main() {
    int M, N, K, L, D;
    std::cin >> M >> N >> K >> L >> D;
    for (int i = 1; i <= D; i++) {
        int x, y, p, q;
        std::cin >> x >> y >> p >> q;
        if (x == p && abs(y - q) == 1) {
            c[y + q >> 1].pos = y + q >> 1;
            c[y + q >> 1].n++;
        } else if (y == q && abs(x - p) == 1) {
            r[x + p >> 1].pos = x + p >> 1;
            r[x + p >> 1].n++;
        }
    }
    
    std::sort(r + 1, r + 1 + N, cmp1);
    std::sort(c + 1, c + 1 + N, cmp1);
    std::sort(r + 1, r + 1 + K, cmp2);
    std::sort(c + 1, c + 1 + L, cmp2);
    
    for (int i = 1; i <= K; i++) {
        std::cout << r[i].pos << ' ';
    }
    std::cout << std::endl;
    for (int i = 1; i <= L; i++) {
        std::cout << c[i].pos << ' ';
    }
    

    
    std::cout << std::endl;
    return 0;
}