#include <iostream>
#include <algorithm>
#include <algorithm>

using namespace std;

typedef long long lli;

class S{
public:
  lli y, m, d;

  S(){}
  S(lli y, lli m, lli d): y(y), m(m), d(d) {}
  S(string str){
    lli pre = 0;
    for(lli i=0;i<str.size();i++){
      if(str[i] == '.'){
        if(pre == 0) y = atoi(str.substr(pre, i).c_str());
        else m = atoi(str.substr(pre + 1, i - pre + 1).c_str());
        pre = i;
      }
    }
    d = atoi(str.substr(pre + 1).c_str());
  }
  S(lli days){
    if(days <= 10){
      y = 2012;
      m = 12;
      d = 21 + days;
    }else{
      days -= 11;
      lli lb = 2013, ub = 10000000;
      while(lb <= ub){
        lli mid = (ub + lb) / 2;
        lli tmp = days - ((mid - 2013) * 365 + countLeap(mid));
        if(0 <= tmp && tmp < 365){
          lb = mid;
          break;
        }else if(tmp < 0) ub = mid - 1;
        else lb = mid + 1;
      }
      y = lb;
      days -= (y - 2013) * 365 + countLeap(y);
      if(days == -1){
        y = y - 1;
        m = 12;
        d = 31;
      }else{
        for(lli i=1;i<=12;i++){
          if(days - getMSize(y, i) < 0){
            m = i;
            break;
          }
          days -= getMSize(y, i);
        }
        d = days + 1;
      }
    }
  }

  lli getMSize(lli y, lli m){
    lli msize[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};    
    if(isLeap(y) && m == 2) return 29;
    return msize[m];
  }

  bool isLeap(lli y){
    return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
  }

  lli countLeap(lli y){
    if(y == 2012 || y == 2013) return 0;
    y--;
    lli tmp = 2012 / 4 - 2012 / 100 + 2012 / 400;
    lli res = y / 4 - y / 100 + y / 400;
    return res - tmp;
  }
  
  lli stod(S s){
    lli res;
    if(s.y == 2012){
      res = s.d - 21;
    }else{
      res = (s.y - 2013) * 365 + countLeap(s.y) + 10;
      for(lli i=1;i<s.m;i++) res += getMSize(s.y, i);
      res += s.d;
    }
    return res;
  }
};

class M{
public:
  lli b, ka, t, w, ki;

  M(){}
  M(lli b, lli ka, lli t, lli w, lli ki): b(b), ka(ka), t(t), w(w), ki(ki) {}
  M(string str){
    lli pre = 0;
    lli cnt = 0;
    for(lli i=0;i<str.size();i++){
      if(str[i] == '.'){
        if(cnt == 0) b = atoi(str.substr(pre, i).c_str());
        else if(cnt == 1) ka = atoi(str.substr(pre + 1, i - pre + 1).c_str());
        else if(cnt == 2) t = atoi(str.substr(pre + 1, i - pre + 1).c_str());
        else if(cnt == 3) w = atoi(str.substr(pre + 1, i - pre + 1).c_str());
        cnt++;
        pre = i;
      }
    }
    ki = atoi(str.substr(pre + 1).c_str());
  }
  M(lli days){
    days %= 13*20*20*18*20;
    if(days != 0){
      b = days / (20*20*18*20);
      days -= b * (20*20*18*20);
    }else b = 0;
    if(days != 0){
      ka = days / (20*18*20);
      days -= ka * (20*18*20);
    }else ka = 0;
    if(days != 0){
      t = days / (18*20);
      days -= t * (18*20);
    }else t = 0;
    if(days != 0){
      w = days / 20;
      days -= w * 20;
    }else w = 0;
    ki = days;
  }

  lli mtod(M m){
    lli res = 0;
    res += b * (20*20*18*20);
    res += ka * (20*18*20);
    res += t * (18*20);
    res += w * 20;
    res += ki;
    return res;
  }
};

main(){
  string in;
  while(cin >> in){
    if(in == "#") break;
    int cnt = 0;
    for(int i=0;i<in.size();i++) if(in[i] == '.') cnt++;
    if(cnt == 2){
      S s = S(in);
      M m = M(s.stod(s));
      cout << m.b << "." << m.ka << "." << m.t << "." << m.w << "." << m.ki << endl;
    }else{
      M m = M(in);
      S s = S(m.mtod(m));
      cout << s.y << "." << s.m << "." << s.d << endl;
    }
  }
}

Measured memory_bytes: 1204