#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int p, e, i, d, T = 1;
while (scanf("%d %d %d %d", &p, &e, &i, &d))
{
if (p == -1 && e == -1 && e == -1 && d == -1) return 0;
p *= 5544; e *= 14421; i *= 1288; d -= 21252;
int ans = (p + e + i - d) % 21252;
if (ans == 0) ans = 21252;
printf("Case %d: the next triple peak occurs in %d days.\n", T ++, ans);
}
return 0;
}