#include <bits/stdc++.h>
using namespace std;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

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

int months[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int leapmonths[12] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main() {

    string s;

    const long long  int baseday = (2012*365 + 2012/4 - 2012/100 + 2012/400 + 366-11);

    while(1){

        cin >> s;

        if(s[0] == '#'){
            break;
        }

        vector<string> vec = split(s,'.');

        if(vec.size() == 5){

            int a[5];//b,ka,t,w,ki

            for(int i=0;i<5;i++){
                stringstream ss;
                ss << vec[i];
                ss >> a[i];
            }

            long long int allday = 0;

            allday = a[0]*20*20*18*20 + a[1]*20*18*20 + a[2]*18*20 + a[3]*20 + a[4];

            if(allday>=11){
                allday -= 11;
                int year,month,day;
                year = 2013;

                while(1){
                    if(is_Leapyear(year) && allday >= 366){
                        year++;
                        allday -= 366;
                    }
                    else if(!is_Leapyear(year) && allday >= 365){
                        year++;
                        allday -= 365;
                    }
                    else{
                        break;
                    }
                }

                /*+(static_cast<int>(allday/(365+365+365+366))*4);
                allday = allday % (365+365+365+366);
                allday = allday + (year)/100 - (year)/400 -(2000)/100 + 2000/400;


                int byear = year;


                year += allday/365;

                allday %= 365;

                if(year - byear == 4 && allday != 0){
                    allday--;
                }

                 */


                month = 1;
                day = 1;
                if(is_Leapyear(year)){
                    for(int i=0;i<12;i++){
                        if(allday>=leapmonths[i]){
                            allday-=leapmonths[i];
                            month++;
                        }
                        else{
                            break;
                        }
                    }
                    day += allday;
                    printf("%d.%d.%d\n",year,month,day);
                }
                else{
                    for(int i=0;i<12;i++){
                        if(allday>=months[i]){
                            allday-=months[i];
                            month++;
                        }
                        else{
                            break;
                        }
                    }
                    day += allday ;
                    printf("%d.%d.%d\n",year,month,day);
                }
            }
            else{
                printf("2012.12.%lld\n",21+allday);
            }

        }

        else{

            long long int b[3];//year,month,day

            for(int i=0;i<3;i++){
                stringstream ss;
                ss << vec[i];
                ss >> b[i];
            }

            long long int allday = (b[0] % 1872000 * 365 + b[0]/4 - b[0]/100 + b[0]/400);

            if(is_Leapyear(b[0])){
                allday--;
            }

            for(int i=0;i<b[1]-1;i++){
                if(is_Leapyear(b[0])){
                    allday += leapmonths[i];
                }
                else{
                    allday += months[i];
                }
            }

            allday += b[2];

            allday -= baseday;

            allday %= 1872000;

            long long int ba,ka,t,w,ki;

            ba = allday/144000;

            allday %= 144000;

            ka = allday/7200;

            allday %= 7200;

            t = allday/360;

            allday %= 360;

            w = allday/20;

            allday %= 20;

            ki = allday;

            printf("%lld.%lld.%lld.%lld.%lld\n",ba,ka,t,w,ki);
        }

    }



    return 0;
}

Measured memory_bytes: 3356