#include <iostream>
using namespace std;
int main(void)
{
int M,N,row,col;
while(cin>>M>>N){
int *arrA=new int[M*N];
int *arrB=new int[M*N];
for(row=1;row<=M;row++)
{
for(col=1;col<=N;col++)
{
cin>>arrA[(row-1)*N+(col-1)];
}
}
for(row=1;row<=N;row++)
for(col=1;col<=N;col++)
arrB[(col-1)*N+(row-1)]=arrA[(row-1)+(col-1)*N];
for(row=1;row<=N;row++)
{
for(col=1;col<=M;col++)
{
cout<<arrB[(col-1)*N+(row-1)]<<" ";
}
cout<<endl;
}
}
return 0;
}