#include "bits/stdc++.h"
using namespace std;

using int64 = long long;

template<typename T>
using p_que = priority_queue<T>;
template<typename T>
using rp_que = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = (1 << 30) - 1;
constexpr int64 INF64 = (1ll << 60) - 1;

#define rep(i, N) for(int i=0;i<(int)(N);++i)
#define fs first
#define sc second
#define e_b emplace_back
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	return os << "P(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& m) {
	os << "{" << endl;
	for (auto& e : m) os << "(" << e.first << ", " << e.second << ")" << endl;
	return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
	os << "{" << endl;
	for (auto& e : s) os << ", " << e << endl;
	return os << "}";
}

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int64 gcd(int64 x, int64 y) {
	if (x == 0 || y == 0) return 0;
	int64 r;
	while ((r = y % x) != 0) {
		y = x;
		x = r;
	}
	return x;
}
int64 lcm(int64 x, int64 y) {
	if (x == 0 || y == 0) return 0;
	return x / gcd(x, y) * y;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

void Main();
signed main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	Main();
}

/*----------------------------Insert from here!----------------------------*/

template <int mod>
struct ModInt {
	int x;

	ModInt() : x(0) {}

	ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

	ModInt& operator+=(const ModInt& p) {
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}

	ModInt& operator-=(const ModInt& p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}

	ModInt& operator*=(const ModInt& p) {
		x = (int)(1LL * x * p.x % mod);
		return *this;
	}

	ModInt& operator/=(const ModInt& p) {
		*this *= p.inverse();
		return *this;
	}

	ModInt operator-() const { return ModInt(-x); }

	ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }

	ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }

	ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }

	ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

	bool operator==(const ModInt& p) const { return x == p.x; }

	bool operator!=(const ModInt& p) const { return x != p.x; }

	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			swap(a -= t * b, b);
			swap(u -= t * v, v);
		}
		return ModInt(u);
	}

	ModInt pow(int64_t n) const {
		ModInt ret(1), mul(x);
		while (n > 0) {
			if (n & 1) ret *= mul;
			mul *= mul;
			n >>= 1;
		}
		return ret;
	}

	friend ostream& operator<<(ostream& os, const ModInt& p) {
		return os << p.x;
	}

	friend istream& operator>>(istream& is, ModInt& a) {
		int64_t t;
		is >> t;
		a = ModInt< mod >(t);
		return (is);
	}

	static int get_mod() { return mod; }
};


// Calculate elapsed days from Gregorian calendar 1.1.1(y.m.d)
// Fairfield's congruence
long long getElapsedDays(long long y, int m, int d) {
	if (m <= 2) {
		m += 12;
		y--;
	}
	return 365 * y + y / 4 - y / 100 + y / 400 + (306 * (m + 1)) / 10 + d - 429;
}

// Calculate the day of the week of specified date
// 7:Sun 1:Mon ... 6:Satur
int getDayOfWeek(int y, int m, int d) {
	int c = y / 100;
	y %= 100;
	int dow = d + 26 * (m + 1) / 10 + y + y / 4 + (-2 * c) + c / 4 + 5;
	dow %= 7;
	return dow + 1;
}

// Calculate the date from elapsed days (from Gregorian Calendar 1.1.1)
void getDate(long long U, int& y, int& m, int& d) {
	U += 306;
	int V = U / 146097; int mv = U % 146097;
	int W = (4 * mv + 3) / 146097; int mw = mv - 36524 * W;
	int X = mw / 1461; int mx = mw % 1461;
	int Y = (4 * mx + 3) / 1461; int my = mx - 365 * Y;

	y = 400 * V + 100 * W + 4 * X + Y;
	m = (5 * my + 2) / 153 + 3;
	d = my - (153 * (m - 3) + 2) / 5 + 1;
	if (m > 12) m -= 12, y++;
}

// Split string by specified character
vector<string> split_string(const string& s, char delim) {
	vector<string> elems;
	string item;
	for (char ch : s) {
		if (ch == delim) {
			if (!item.empty())
				elems.push_back(item);
			item.clear();
		} else {
			item += ch;
		}
	}
	if (!item.empty())
		elems.push_back(item);
	return elems;
}

/*----------------------------Insert above here----------------------------*/

void Main() {
	int key = getElapsedDays(2012, 12, 21);
	string str;
	while (true) {
		cin >> str;
		if (str == "#") break;

		auto vec = split_string(str, '.');

		if (vec.size() == 3) {
			int y, m, d;
			y = stoi(vec[0]), m = stoi(vec[1]), d = stoi(vec[2]);

			int64 U = getElapsedDays(y, m, d);
			U -= key;

			int64 b = U / 144000; U %= 144000;
			int ka = U / 7200; U %= 7200;
			int t = U / 360; U %= 360;
			int w = U / 20; U %= 20;
			cout << b % 13 << "." << ka << "." << t << "." << w << "." << U << endl;

		} else {
			int64 b, ka, t, w, ki;
			b = stoi(vec[0]), ka = stoi(vec[1]), t = stoi(vec[2]), w = stoi(vec[3]), ki = stoi(vec[4]);
			int64 U = b * 144000;
			U += ka * 7200;
			U += t * 360;
			U += w * 20;
			U += ki;

			U += key;
			int y, m, d;
			getDate(U, y, m, d);
			cout << y << "." << m << "." << d << endl;
		}
	}
}


Measured memory_bytes: 3200