Under construction

Still being built. Things may change

Windows

Interview

Time limit1sMemory limit128 MB

Summary
Given windows in opening order, answer clicks by returning the most recently opened window covering each click point, or background if none does.
Level

Easy3 of 10

Topics
Array, Brute force, Implementation, Simulation
Solved
No attempts yet

Problem

Emma is careless with her computer's desktop: she keeps opening windows and never closes the applications that created them. Her desktop becomes a cluttered pile in which some windows only peek out from behind others and some are hidden entirely. Because Emma leaves her machine on for days, the mess grows enormous. Your task is to determine which window (if any) is selected when Emma clicks a given point on the screen.

When Emma clicks, the selected window is the topmost window covering that point — that is, the most recently opened window that contains it. Clicking a window does not bring it to the front.

The screen has a resolution of 106×10610^6 \times 10^6 pixels. The pixel in the upper-left corner of the desktop is at position (0,0)(0, 0), so the lower-right pixel is at (999999,999999)(999999, 999999). Rows are numbered top to bottom and columns left to right. A window is given by the position of its upper-left pixel (r,c)(r, c) together with its width ww and height hh; it covers exactly the pixels in rows rr through r+h−1r + h - 1 and columns cc through c+w−1c + w - 1.

Input

The input contains a sequence of desktop descriptions.

Each description begins with a line containing a positive integer nn (n≤100n \le 100), the number of windows, followed by nn lines listing the windows in the order Emma opened them. Each window line contains four integers rr, cc, ww, and hh: (r,c)(r, c) is the row and column of the window's upper-left pixel (0≤r,c≤9999990 \le r, c \le 999999), and ww and hh are its width and height in pixels (w,h≥1w, h \ge 1). Every window lies entirely on the desktop, so no window is cropped.

After the window lines comes a line with a positive integer mm, the number of queries, followed by mm lines. Each query line contains two integers crcr and cccc, the row and column of a clicked location, which is always on the desktop.

The input ends with a line containing a single 00 in place of the window count nn.

Output

For each desktop description, in the order given, first print a line Desktop k:, where kk is the desktop number starting from 11. Then print mm lines, one per query in order: print window k if the click selects the window numbered kk, or background if the click hits no window. Windows are numbered 1,2,…,n1, 2, \ldots, n in the order Emma opened them. Remember that a query never changes which window is in front.

Examples1

  1. Example 1

    Input
    3
    1 2 3 3
    2 3 2 2
    3 4 2 2
    4
    3 5
    1 2
    4 2
    3 3
    2
    5 10 2 10
    100 100 100 100
    2
    5 13
    100 101
    0
    
    Expected output
    Desktop 1:
    window 3
    window 1
    background
    window 2
    Desktop 2:
    background
    window 2