How much can he sleep?

image

Richi is a student with notable characteristics, one of which is his habit of sleeping. Now he is planning one of his usual travels, with many activities, to which he will assist even if they overlap. During his spare time he wants to sleep, but he has decided that only if he can do it for exactly 8 hours (sleeping for less time would be silly). If, when he wakes up, he can sleep for exactly 8 more hours, he will keep sleeping, and so on. How many hours can he sleep in total?

Input

Input consists of several cases. Each case begins with the starting time of the trip ss and the ending time of the trip ee, two natural numbers such that s<e108s < e \le 10^8. Then comes the number of activities nn, followed by nn descriptions of activities in any order: two natural numbers aa and bb separated by a hyphen, and such that sa<bes \le a < b \le e. Input ends with two zeros. Suppose n105n \le 10^5.

Output

For every test case, print a line with the case number and how many hours Richi can sleep, following the format of the sample output.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:06:47.501Z

© Jutge.org, 2006–2026.
https://jutge.org