Biorhythms

No attempts yetTime limit1sMemory limit128 MB

Problem

Some people believe that three cycles start on the day a person is born and then run for life. The three cycles are physical, emotional, and intellectual, with periods of 23, 28, and 33 days. Each period of a cycle contains exactly one peak. On the peak day a person performs at his or her best in the matching area. When the intellectual cycle peaks, for example, thinking is sharper and concentration comes more easily.

Because the three periods differ, the peaks usually land on different days. A day on which all three peaks land together is a triple peak, and we want to know when one happens. For each cycle you are given one day on which it peaks, counted in days from the beginning of the current year. That day is not necessarily the first peak. You are also given a date, counted the same way. Find how many days pass from the given date to the next triple peak. The given date itself is not counted. If the given date is 10 and the next triple peak falls on day 12, the answer is 2, not 3. If a triple peak falls on the given date, report the number of days to the following triple peak.

Input

The input holds several test cases. Each test case is one line with four integers p, e, i, and d separated by spaces. The values p, e, and i are the days on which the physical, emotional, and intellectual cycles peak, counted from the beginning of the current year. The value d is the given date and may be smaller than p, e, or i. All four values are between 0 and 365, and a triple peak is guaranteed to occur within 21252 days of the given date. A line whose four values are all -1 ends the input.

Output

For each test case, print the case number and the number of days to the next triple peak in this form.

Case x: the next triple peak occurs in y days.

Replace x with the case number, counting from 1, and y with the number of days.