#include<bits/stdc++.h>
#define LL long long int
#define INF 734858
using namespace std;
int main(void)
{
	LL b,ka,t,w,ki,y,m,d,sum,cnt,mon,day,year;
	LL i,j,k;
	LL maya[5]={144000,7200,360,20,1};
	LL month[2][12]={
					{31,28,31,30,31,30,31,31,30,31,30,31},
					{31,29,31,30,31,30,31,31,30,31,30,31}
					};
	char s[100];
	while(1) {
		cin>>s;
		if(s[0]=='#') break;
		cnt=0;
		for(i=0;i<strlen(s);i++) {
			if(s[i]=='.') cnt++;
		}
		if(cnt==2) { //?\?????????????
			sum=0;
			string sum2;
			sum2=s[0];
			for(i=1;i<strlen(s);i++) {
				if(s[i]=='.') break;
				else sum2+=s[i];
			}
			int mx;
			mx=atoi(sum2.c_str());
			//sum=?\????????¨? 
			for(i=1;i<mx;i++) {
				if(i%4==0&&i%100!=0||i%400==0) sum+=366;
				else sum+=365;
			}
			//?????°????¨????
			int f=0;
			for(i=0;i<strlen(s);i++) {
				if(s[i]=='.'&&s[i+2]=='.') {
					sum2=s[i+1];
					if(f==0) mon=atoi(sum2.c_str());
					else day=atoi(sum2.c_str());
					f=1;
				}
				else if(s[i]=='.'&&s[i+2]!='.') {
					sum2=s[i+1];
					sum2+=s[i+2];
					if(f==0) mon=atoi(sum2.c_str());
					else day=atoi(sum2.c_str());
					f=1;
				}
			}
			//cout<<mon<<" "<<day<<endl;
			//?????°???sum????¶?????????????????????´??¨????????§????????¨?????????????????????
			int test=0;
			for(i=0;i<mon-1;i++) {
				if(mx%4==0&&mx%100!=0||mx%400==0) sum+=month[1][i];
				else sum+=month[0][i];
			}
			//??\????????????????????§???????????§??????????????§?????\??§?¨????
			sum+=day,sum-=INF;
			b=sum/maya[0],sum=sum%maya[0];
			ka=sum/maya[1],sum=sum%maya[1];
			t=sum/maya[2],sum=sum%maya[2];
			w=sum/maya[3],ki=sum%maya[3];
			cout<<b%13<<"."<<ka%20<<"."<<t%20<<"."<<w%18<<"."<<ki%20<<endl;
		}
		else { //??????????\????
			sum=0;
			LL swi=1,x;
			string sum3;
			//????????????????????§???
			if(s[1]=='.') sum3=s[0],sum+=atoi(sum3.c_str())*maya[0];
			else if(s[1]!='.') sum3=s[0],sum3+=s[1],sum+=atoi(sum3.c_str())*maya[0];
			for(i=0;i<strlen(s);i++) {
				if(s[i]=='.'&&s[i+2]=='.') {
					sum3=s[i+1];
					sum+=atoi(sum3.c_str())*maya[swi];
					swi++;					
				}
				else if(s[i]=='.'&&s[i+2]!='.') {
					sum3=s[i+1],sum3+=s[i+2];
					sum+=atoi(sum3.c_str())*maya[swi];	
					swi++;		
				}
			}
			//cout<<sum<<endl;
			int zan=10;//zan???21????£????10???????´????????????????sum?????????10???????????????
			if(sum<11) {
				cout<<"2012.12."<<sum+21<<endl;
			}
			else {
				sum-=10;
				//cout<<sum<<endl;
				LL suu=2013;
				while(1) {
					if(suu%4==0&&suu%100!=0||suu%400==0) {
						if(sum>366) {
							sum-=366;
						}
						else if(sum==366) {
							sum-=366;
							mon=12,day=31;
						}
						else {
							mon=1;
							for(i=0;i<12;i++) {
							//	printf("sum=%lld day=%lld month=%lld\n",sum,month[1][i],mon);
								if(sum>=month[1][i]&&mon-1>=i) {
									if(sum-month[1][i]==0) break;
									sum-=month[1][i];
									mon++;
								}
							}
							day=sum;
							sum=0;
						}
					}
					else {
						if(sum>365) {
							sum-=365;
						}
						else if(sum==365) {
							sum-=365;
							mon=12,day=31;
						}
						else {
							mon=1;
							//cout<<"sum=="<<sum<<endl;
							//printf("sum=%lld day=%lld month=%lld\n",sum,month[0][i],mon);
							for(i=0;i<12;i++) {
								if(sum>=month[0][i]&&mon-1>=i) {
									if(sum-month[0][i]==0) break;
									sum-=month[0][i];
									mon++;
									//cout<<"sum=="<<sum<<endl;
								}
							}
							day=sum;
							sum=0;
						}
					}
					if(sum==0) break;
					suu++;
				}
				cout<<suu<<"."<<mon<<"."<<day<<endl;
			}
		}
	}
}
	

Measured memory_bytes: 3204