#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int ms[] = { 31,28,31,30,31,30,31,31,30,31,30,31};
const ll Kin = 1;
const ll Uinal = 20 * Kin;
const ll Tun = Uinal * 18;
const ll Katun = Tun * 20;
const ll Baktun = Katun * 20;

vector<string> split(string s){
    int x;
    vector<string> ret;
    s += '.';
    x = -1;
    REP(i,s.size()){
	if(s[i] == '.'){
	    ret.PB(s.substr(x+1,i-x-1));
	    x = i;
	}
    }
    return ret;
}

ll cg(string s){
    vector<string> d = split(s);
    if(d[0] == "2012"){
	return stoll(d[2]) - 21;
    }else{
	ll y = stoll(d[0]);
	ll m = stoll(d[1]);
	ll da = stoll(d[2]);
	ll ret = 0;
	ll ty = y - 1;
	ret = 10LL;
	ll a = (ty - 2012LL) * 365LL;
	if(a < 0) a = 0;
	ret += a;
	ret += ty / 4LL - ty / 100LL + ty / 400LL;
	ret -= 2012 / 4 - 2012 / 100 + 2012 / 400;
	REP(i,m-1){
	    if(i==1 && ( y%4==0 && (y%100!=0 || (y%100==0&&y%400==0)) ) ) {
		ret += 1;
	    }
	    ret += ms[i];
	}
	ret += da;
	return ret;
    }
    return 0;
}

ll cm(string s){
    vector<string> d = split(s);
    ll ret=0;
    ret += Baktun * stoi(d[0]);
    ret += Katun * stoi(d[1]);
    ret += Tun * stoi(d[2]);
    ret += Uinal * stoi(d[3]);
    ret += Kin * stoi(d[4]);
    return ret;
}

string mtog(string s){
    int num = cm(s);
    int y = 2012;
    int m = 12;
    int d = 21;
    if(num <= 10){
	return "2012.12." + to_string(d+num);
    }else{
	REP(i,num){
	    if(m == 12 && d == 31){
		y++;
		m = 1;
		d = 1;
	    }else if(m==2 && d == 28 &&  ( y%4==0 && (y%100!=0 || (y%100==0&&y%400==0)) ) ) d++;
	    else if(d >= ms[m-1]){
		m++;
		d = 1;
	    }else d++;
	}
	return to_string(y) + "." + to_string(m) + "." + to_string(d);
    }
    return "";
}

string gtom(string s){
    ll num = cg(s);
    ll days[5];
    days[0] = Baktun;
    days[1] = Katun;
    days[2] = Tun;
    days[3] = Uinal;
    days[4] = Kin;
    string ret = "";
    num = (num % (13*days[0]));
    REP(i,4){
	ret += to_string(num/days[i]) + ".";
	num %= days[i];
    }
    ret += to_string(num/days[4]);
    return ret;
}

int main(){
    while(true){
	string s;
	cin >> s;
	if(s == "#") break;
	int c = 0;
	REP(i,s.size()) if(s[i] == '.') c++;
	if(c == 2) cout << gtom(s) << endl;
	else if(c == 4) cout << mtog(s) << endl;;
    }
    return 0;
}