implement multi-pass k-way merge