#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

struct maya {
    ll b, ka, t, w, ki;
};

struct we {
    ll y, m, d;
};

ll year2d(ll x);
ll west2d(we x);
ll maya2d(maya x);
ll is_uru(ll y);

ll month_table[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll maya_table[] = {1, 20, 20 * 18, 20 * 20 * 18, 20 * 20 * 20 * 18};
ll maya_mod[]   = {20, 20 * 18, 20 * 20, 20 * 20 * 18, 13};

ll west_origin;

int main()
{
    ll d;
    ll a;
    maya m;
    we w;

    west_origin = west2d((we){2012, 12, 21});

    while (scanf("%lld", &a) != 0) {
        if (a < 13) {
            m.b = a;
            scanf(". %lld . %lld . %lld . %lld",
                  &m.ka, &m.t, &m.w, &m.ki);

            d = maya2d(m) + west_origin;

            //year
            ll valid = 0;
            ll invalid = 100000000ll;

            while (invalid - valid > 1) {
                ll mid = (valid + invalid) / 2;

                if (year2d(mid) < d) {
                    valid = mid;
                }
                else {
                    invalid = mid;
                }
            }

            bool f = is_uru(valid);
            if (f) {
                month_table[2]++;
            }

            d -= year2d(valid);
            ll sum = 0;
            ll i = 1;
            while (sum + month_table[i] < d) {
                sum += month_table[i];
                i++;
            }

            printf("%lld.%lld.%lld\n", valid, i, d - sum);

            if (f) {
                month_table[2]--;
            }
        }
        else {
            w.y = a;
            scanf(". %lld . %lld", &w.m, &w.d);

            d = west2d(w) - west_origin;

            int f = 0;
            for (int i = 4; i >= 0; i--) {
                if (f) putchar('.');
                printf("%lld", d / maya_table[i] % maya_mod[i]);
                d %= maya_table[i];
                f = 1;
            }
            putchar('\n');
        }
    }

    return 0;
}

ll year2d(ll year)
{
    year--;
    return year * 365 + year / 4  - year / 100 + year / 400;
}

ll west2d(we x)
{
    ll ans = 0;

    ans += year2d(x.y);

    if (is_uru(x.y)) {
        month_table[2]++;
    }

    for (int i = 1; i < x.m; i++) {
        ans += month_table[i];
    }

    ans += x.d;

    if (is_uru(x.y)) {
        month_table[2]--;
    }

    return ans;
}

ll maya2d(maya x)
{
    int ans = 0;

    ans += x.ki * maya_table[0];
    ans += x.w  * maya_table[1];
    ans += x.t  * maya_table[2];
    ans += x.ka * maya_table[3];
    ans += x.b  * maya_table[4];

    return ans;
}

ll is_uru(ll y)
{
    if (y % 4 == 0 && y % 100 != 0) {
        return true;
    }
    else if (y % 100 == 0 && y % 400 == 0) {
        return true;
    }

    return false;
}

