#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int p1, p2;
int d1, d2;
int t1 = 0, t2 = 0;
int h, m;
int day = 0;
bool ok = false;
string dan[] = {"subota", "nedjelja", "ponedjeljak", "utorak", "srijeda", "cetvrtak", "petak"};

inline void convert(int &x) {x = h * 60 + m;}

int main(void) {
	scanf("%02d:%02d", &h, &m); convert(p1);
	scanf("%02d:%02d", &h, &m); convert(p2);
	scanf("%02d:%02d", &h, &m); convert(d1);
	scanf("%02d:%02d", &h, &m); convert(d2);

	if (p1 < p2) {
		swap(p1, p2);
		swap(d1, d2);
	}

	if ((p1 != p2 && d1 == d2) || (p1 > p2 && d1 > d2)) {
		printf("nikad\n");
		return 0;
	}

	for(;!ok;) {
		if (p1 > p2 && t1 >= t2) p2 += d2; else p1 += d1;
		if (p1 >= 1440) {
			p1 -= 1440;
			++t1;
			if (t1 == 7) t1 = 0;
		}
		if (p2 >= 1440) {
			p2 -= 1440;
			++t2;
			if (t2 == 7) t2 = 0;
		}		
		if (p1 == p2 && t1 == t2) ok = true;
	}
	
	if (ok) {
		printf("%s\n", dan[t1].c_str());
		h = p1 / 60;
		m = p1 % 60;
		printf("%02d:%02d\n", h, m);
	} else printf("nikad\n");

	return 0;
}
	
