#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

ll calc1(ll y,ll m,ll d){
  ll ret = 0;
  if(y>0){
    ret += y*365;
    ret += (y-1)/4;
    ret -= (y-1)/100;
    ret += (y-1)/400;
    ret += 1;
  }
  if((y%4==0&&y%100!=0) || (y%400==0)){
    // is uruu
    ll daylist[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
    REP(i,m-1) ret += daylist[i];
    ret += d;
  }else{
    // isnt uruu
    ll daylist[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    REP(i,m-1) ret += daylist[i];
    ret += d;
  }
  return ret;
}

string tostr(ll a){
  if(a==0)return "0";
  string ret = "";
  while(a){
    ret = (char)(a%10+'0') + ret;
    a /= 10;
  }
  return ret;
}

void printmaya(ll day){
  day %= 1872000;
  string ret = "";
  ret = tostr(day%20) + ret;
  day /= 20;
  ret = tostr(day%18) + "." + ret;
  day /= 18;
  ret = tostr(day%20) + "." + ret;
  day /= 20;
  ret = tostr(day%20) + "." + ret;
  day /= 20;
  ret = tostr(day) + "." + ret;
  cout << ret << endl;
  return;
}

void printdays(ll days){
  ll year;
  year = days/366;
  while(calc1(year,1,0) < days)++year;
  --year;
  days -= calc1(year,1,0);
  ll month = 0, day = 0;
  if((year%4==0&&year%100!=0) || (year%400==0)){
    // is uruu
    ll daylist[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
    REP(i,12){
      if(days <= daylist[i]){
        month = i+1;
        day = days;
        break;
      }
      days -= daylist[i];
    }
  }else{
    // isnt uruu
    ll daylist[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    REP(i,12){
      if(days <= daylist[i]){
        month = i+1;
        day = days;
        break;
      }
      days -= daylist[i];
    }
  }
  printf("%lld.%lld.%lld\n",year,month,day);
}

int main(){
  // DEBUG(calc1(1,1,1));
  // DEBUG(calc1(1,12,31));
  while(true){
    string s;
    cin>>s;
    if(s=="#")break;
    if(count(ALL(s),'.') == 4){
      // DEBUG("?????????");
      ll a=0,b=0,c=0,d=0,e=0;
      // input
      {
        int it = 0;
        while(s[it]!='.'){
          a *= 10;
          a += (s[it]-'0');
          ++it;
        }
        ++it;
        while(s[it]!='.'){
          b *= 10;
          b += (s[it]-'0');
          ++it;
        }
        ++it;
        while(s[it]!='.'){
          c *= 10;
          c += (s[it]-'0');
          ++it;
        }
        ++it;
        while(s[it]!='.'){
          d *= 10;
          d += (s[it]-'0');
          ++it;
        }
        ++it;
        while(it<s.size()){
          e *= 10;
          e += (s[it]-'0');
          ++it;
        }
      }
      ll dest = calc1(2012,12,21);
      ll add = (((a*20+b)*20+c)*18+d)*20+e;
      printdays(dest+add);
    }else{
      // DEBUG("??±????????????");
      // year month day
      ll year = 0, month = 0, day = 0;
      // input
      {
        int it = 0;
        while(s[it]!='.'){
          year *= 10;
          year += (s[it]-'0');
          ++it;
        }
        ++it;
        while(s[it]!='.'){
          month *= 10;
          month += (s[it]-'0');
          ++it;
        }
        ++it;
        while(it<s.size()){
          day *= 10;
          day += (s[it]-'0');
          ++it;
        }
      }
      ll dest = calc1(2012,12,21);
      ll birt = calc1(year,month,day);
      printmaya(birt - dest);
    }
  }
  return 0;
}

Measured memory_bytes: 1228