#include<iostream>
#include<string> 
using namespace std;
int main(){
  long long y,m,d,b,ka,t,w,ki;
  int i,j,k,p;
  long long day,base=0,ba=1872000;
  int mo[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  string str;
  cin>> str;
  while(str[0]!='#'){
    y=0;m=0;d=0;i=0;day=0;p=0;
    while(str[i]!='\0'){
      if(str[i]=='.') p++;
      i++;
    }
    if(p==2){
      i=0;
      while(str[i]!='.') i++;
      for(j=0;j<i;j++){
	y*=10;
	y+=str[j]-'0';
      }
      i++;
      k=i;
      while(str[i]!='.') i++;
      for(j=k;j<i;j++){
	m*=10;
	m+=str[j]-'0';
      } 
      i++;
      k=i;
      while(str[i]!='\0') i++;
      for(j=k;j<i;j++){
	d*=10;
	d+=str[j]-'0';
      }
      //cout << y << " " << m << " " << d << endl;
      if(y==2012) {
	day=d-21;
      }else{
	day=10;
	for(i=2013;i<y;i++)
	  if((i%4==0&&i%100!=0)||i%400==0) day+=366;
	  else day+=365;
	for(i=1;i<m;i++) day+=mo[i];
	if(2<m&&((y%4==0&&y%100!=0)||y%400==0)) day++;
	day+=d;
      }
      while(ba<day) day-=ba;
      b=day%(13*20*20*18*20)/(20*20*18*20);
      ka=day%(20*20*18*20)/(20*18*20);
      t=day%(20*18*20)/(18*20);
      w=day%(18*20)/20;
      ki=day%(20);
      cout << b << "." << ka << "." << t << "." << w << "." << ki << endl;
    }else{
      i=0;b=0;ka=0;t=0;w=0;ki=0;
      while(str[i]!='.') i++;
      for(j=0;j<i;j++){
	b*=10;
	b+=str[j]-'0';
      }
      i++;
      k=i;
      while(str[i]!='.') i++;
      for(j=k;j<i;j++){
	ka*=10;
	ka+=str[j]-'0';
      } 
      i++;
      k=i;
      while(str[i]!='.') i++;
      for(j=k;j<i;j++){
	t*=10;
	t+=str[j]-'0';
      }
      i++;
      k=i;
      while(str[i]!='.') i++;
      for(j=k;j<i;j++){
	w*=10;
	w+=str[j]-'0';
      } 
      i++;
      k=i;
      while(str[i]!='\0') i++;
      for(j=k;j<i;j++){
	ki*=10;
	ki+=str[j]-'0';
      }
      //cout << b << "." << ka << "." << t << "." << w << "." << ki << endl;
      day =b*20*20*18*20+ka*20*18*20+t*18*20+w*20+ki;
      
      y=2012;m=12;d=21;
      if(day<=10) d+=day;
      else{
	day-=10;
	y=2013;
	int f1=0;
	while(day>365&&f1==0){
	  if((y%4==0&&y%100!=0)||y%400==0) 
	    if(day==366) f1=1;
	    else day-=366;
	  else day-=365;
	  if(f1==0)y++;
	}
	m=1;int flag=0;
	//cout << day << endl;
	while(day>mo[m]&&flag==0){
	  if(m==2&&((y%4==0&&y%100!=0)||y%400==0)) {
	    if(day>29) {
	      day-=29;
	      m++;
	      
	    }else{
	      flag=1;
	    }
	  }else{
	    day-=mo[m];
	    m++;
	  }
	}
	//cout << day << endl;
	d=day;
      }
      cout << y << "." << m << "." << d << endl;
    }
    cin >> str;
  }
  return 0;
}