#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>
   
using namespace std;
   
 
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) for (__typeof__((c).rbegin()) it=(c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(dest))
#define ten(n) ((long long)(1e##n))
#define bin(n) (1LL << (n))
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define revrep(i, n) for (int i = (n); i >= 0; --i)
#define pb push_back

template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }

template <class T> T round_up(T a, T b) { return (a + b - 1) / b; }

template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); }
 
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
  
template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; }
  
template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; }
template <class T> void print(const T& c, const string& deli = " ", int br = 1) { foreach (it, c) { cout << *it; if (++it != c.end()) cout << deli;--it; } while (br--) cout << endl; }
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) {    if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
   
template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
#define trace(x) (cout << #x << ": " << (x) << endl)
 
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }
 

typedef long long ll;
typedef pair<int, int> pint;
 
// y(v): v>^<  y(^): ^>v<
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

const double PI = acos(-1.0);

#define F first
#define S second


// __days[month - 1]
static const int __days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

// __sum_days[month] -> sum_days(1, 2, .., month - 1)
static const int __sum_days[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };

const int days_of_year = 365;

class Date
{
private:
    int _year, _month, _day;    // _month, day: 1-based

public:
//////// class method

    // definition
    // 0 year is leep year
    // n(n < 0) year is NOT leep year

    static bool is_leep(int year)
    {
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }

    // [0, until]
    static int leep_years(int until)
    {
        if (until < 0)
            return 0;
        int res = (until / 4) - (until / 100) + (until / 400);
        ++res; // by definition: 0 year is leep
        return res;
    }

    static int days(int year)
    {
        return is_leep(year) ? days_of_year + 1 : days_of_year;
    }
    static int days(int year, int month)
    {
        if (is_leep(year) && month == 2)
            return __days[month - 1] + 1;
        else
            return __days[month - 1];
    }


//////// instance method
    Date(int year, int month, int day)
        : _year(year), _month(month), _day(day)
    {
        assert(1 <= month && month <= 12);
        assert(1 <= day && day <= days(year, month));
    }

    int year() const { return _year; }
    int month() const { return _month; }
    int day() const { return _day; }

    // 0000/01/01 -> 1
    ll to_n() const
    {
        ll res = 0;
        int leep = leep_years(year() - 1);
        int not_leep = year() - leep;
        res += not_leep * (ll)days_of_year + leep * (ll)(days_of_year + 1);
        res += __sum_days[month() - 1] + (is_leep(year()) && month() > 2 ? 1 : 0);
        res += day();
        return res;
    }

    Date next(ll next_days) const
    {
        if (next_days < 0)
            return prev(-next_days);

        ll correct_n = this->to_n() + next_days;

        int y = year() + (next_days / (days_of_year + 1));
        while (Date(y, 12, days(y, 12)).to_n() < correct_n)
            ++y;

        int m = 1;
        while (Date(y, m, days(y, m)).to_n() < correct_n)
            ++m;

        int d = 1;
        while (Date(y, m, d).to_n() < correct_n)
            ++d;

        return Date(y, m, d);
    }

    Date prev(ll prev_days) const
    {
        if (prev_days < 0)
            return next(-prev_days);

        ll correct_n = this->to_n() - prev_days;

        int y = year() - (prev_days / (days_of_year + 1));
        while (Date(y, 1, 1).to_n() > correct_n)
            --y;

        int m = 12;
        while (Date(y, m, 1).to_n() > correct_n)
            --m;

        int d = Date::days(y, m);
        while (Date(y, m, d).to_n() > correct_n)
            --d;

        return Date(y, m, d);
    }

    string to_s() const
    {
        char buf[128];
        sprintf(buf, "%d/%d/%d", year(), month(), day());
        return buf;
    }
};

// Date tester
void test_to_n()
{
    ll correct = 1;
    for (int y = 0; y < 1000000; ++y)
    {
        for (int m = 1; m <= 12; ++m)
        {
            for (int d = 1; d <= Date::days(y, m); ++d)
            {
                Date date(y, m, d);
                if (date.to_n() != correct)
                {
                    printf("%lld: %d/%d/%d, %lld\n", correct, y, m, d, date.to_n());
                    exit(1);
                }
                ++correct;
            }
        }
    }
}
void test_next()
{
    const int max_y = 100;
    const int max_next = 100;

    for (int y = 0; y <= max_y; ++y)
    {
        for (int m = 1; m <= 12; ++m)
        {
            for (int d = 1; d <= Date::days(y, m); ++d)
            {
                Date base(y, m, d);
                for (int next = -max_next; next <= max_next; ++next)
                {
                    if (base.to_n() + next <= 0)
                        continue;

                    Date nexted = base.next(next);
                    if (base.to_n() + next != nexted.to_n())
                    {
                        printf("%d/%d/%d\n", y, m, d);
                        trace(next);
                        trace(base.to_n());
                        cout << base.to_s() << endl;
                        cout << nexted.to_s() << endl;
                        exit(1);
                    }
                }
            }
        }
    }
}
void test_prev()
{
    const int max_y = 100;
    const int max_prev = 100;

    for (int y = 0; y <= max_y; ++y)
    {
        for (int m = 1; m <= 12; ++m)
        {
            for (int d = 1; d <= Date::days(y, m); ++d)
            {
                Date base(y, m, d);
                for (int prev = -max_prev; prev <= max_prev; ++prev)
                {
                    if (base.to_n() - prev <= 0)
                        continue;

                    Date preved = base.prev(prev);
                    if (base.to_n() - prev != preved.to_n())
                    {
                        printf("%d/%d/%d\n", y, m, d);
                        trace(prev);
                        trace(base.to_n());
                        cout << base.to_s() << endl;
                        cout << preved.to_s() << endl;
                        exit(1);
                    }
                }
            }
        }
    }
}
void test_nextprev()
{
    for (int y = 0; y < 500; ++y)
    {
        for (int m = 1; m <= 12; ++m)
        {
            for (int d = 1; d <= Date::days(y, m); ++d)
            {
                Date cur(y, m, d);
                for (int diff = 0; diff < 10000; ++diff)
                {
                    if (cur.to_n() != cur.next(diff).prev(diff).to_n())
                    {
                        printf("%d, %d, %d, %d\n", y, m, d, diff);
                        exit(1);
                    }
                }
            }
        }
    }
}
// end Date tester

// 1 day = 1 kin
// uninal, tun, katun, baktun
int maya_weight[] = { 20, 18, 20, 20 };
ll maya_to_num(int baktun, int katun, int tun, int unial, int kin)
{
    int arg[] = { unial, tun, katun, baktun };
    ll res = kin, days = 1;
    for (int i = 0; i < 4; ++i)
    {
        days *= maya_weight[i];
        res += days * arg[i];
    }
    return res;
}
// return: { kin, uninal, tun, katun, baktun }
vector<int> num_to_maya(ll num)
{
    vector<int> res(5);
    for (int i = 0; i < 4; ++i)
    {
        res[i] = num % maya_weight[i];
        num /= maya_weight[i];
    }
    res[4] = num;
    return res;
}

int main()
{
    ll maya_period = 1;
    rep(i, 4)
        maya_period *= maya_weight[i];
    maya_period *= 13;

    const Date new_maya(2012, 12, 21);

    string in;
    while (cin >> in, in[0] != '#')
    {
        if (count(all(in), '.') == 2)
        {
            int y, m, d;
            sscanf(in.c_str(), "%d.%d.%d", &y, &m, &d);

            ll offset = Date(y, m, d).to_n() - new_maya.to_n();
            offset = (offset + maya_period) % maya_period;
            vector<int> maya = num_to_maya(offset);
            printf("%d.%d.%d.%d.%d\n", maya[4], maya[3], maya[2], maya[1], maya[0]);
        }
        else
        {
            int a, b, c, d, e;
            sscanf(in.c_str(), "%d.%d.%d.%d.%d", &a, &b, &c, &d, &e);

            ll offset = maya_to_num(a, b, c, d, e);
            Date res = new_maya.next(offset);
            printf("%d.%d.%d\n", res.year(), res.month(), res.day());
        }
    }
}

Measured memory_bytes: 1244