#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e3 + 10, M = N * 2;
const int INF = 0x3f3f3f3f3f3f3f3f;
void print(stack<int>& tree)
{
stack<int> tmp;
while(tree.size())
{
tmp.push(tree.top());
tree.pop();
}
int ff = 1;
while(tmp.size())
{
if(ff)
{
cout << tmp.top();
ff = 0;
}
else cout << ' '<< tmp.top() ;
tmp.pop();
}
cout << endl;
}
signed main()
{
int n, m, k;
cin >> n >> m >> k;
queue<int> q;
for(int i = 0; i < n; i ++)
{
int x; cin >> x;
q.push(x);
}
stack<int> box;
stack<int> tree;
while(q.size() || box.size())
{
// 优先使用盒子里面的松针
while(box.size() && (tree.size() == 0 || box.top() <= tree.top()))
{
tree.push(box.top());
box.pop();
if(tree.size() == k) print(tree);
}
// 盒子里面的不能用,用推送器上面的
if(q.size())
{
if(tree.size() == 0 || q.front() <= tree.top())
{
tree.push(q.front());
q.pop();
if(tree.size() == k) print(tree);
}
else
{
if(box.size() == m) print(tree);
else
{
box.push(q.front());
q.pop();
}
}
}
else print(tree);
}
if(tree.size()) print(tree);
return 0;
}