#include <iostream>
#include <string>
#include <sstream>
using namespace std;
 
bool is_leap(int y)
{
    return (y%400==0 || (y%4==0 && y%100!=0));
}
 
int main()
{
    while(true){
        string S;
        cin >> S;
 
        if(S=="#")
            break;
 
        int cnt = 0;
 
        while(true){
            int loc = S.find(".");
 
            if(loc==string::npos)
                break;
 
            S.replace(loc, 1, " ");
            cnt++;
        }
 
        if(cnt==4){
            istringstream is(S);
            int b, ka, t, w, ki;
            is >> b >> ka >> t >> w >> ki;
 
            int KI = (((b*20+ka)*20+t)*18+w)*20+ki;
 
            int y = 2012;
            int m = 12;
            int d = 21;
 
            if(KI<11){
                d += KI;
                KI = 0;
            }
            else{
                y = 2013;
                m = 1;
                d = 1;
                KI -= 11;
            }
 
            while(true){
                if(is_leap(y) && KI>=366){
                    y++;
                    KI -= 366;
                }
                else if(!is_leap(y) && KI>=365){
                    y++;
                    KI -= 365;
                }
                else{
                    break;
                }
            }
 
            while(true){
                if((m==1 || m==3 || m==5 || m==7 || m==8 || m==10) && KI>=31){
                    m++;
                    KI -= 31;
                }
                else if((m==4 || m==6 || m==9 || m==11) && KI>=30){
                    m++;
                    KI -= 30;
                }
                else if(m==2 && is_leap(y) && KI>=29){
                    m++;
                    KI -= 29;
                }
                else if(m==2 && !is_leap(y) && KI>=28){
                    m++;
                    KI -= 28;
                }
                else{
                    break;
                }
            }
 
            if(KI>0){
                d += KI;
                KI = 0;
            }
 
            cout << y << '.' << m << '.' << d << endl;
        }
        else if(cnt==2){
            istringstream is(S);
            int y, m, d;
            is >> y >> m >> d;
 
            long long D = 0;
 
            if(y==2012&&m==12){
                D = d-21;
            }
            else{
                D = 11;
 
                for(int i=2013; i<y; i++){
                    if(is_leap(i)){
                        D += 366;
                    }
                    else{
                        D += 365;
                    }
                }
 
                for(int i=1; i<m; i++){
                    if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10){
                        D += 31;
                    }
                    else if(i==4 || i==6 || i==9 || i==11){
                        D += 30;
                    }
                    else if(i==2 && is_leap(y)){
                        D += 29;
                    }
                    else if(i==2 && !is_leap(y)){
                        D += 28;
                    }
                    else{
                        break;
                    }
                }
 
                D += (d-1);
            }
 
            int ki = D%20;
            D /= 20;
 
            int w = D%18;
            D /= 18;
 
            int t = D%20;
            D /= 20;
 
            int ka = D%20;
            D /= 20;
 
            int b = D%13;
 
            cout << b << '.' << ka << '.' << t << '.' << w << '.' << ki << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 1228