This page is still under construction.

Parts of this page are still being built. What you see may change.

Library Codes

Time limit1sMemory limit128 MB

Summary
For each book, print horizontal if f times label length plus 2 is at most the book width, otherwise print vertical.
Level

Easy1 of 10

Topics
Implementation
Solved
No attempts yet

Problem

A library is relabelling its books using the Dewey Decimal classification. Whenever it fits, a label is printed horizontally; if the text is wider than the book, it is printed vertically instead.

The label uses a fixed-pitch (monospaced) font, so every character occupies exactly ff mm of width. For readability, a 1 mm gap must be left both before and after the printed text. A label can therefore be printed horizontally only when

f×L+2≤wf \times L + 2 \le w

where LL is the number of characters in the label text and ww is the width of the book in mm. Otherwise the label must be printed vertically.

Given each library's character width, each book's width, and each label's text, decide for every book whether its label is printed horizontally or vertically.

Input

The input describes several libraries.

Each library is given as follows:

  • The first line contains the library's name (letters only, no spaces, at most 20 characters) and a single integer ff (1<f<81 < f < 8), the width in mm of one character, separated by a space.
  • The next line contains a single integer cc, the number of books for this library.
  • Each of the following cc lines describes one book: an integer ww (5≤w≤505 \le w \le 50), the width of the book in mm, and the label text (between 3 and 6 characters, no spaces), separated by a space.

The input ends with a line containing # 0 (a #, a space, then a 0); this line is not a library and must not be processed.

Output

For each library, first print the library's name followed by a space and the word Library on its own line. Then, for each book in the order given, print a line Book k horizontal or Book k vertical, where kk is the book's position in the library's list starting from 1, and the word is horizontal if the label fits horizontally or vertical otherwise.

Examples2

  1. Example 1

    Input
    Auckland 3
    6
    11 811
    25 636.7
    38 330.94
    29 398.2
    16 398.6
    18 973.05
    Wellington 4
    2
    35 636
    12 398.2
    # 0
    
    Expected output
    Auckland Library
    Book 1 horizontal
    Book 2 horizontal
    Book 3 horizontal
    Book 4 horizontal
    Book 5 vertical
    Book 6 vertical
    Wellington Library
    Book 1 horizontal
    Book 2 vertical
    
  2. Example 2

    Input
    Testlib 2
    4
    8 123
    7 123
    9 1234
    6 12.4
    # 0
    
    Expected output
    Testlib Library
    Book 1 horizontal
    Book 2 vertical
    Book 3 vertical
    Book 4 vertical