#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin>>n,n!=0){
for(int i=1;i<=n;i++){
if(i>1){
int count=0;
for(int j=i;j>1;j--){
cout<<j<<" ";
count++;
}
for(int j=1;j<=n&&count<n;j++,count++){
cout<<j<<" ";
}
cout<<endl;
}
else{
for(int i=1;i<=n;i++) cout<<i<<" ";
cout<<endl;
}
}
cout<<endl;
}
}