#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0261>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int tuki[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
string maya;

ll calcday1(ll y,ll m,ll d){
    ll res = 0;
    
    res = (y-1)*365 + (y-1)/4 - (y-1)/100 +  (y-1)/400;
    for(int i = 1; i < m;i++){
        res += tuki[i-1];
        if(i == 2){
            if(y%4==0&&(y%100!=0||y%400==0)) res++;
        }
    }
    res += d;
    return res;
}
ll calcday2(ll b,ll ka,ll t,ll w,ll ki){
    ll res = 0;
    res += 20*18*20*20*b + 20*18*20*ka + 20*18*t + 20*w + ki;
    return res;
}
string solve(){
    string res;
    if(count(maya.begin(),maya.end(),'.') == 2){
        replace(maya.begin(),maya.end(),'.',' ');
        stringstream ss;
        ss << maya;
        ll y,m,d; ss >> y >> m >> d;
        
        ll D = calcday1(y,m,d) - calcday1(2012,12,21);

        ll b,ka,t,w,ki;
        ki = D%20; D/=20;
        w = D%18; D/=18;
        t = D%20; D/=20;
        ka = D%20; D/=20;
        b = D%13;
        res = to_string(b) + "." + to_string(ka) + "." + to_string(t) + "." + to_string(w) + "." + to_string(ki);
    }else{
        replace(maya.begin(),maya.end(),'.',' ');
        stringstream ss;
        ss << maya;
        ll b,ka,t,w,ki; ss >> b >> ka >> t >> w >> ki;
        ll D = calcday2(b,ka,t,w,ki) + calcday1(2012,12,21);
        
        ll y,m,d;
        y = 1;
        while(365 + (y%4==0&&(y%100!=0||y%400==0)) < D){
            D -= 365;
            D -= (y%4==0&&(y%100!=0||y%400==0));
            y++;
        }
        m = 1;
        while(tuki[m-1] + (m==2&&(y%4==0&&(y%100!=0||y%400==0))) < D){
            D -= tuki[m-1];
            D -= (m==2&&(y%4==0&&(y%100!=0||y%400==0)));
            m++;
        }
        res = to_string(y) + "." + to_string(m) + "." + to_string(D);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> maya){
        if(maya == "#") break;
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3264