#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

ll GetDays(ll y, ll m, ll d){
    // 1・2月 → 前年の13・14月
    if (m <= 2){
        --y;
        m += 12;
    }
    ll dy = 365 * (y - 1); // 経過年数×365日
    ll c = y / 100;
    ll dl = (y >> 2) - c + (c >> 2); // うるう年分
    ll dm = (m * 979 - 1033) >> 5; // 1月1日から m 月1日までの日数
    return dy + dl + dm + d - 1;
}

ll solve(ll y, ll m, ll d) {
    return GetDays(y, m, d) - GetDays(2012, 12, 21);
}

bool uru(int y) {
    if (y % 400 == 0)return true;
    if (y % 100 == 0)return false;
    if (y % 4 == 0)return true;
    return false;
}
int month[2][13] = {
    {0,31,28,31,30,31,30,31,31,30,31,30,31}
    ,{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
void nextday(int& y, int& m, int& d) {
    if (d == month[uru(y)][m]) {
        m++;
        d = 1;
    }
    else d++;
    if (m == 13) {
        y++;
        m = 1;
    }
}

int main() {
    init();

    string in;
    while (1) {
        cin >> in;
        if (in == "#")break;
        VI a;
        int f = 0;
        FOR(i, 0, in.length()) {
            if (in[i] == '.') {
                a.push_back(stoi(in.substr(f, i - f)));
                f = i + 1;
            }
        }
        a.push_back(stoi(in.substr(f)));

        if (a.size() == 3) {
            int w = 20, t = w * 18, k = t * 20, b = k * 20;
            ll date = solve(a[0], a[1], a[2]) % 1872000;
            cout << date / b << ".";
            date %= b;
            cout << date / k << ".";
            date %= k;
            cout << date / t << ".";
            date %= t;
            cout << date / w << ".";
            date %= w;
            cout << date << "\n";
        }
        else {
            int dif[4] = { 20,20,18,20 };
            FOR(i, 0, 4)a[i + 1] += a[i] * dif[i];
            int date = a[4];

            int y = 2012, m = 12, d = 21;
            FOR(i, 0, date)nextday(y, m, d);
            cout << y << "." << m << "." << d << "\n";
        }
    }
}
