This page is still under construction.

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

What are Birds? (Small)

Time limit5sMemory limit512 MB

Summary
Given labeled bird and non-bird points in 2D, decide for unlabeled animals whether they must be birds, cannot be birds, or are unknown.
Level

Medium5 of 10

Topics
Intervals, Implementation, Math
Solved
No attempts yet

Problem

You are studying animals in a forest and want to decide which of them are birds.

For every animal you measure two numbers, its height and its weight. An animal is a bird exactly when its height lies inside one range and its weight lies inside another range. You do not know either range. Every animal that satisfies both ranges is a bird, without exception.

You showed some of the measured animals to biologists, and they told you which ones are birds. Those answers restrict what the height range and the weight range can be. For each animal you did not show them, decide whether it is certainly a bird, certainly not a bird, or undecided from the information you have.

The biologists are always right, so at least one pair of ranges agrees with every answer they gave.

Input

The first line contains an integer CC, the number of test cases.

Each test case is given as follows.

  • One line with an integer NN, the number of animals shown to the biologists.
  • NN lines, one per animal, in the form H W X, where HH is the height, WW is the weight, and XX is either BIRD or NOT BIRD.
  • One line with an integer MM, the number of animals not shown to the biologists.
  • MM lines, one per animal, in the form H W, the height and the weight.

Limits

  • 1≤C≤101 \le C \le 10
  • 1≤N≤101 \le N \le 10
  • 1≤M≤101 \le M \le 10
  • Every height and weight is an integer with 1≤H,W≤10000001 \le H, W \le 1000000.

Output

For each test case print M+1M + 1 lines.

  • One line with Case #X:, where XX is the number of the test case, counting from 1.
  • MM lines with the verdict for each animal you did not show, in input order. Print BIRD if the animal must be a bird, NOT BIRD if it cannot be a bird, and UNKNOWN if both are still possible.

Notes on the example

In case 1 of the example, the animal 1500 1500 must be a bird, because the height range and the weight range each contain 1000 and 2000. The animal 900 900 may or may not be a bird, since nothing tells you whether 900 falls inside either range. The animal 1400 2020 lies inside the height range, but if 2020 were inside the weight range, then 1500 2010, which is known not to be a bird, would also fall inside both ranges. So 1400 2020 is not a bird.

In case 2 you know that a bird must have height 501. About the weight range you only know that it contains 700.

In case 3 you know that an animal of height 100 and weight 100 is not a bird, and nothing more.

Examples1

  1. Example 1

    Input
    3
    5
    1000 1000 BIRD
    2000 1000 BIRD
    2000 2000 BIRD
    1000 2000 BIRD
    1500 2010 NOT BIRD
    3
    1500 1500
    900 900
    1400 2020
    3
    500 700 NOT BIRD
    501 700 BIRD
    502 700 NOT BIRD
    2
    501 600
    502 501
    1
    100 100 NOT BIRD
    3
    107 93
    86 70
    110 115
    
    Expected output
    Case #1:
    BIRD
    UNKNOWN
    NOT BIRD
    Case #2:
    UNKNOWN
    NOT BIRD
    Case #3:
    UNKNOWN
    UNKNOWN
    UNKNOWN