n, m, k, l, d = map(int,input().split())#输入相关参数 clmt = [list(map(int,input().split())) for _ in range(d)]#输入交头接耳同学的位置 a, b = dict(), dict() for x,y,p,q in clmt:#记录分开所有交头接耳同学,需要放置的横纵通道数量,及每条通道隔开的人数 if x==p:#纵向通道 b[min(y,q)] = b.setdefault(min(y,q),0)+1 if y==q:#横向通道 a[min(x,p)] = a.setdefault(min(x,p),0)+1 if len(a)>k:#若可设立横向通道数不足,则升序输出k个分开最多同学的组合 ans = [] for c in sorted(list(a.items()),key=lambda c:(-c[1],c[0]))[:k]: ans += [c[0]] print(' '.join(map(str,sorted(ans)))) else:#若可设立通道数足够,则升序输出所有 print(' '.join(map(str,sorted(a.keys())))) if len(b)>l:#若可设立纵向通道数不足,则升序输出l个分开最多同学的组合 ans = [] for c in sorted(list(b.items()),key=lambda c:(-c[1],c[0]))[:l]: ans += [c[0]] print(' '.join(map(str,sorted(ans)))) else:#若可设立通道数足够,则升序输出所有 print(' '.join(map(str,sorted(b.keys()))))