public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);

		int no = 1;
		while (true) {
			int p = cin.nextInt();
			int e = cin.nextInt();
			int i = cin.nextInt();
			int d = cin.nextInt();
			if (p < 0 && e < 0 && i < 0 && d < 0) {
				break;
			}
			int ans = (p * 5544 + e * 14421 + i * 1288 - d + 21252) % 21252;
			if (ans == 0)
				ans = 21252;
			System.out.println(String
					.format("Case %d: the next triple peak occurs in %d days.",
							no, ans));
			no++;
		}
	}