program ideone;
Type simple = array[1..20, 1..20] of shortint;
var arr:simple; m, n, k, i, j: shortint;
begin
readln(m, n);
for i:=1 to m do
for j:=1 to n do
read(arr[i, j]);
readln();
read(k);
for i:=1 to m do begin
for j:=n-k+1 to n do write(arr[i, j], ' ');
writeln(); end;
for i:=1 to m do begin
for j:=1 to k do write(arr[i, j], ' ');
writeln(); end;
end.
cHJvZ3JhbSBpZGVvbmU7CgpUeXBlIHNpbXBsZSA9IGFycmF5WzEuLjIwLCAxLi4yMF0gb2Ygc2hvcnRpbnQ7CnZhciBhcnI6c2ltcGxlOyBtLCBuLCBrLCBpLCBqOiBzaG9ydGludDsKCmJlZ2luCglyZWFkbG4obSwgbik7Cglmb3IgaTo9MSB0byBtIGRvCgkJZm9yIGo6PTEgdG8gbiBkbwoJCQlyZWFkKGFycltpLCBqXSk7CglyZWFkbG4oKTsKCXJlYWQoayk7CQoJCglmb3IgaTo9MSB0byBtIGRvIGJlZ2luCgkJZm9yIGo6PW4taysxIHRvIG4gZG8gd3JpdGUoYXJyW2ksIGpdLCAnICcpOwoJCXdyaXRlbG4oKTsgZW5kOwoJCglmb3IgaTo9MSB0byBtIGRvIGJlZ2luCgkJZm9yIGo6PTEgdG8gayBkbyB3cml0ZShhcnJbaSwgal0sICcgJyk7CgkJd3JpdGVsbigpOyBlbmQ7CmVuZC4=