#include <stdio.h>

typedef unsigned long long li;

int table[2][13] = {{365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
					{366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

li conv(int y, int m, int d)
{
	li ret;
	int i;
	li t = y - 1;
	ret = 0;
	ret += t * 365 + (t / 4) - (t / 100) + (t / 400);
	
	if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)){
		for (i = 1; i <= m - 1; i++){
			ret += table[1][i];
		}
	}
	else {
		for (i = 1; i <= m - 1; i++){
			ret += table[0][i];
		}
	}
	ret += d;
	return (ret);
}

int main(void)
{
	char rec[256];
	li t;
	int i, j;
	int dot;
	while (scanf("%s", rec), rec[0] != '#'){
		dot = 0;
		for (i = 0; rec[i] != '\0'; i++){
			if (rec[i] == '.') dot++;
		}
		if (dot == 2){
			int year, month, day;
			sscanf(rec, "%d.%d.%d", &year, &month, &day);
			t = (conv(year, month, day) - conv(2012, 12, 21)) % (1872000);
			
			printf("%lld.", t / (20 * 20 * 20 * 18));
			t %= (20 * 20 * 20 * 18);
			printf("%lld.", t / (20 * 20 * 18));
			t %= (20 * 20 * 18);
			printf("%lld.", t / (20 * 18));
			t %= (20 * 18);
			printf("%lld.", t / 20);
			t %= 20;
			printf("%lld\n", t);
		}
		else {
			li b, ka, tt, w, ki;
			int y, sum;
			sscanf(rec, "%lld.%lld.%lld.%lld.%lld", &b, &ka, &tt, &w, &ki);
			t = b * (20 * 20 * 20 * 18) + ka * (20 * 20 * 18) + tt * (20 * 18) + w * 20 + ki + conv(2012, 12, 21);
			
			for (i = 0; i < 10000; i++){
				if (t <= i * 365 + (i / 4) - (i / 100) + (i / 400)) break;
			}
			y = i;
			printf("%d.", y);
			y--;
			t -= (y * 365 + (y / 4) - (y / 100) + (y / 400));
			sum = 0;
			y++;
				for (j = 1; j <= 12; j++){
					if (t > table[y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)][j]){
						t -= table[y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)][j];
					}
					else {
						break;
					}
				}
				printf("%d.%lld\n", j, t);
		}
	}
	
	return (0);
}