Shinya watched a program on TV called "Maya's Great Prophecy! Will the World End in 2012?" After all, I wasn't sure if the world would end, but I was interested in Maya's "long-term calendar," which was introduced in the program. The program explained as follows.

The Maya long-term calendar is a very long calendar consisting of 13 Baktuns (1872,000 days) in total, consisting of the units shown in the table on the right. One calculation method believes that the calendar begins on August 11, 3114 BC and ends on December 21, 2012, which is why the world ends on December 21, 2012. .. However, there is also the idea that 13 Baktun will be one cycle, and when the current calendar is over, a new cycle will be started.

| 1 kin = 1 day
1 winal = 20 kin
1 tun = 18 winals
1 Katun = 20 tons
1 Baktun = 20 Katun |
--- | --- | ---



"How many days will my 20th birthday be in the Maya calendar?" Shinya wanted to express various days in the Maya long-term calendar.

Now, instead of Shinya, create a program that converts between the Christian era and the Maya long-term calendar.



input

The input consists of multiple datasets. The end of the input is indicated by # 1 line. Each dataset is given in the following format:


b.ka.t.w.ki


Or


y.m.d


The dataset consists of one line containing one character string. b.ka.t.w.ki is the Mayan long-term date and y.m.d is the Christian era date. The units given are as follows.

Maya long calendar
b | Baktun | (0 ≤ b <13)
--- | --- | ---
ka | Katun | (0 ≤ ka <20)
t | Tun | (0 ≤ t <20)
w | Winal | (0 ≤ w <18)
ki | kin | (0 ≤ ki <20)

Year
y | year | (2012 ≤ y ≤ 10,000,000)
--- | --- | ---
m | month | (1 ≤ m ≤ 12)
d | day | (1 ≤ d ≤ 31)



The maximum value for a day in the Christian era depends on whether it is a large month, a small month, or a leap year (a leap year is a multiple of 4 that is not divisible by 100 or divisible by 400). The range of dates in the Maya long calendar is from 0.0.0.0.0 to 12.19.19.17.19. However, 0.0.0.0.0.0 of the Maya long-term calendar corresponds to 2012.12.21 of the Christian era. The range of dates in the Christian era is from 2012.12.21 to 10000000.12.31.

The number of datasets does not exceed 500.

output

When the input is the Western calendar, the Maya long calendar is output, and when the input is the Maya long calendar, the Western calendar is output in the same format as the input. As a result of converting the input year, even if the next cycle of the Maya long calendar is entered, it may be output in the format of b.ka.t.w.ki.

Example

Input

2012.12.31
2.12.16.14.14
7138.5.13
10.5.2.1.5
10000000.12.31
#


Output

0.0.0.0.10
3054.8.15
0.0.0.0.10
6056.2.29
8.19.3.13.2
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

unsigned int sumd[10000011];

const int md[2][12]
={{31,28,31,30,31,30,31,31,30,31,30,31}
  ,{31,29,31,30,31,30,31,31,30,31,30,31}};

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

int main(){

  // テァツエツッテァツゥツ硬ay
  for(int y=2013;y<=10000010;y++){
    if(isLeap(y))sumd[y]=sumd[y-1]+366;
    else sumd[y]=sumd[y-1]+365;
  }

  string str;
  while(getline(cin,str)&&str!="#"){
    int dot=0;
    for(int i=0;i<(int)str.size();i++){
      if(str[i]=='.')dot++;
    }
    // s to m
    if(dot==2){
      vector<string> v=split(str,'.');
      vector<int> vv;
      for(int i=0;i<(int)v.size();i++)
        vv.push_back(StringToInt<int>(v[i]));
      ll pday=0;
      // 2012,12.21テ」ツ?凝」ツつ嘉・ツ按敕」ツつ?」ツ?ヲテ、ツスツ陛ヲツ猟・テァツオツ古ゥツ?偲」ツ?療」ツ?淌」ツ?凝」ツつ津ィツィツ暗ァツョツ療」ツ??
      // テ」ツ?敕」ツ?ョテ・ツ?、テ」ツつ津ァツ板ィテ」ツ??」ツ?ヲテ」ツδ榲」ツδ、テヲツ堋ヲテ」ツ?ォテ・ツ、ツ嘉ヲツ渉?
      if(vv[0]==2012&&vv[1]==12)pday+=vv[2]-21;
      else{
        pday+=10;
        pday+=sumd[vv[0]-1];
        int c=isLeap(vv[0]);
        for(int i=0;i<12;i++){
          if(vv[1]==i+1){
            pday+=vv[2];
            break;
          }
          else{
            pday+=md[c][i];
          }
        }
      }
      pday%=(ll)13*20*20*18*20;
      // cout<<pday<<endl;
      // pdayテ」ツつ津・ツ、ツ嘉ヲツ渉?
      vector<int> res;
      res.push_back(pday/(20*18*20*20));
      pday%=(20*18*20*20);
      res.push_back(pday/(20*18*20));
      pday%=20*18*20;
      res.push_back(pday/(20*18));
      pday%=20*18;
      res.push_back(pday/20);
      pday%=20;
      res.push_back(pday);
      for(int i=0;i<(int)res.size();i++){
        cout<<res[i];
        if(i==(int)res.size()-1)cout<<endl;
        else cout<<".";
      }
    }
    // m to s
    else{
      vector<string> v=split(str,'.');
      vector<int> vv;
      for(int i=0;i<(int)v.size();i++)
        vv.push_back(StringToInt<int>(v[i]));
      ll sum=0;
      sum=sum+vv[0];
      sum=sum*20+vv[1];
      sum=sum*20+vv[2];
      sum=sum*18+vv[3];
      sum=sum*20+vv[4];
      // 2012,12,21テ」ツ?凝」ツつ嘉」ツ?ョテァツオツ古ゥツ?仕ayテ」ツつ痴umテ」ツ?ィテ」ツ?凖」ツつ?
      if(sum<=10)cout<<2012<<"."<<12<<"."<<21+sum<<endl;
      else{
        sum-=10;
        // テ」ツ?禿」ツ?禿」ツ?凝」ツつ嘉ァツエツッテァツゥツ酵earテ」ツつ津、ツスツソテ」ツ?」テ」ツ?ヲテ、ツコツ古・ツ按?ヲツ篠「テァツエツ「テ」ツ?ァテ」ツ??、ツスツ陛・ツケツエテ」ツ?セテ」ツ?ァテゥツ?イテ」ツつ?」ツつ凝」ツ?凝ィツェツソテ」ツ?ケテ」ツつ?
        int ub=10000010;
        int lb=2012;
        while(ub-lb>1){
          int mid=(ub+lb)/2;
          if(sumd[mid]>=sum)ub=mid;
          else lb=mid;
        }
        // ubテ・ツケツエテ」ツ?古」ツ??ィツカツ?」ツ?暗」ツつ凝ヲツ慊?・ツ按敕」ツ?ョテ・ツケツエテ」ツ?ェテ」ツ?ョテ」ツ?ァ
        // ub-1テ・ツケツエテ」ツ?セテ」ツ?ァテ・ツケツエテ」ツつ津ゥツ?イテ」ツつ?」ツ?ヲテ」ツ?甘」ツ??
        sum-=sumd[ub-1];
        int resy=ub;
        int c=isLeap(resy);
        int resm,resd;
        for(int i=0;i<12;i++){
          if(sum<=md[c][i]){
            resm=i+1;
            resd=sum;
            break;
          }
          else sum-=md[c][i];
        }
        cout<<resy<<"."<<resm<<"."<<resd<<endl;
      }
    }
  }

  return 0;
}