
#include<iostream>
#include<sstream>
#include<algorithm>
using namespace std;

long long int dayCount(long long int y, long long int m, long long int d)
{
    long long int sum;
    long long int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    for(int i=1; i<12; i++) days[i] += days[i-1];
    y--;
    sum = 365*y + days[m-1] + d + y/4 - y/100 + y/400;
    y++;
    if((y%4==0 && y%100!=0) || (y%400==0)) if(m>=3) sum++;
    return sum;
}
long long int dayCount(long long int b, long long int ka, long long int t, long long int w, long long int ki)
{
    long long int sum;
    long long int days[5]={1,20,18,20,20};
    for(int i=2; i<5; i++) days[i] *= days[i-1];
    sum = ki + w*days[1] + t*days[2] + ka*days[3] + b*days[4];
    return sum;
}

string ADtoMaya(int y, int m, int d)
{
    stringstream date;
    long long int now = dayCount(y,m,d);
    long long int dif = now - dayCount(2012,12,21);
    dif %= dayCount(13,0,0,0,0);

    int b,ka,t,w,ki;
    int days[5]={1,20,18,20,20};
    for(int i=2; i<5; i++) days[i] *= days[i-1];
    b = dif/days[4];
    dif %= days[4];
    ka = dif/days[3];
    dif %= days[3];
    t = dif/days[2];
    dif %= days[2];
    w = dif/days[1];
    dif %= days[1];
    ki = dif/days[0];
    date<<b<<"."<<ka<<"."<<t<<"."<<w<<"."<<ki;
    return date.str();
}

string MayatoAD(int b, int ka, int t, int w, int ki)
{
    stringstream date;
    long long int now = dayCount(b,ka,t,w,ki);
    now += dayCount(2012,12,21);

    int y,m,d;
    int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    y = 1;
    while(now > 365) {
        bool leap = (y%4==0 && y%100!=0) || (y%400==0);
        if(leap && now==366) break;
        now -= 365 + leap;
        y++;
    }
    bool leap = (y%4==0 && y%100!=0) || (y%400==0);
    for(int i=1; i<=12; i++) {
        m = i;
        if(now <= days[i]) break;
        now -= days[i];
        if(leap && i==2) {
            if(now==1) {
                now = 29;
                break;
            }
            now--;
        }
    }
    d = now;
    date<<y<<"."<<m<<"."<<d;
    return date.str();
}

int main()
{
    string date;
    while(getline(cin, date), date!="#") {
        int y,m,d;
        int b,ka,t,w,ki;
        stringstream ss;
        string ans;

        while(date.find(".")!=string::npos) {
            date.replace(date.find("."), 1, " ");
        }

        ss.str(date);
        if(count(date.begin(), date.end(), ' ') == 4) {
            ss>>b>>ka>>t>>w>>ki;
            ans = MayatoAD(b, ka, t, w, ki);
        } else {
            ss>>y>>m>>d;
            ans = ADtoMaya(y, m, d);
        }

        cout<<ans<<endl;
    }
}