#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int monthTable[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int monthTable2[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};

bool isLeapYear(int year){
	if(year % 4 == 0){
		if(year % 100 == 0){
			if(year % 400 == 0){
				return true;
			}else{
				return false;
			}
		}else{
			return true;
		}
	}else{
		return false;
	}
}

int main(){

	long long int sum,tmp,year,month,day,b,ka,t,w,ki,NUMBER = 735224;
	int count,status;
	char buf[100];

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		count = 0;

		for(int i = 0;buf[i] != '\0';i++){
			if(buf[i] == '.')count++;
		}

		sum = 0;
		if(count == 2){
			status = 0;
			tmp = 0;

			for(int i = 0; buf[i] != '\0';i++){
				if(buf[i] >= '0' && buf[i] <= '9'){
					tmp = 10*tmp+(buf[i]-'0');

					if(buf[i+1] == '\0'){
						day = tmp;
					}
				}else{
					if(status == 0){
						year = tmp;
					}else{
						month = tmp;
					}
					status++;
					tmp = 0;
				}
			}

			if(year == 2012){
				sum = day - 21;
			}else{

				sum += 10;

				for(int i = 2013; i <= year-1; i++){
					if(isLeapYear(i))sum += 366;
					else{
						sum += 365;
					}
				}

				for(int i = 1; i <= month-1; i++){
					if(i == 2 && isLeapYear(year) == true){
						sum += 29;
					}else{
						sum += monthTable[i];
					}
				}
				sum += day;
			}

			printf("%lld.",(sum/144000)%13);
			sum %= 144000;
			printf("%lld.",sum/7200);
			sum %= 7200;
			printf("%lld.",sum/360);
			sum %= 360;
			printf("%lld.",sum/20);
			sum %= 20;
			printf("%lld\n",sum);

		}else{ //????????´?????\??????????????´???
			status = 0;
			tmp = 0;

			for(int i = 0; buf[i] != '\0';i++){
				if(buf[i] >= '0' && buf[i] <= '9'){
					tmp = 10*tmp + (buf[i] - '0');

					if(buf[i+1] == '\0'){
						ki = tmp;
					}
				}else{
					if(status == 0){
						b = tmp;
					}else if(status == 1){
						ka = tmp;
					}else if(status == 2){
						t = tmp;
					}else if(status == 3){
						w = tmp;
					}
					status++;
					tmp = 0;
				}
			}

			sum = 144000*b + 7200*ka + 360*t + 20*w + ki + NUMBER;

			year = 0,month = 1;

			for(int i = 0;sum > 366; i++){
				if(isLeapYear(i)){
					sum -= 366;
				}else{
					sum -= 365;
				}
				year++;
			}

			if((sum <= 365) || (sum == 366 && isLeapYear(year))){

				if(isLeapYear(year)){
					for(int i = 1; i <= 12 && sum > monthTable2[i];i++){
						sum -= monthTable2[i];
						month++;
					}
				}else{
					for(int i = 1; i <= 12 && sum > monthTable[i];i++){
						sum -= monthTable[i];
						month++;
					}
				}
			}else{
				year++;
				month = 1;
				sum = 1;
			}
			printf("%lld.%lld.%lld\n",(year)%10000001,month,sum);
		}
	}
	return 0;
}