#include<stdio.h>
int main(void){
int year,month,day,c,Y,W,i,j,w;
int t[]={31,0,31,30,31,30,31,31,30,31,30,31};
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
t[1]=29;
else
t[1]=28;
for(month=1;month<=12;month++){
if(month<3){
c=((int)(year-1)/100);
Y=(year-1)-((int)((year-1)/100))*100;
w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(26*(month+12+1)/10));
W=w%7;
}
else if(month>=3){
c=((int)(year/100));
Y=year-((int)(year/100))*100;
w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(26*(month+1)/10));
W=w%7;
}
i=(W+7-1)%7;
printf("\n\n %d\n",month);
printf("*Mon Tue Wed Thu Fri Sat Sun\n");
for(j=1;j<=(W+7-1)%7;j++)
printf(" ");
for(day=1;day<=t[month-1];day++){
i++;
printf("%4d",day);
if(i%7==0)
printf("\n");
}
}
return 0;
}