package T1;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,m;
n = sc.nextInt();
m=sc.nextInt();
/*
* 3 4
* n行
* m列
* 0 4 8
*
* 1 5 9
* 2 6 10
*
*/
int arr[]= new int [n*m];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int m1=0;//第几列开始
int count=0;
for ( m1 =0; m1 < m; m1++) {
for (int i = n-1; i >=0; i--) {
System.out.print(arr[i*m+m1]+" ");
count++;
if(count%3==0) {
System.out.print('\n');
}
}
}
}
}