#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main(){
long b,ka,t,w,ki,y,m,d,j,y1,y2,a1,a2,a3,a4,a5,a6,a7;
string::size_type j1,j2,j3,j4;
string s;
stringstream ss;
while(cin>>s){
if(s=="#")break;
j1=s.find('.');
j2=s.find('.',j1+1);
j3=s.find('.',j2+1);
ss.str("");ss.clear();ss<<s.substr(0,j1);ss>>y;
ss.str("");ss.clear();ss<<s.substr(j1+1,j2-j1);ss>>m;
ss.str("");ss.clear();ss<<s.substr(j2+1,j3-j2);ss>>d;
if(j3==string::npos){
if(m<3){m+=12;y--;}
y1=y/100;y2=y%100;
if(y1>50000)j=(long(36524.25*(y1-50000)))%1872000+long(365.25*y2)+long(30.6*(m+1))+d+277214;
else j=(long(36524.25*y1))%1872000+long(365.25*y2)+long(30.6*(m+1))+d+1136714;
ki=j%20;j-=ki;j/=20;
w=j%18;j-=w;j/=18;
t=j%20;j-=t;j/=20;
ka=j%20;j-=ka;j/=20;
b=j%13;
cout<<b<<"."<<ka<<"."<<t<<"."<<w<<"."<<ki<<endl;
}else{
j4=s.find('.',j3+1);
b=y;ka=m;t=d;
ss.str("");ss.clear();ss<<s.substr(j3+1,j4-j3);ss>>w;
ss.str("");ss.clear();ss<<s.substr(j4+1);ss>>ki;
j=(((b*20+ka)*20+t)*18+w)*20+ki+735163;
a1=j/146097;j%=146097;
if(j==146096){a2=3;j=36524;}else{a2=j/36524;j%=36524;}
a3=j/1461;j%=1461;
if(j==1460){a4=3;j=365;}else{a4=j/365;j%=365;}
a5=j/153;j%=153;
a6=j/61;j%=61;
a7=j/31;j%=31;
y=a1*400+a2*100+a3*4+a4;
if(m=a5*5+a6*2+a7+3,m>12){m-=12;y++;}
cout<<y<<"."<<m<<"."<<j+1<<endl;
}
}
return 0;
}