#include<iostream>
#include <stdio.h>
#include <time.h>
#include<string>
using namespace std;
int main(){
  int f,i,p,count,s,q,type1,type2,type3,type4;
 for(;;){
      count=0;
      s=0;
      p=0;
       q=0;
     cin>>f;
      type1=(f==1||f==10);type2=(f==2||f==3||f==11);type3=(f==4||f==7);type4=(f==9||f==12);
          cout<<"  S  M  T  W  t  F  s"<<endl;
          cout<<endl;
          if(type1){
              count=-1;
              cout<<"   ";
          }
          else if(type2){
          count=-4;
          cout<<"            ";
          }
          else if(type4){
          count=-6;
          cout<<"                  ";
          }
          else if(f==5){
          count=-2;
          cout<<"      ";
          }
          else if(f==6){
              count=-5;
          cout<<"               ";
          }
          else if(f==8){
          count=-3;
          cout<<"         ";
          }if(f==2){
           q=28;
           }
           else if(f==1||f==3||f==5||f==7||f==8||f==10||f==12){
           q=31;
           }    
           else if(f==4||f==6||f==9||f==11){
           q=30;
           }
          for(i=1;i<=37;i++){
              count++;
              if(count<1){
              continue;
              }
          printf("%3d",count);
          if(i%7==0){
          cout<<endl;
          }
          if(count==q){
              break;
              }
          }
          cout<<endl<<endl;
          }
 return 0;
}
