Fifty Coats of Gray

Time limit1sMemory limit128 MB

Problem

A contractor is bidding on the interior painting for a student-housing apartment building. Every apartment is a single-room efficiency with plain drywall walls and a plain ceiling, with no crown molding or other trim. In each apartment the crew paints the four walls and the ceiling in a single color. The floor is never painted, and the openings for windows and doors are left unpainted. Every room, window, and door is a rectangle.

You are given the room dimensions, the list of window and door openings for a floor plan, and how many apartments share that plan. Report how many cans of paint the contractor must buy.

For one apartment the paintable area is the four walls plus the ceiling, minus the openings:

$$A = 2 \cdot \text{height} \cdot (\text{width} + \text{length}) + \text{width} \cdot \text{length} - \sum_{i} w_i \cdot h_i$$

One can of paint covers a fixed area, and paint is sold only in whole cans, so the number of cans is always rounded up.

Input

The input contains several test cases. Each test case starts with a line of six integers:

n width length height area m
  • $n$ ($1 \le n \le 100$) — the number of apartments that share this floor plan
  • $\text{width}$ ($8 \le \text{width} \le 100$) — the width of each room, in feet
  • $\text{length}$ ($8 \le \text{length} \le 100$) — the length of each room, in feet
  • $\text{height}$ ($8 \le \text{height} \le 30$) — the height of each room, in feet
  • $\text{area}$ ($100 \le \text{area} \le 1000$) — the area, in square feet, that one can of paint covers
  • $m$ ($0 \le m \le 10$) — the number of windows and doors

Then follow $m$ lines, each with two positive integers: the width and the height of one door or window, in feet. No window or door is larger than the largest wall.

The input ends with a line containing six zeros, which is not processed.

Output

For each test case, print a single integer on its own line: the number of cans of paint needed to paint the walls and ceilings of all the apartments that share this floor plan. Round up, because paint is sold only in whole cans.