#include <bits/stdc++.h>
using namespace std;
long long m, n, k, ll, d;
long long a[1005][1005];
struct node
{
long long id, sum;
}h[1005], l[1005];
long long ansl[5005], ansh[5005];
long long cnt = 0;
bool cmp(node x, node y)
{
return x.sum > y.sum;
}
int main()
{
cin >> n >> m >> k >> ll >> d;
for(int i = 1; i <= d; i ++)
{
long long x, y, xx, yy;
cin >> x >> y >> xx >> yy;
a[x][y] = a[xx][yy] = ++ cnt;
}
for(int i = 1; i < n; i ++)
{
h[i].id = i;
for(int j = 1; j <= m; j ++)
{
if(a[i][j] == a[i + 1][j] && a[i][j] != 0) h[i].sum ++;
}
}
for(int i = 1; i < m; i ++)
{
l[i].id = i;
for(int j = 1; j <= n; j ++)
{
if(a[j][i] == a[j][i + 1] && a[j][i] != 0) l[i].sum ++;
}
}
sort(h + 1, h + n + 1, cmp);
sort(l + 1, l + m + 1, cmp);
for(int i = 1; i <= k; i ++) ansh[i] = h[i].id;
for(int j = 1; j <= ll; j ++) ansl[j] = l[j].id;
sort(ansh + 1, ansh + k + 1);
sort(ansl + 1, ansl + ll + 1);
for(int i = 1; i <= k; i ++)
{
cout << ansh[i] << " ";
} cout << endl;
for(int i = 1; i <= ll; i ++)
{
cout << ansl[i] << " ";
}
}