Under construction

Still being built. Things may change

Hanging Hats

Time limit3sMemory limit128 MB

Summary
Simulate mages hanging triangular hats on a wall, tracking nail visibility and expulsion under coverage rules that require an advanced geometric data structure.
Level

Hard9 of 10

Topics
Geometry, Segment tree, Sorting, Simulation
Solved
No attempts yet

Problem

All mages wear pointed hats. At the Unheard University, before going to bed each mage hangs their hat on one very large shared wall. Hats come in only two shapes: wide and narrow.

The mages fall asleep one after another. Before going to bed, the ii-th mage takes their hat, picks an arbitrary position (xi,yi)(x_i, y_i) on the wall (where yi>0y_i > 0 is the height above the ground), hammers a nail there, and hangs the hat on that nail.

The hats are magical: once hung, a hat looks exactly like an isosceles triangle of height yiy_i. Its apex is at the nail (xi,yi)(x_i, y_i) and its bottom edge lies on the floor (the line y=0y = 0). A narrow hat has a bottom edge of length yiy_i; a wide hat has a bottom edge of length 2yi2 y_i. Equivalently, a point (x,y)(x, y) lies inside the ii-th hat, boundary included, exactly when 0≤y≤yi0 \le y \le y_i and

∣x−xi∣≤yi−y2(narrow),∣x−xi∣≤yi−y(wide).|x - x_i| \le \frac{y_i - y}{2} \quad (\text{narrow}), \qquad |x - x_i| \le y_i - y \quad (\text{wide}).

Every nail head glows in the dark. A nail stops being visible the moment it is covered by a hat hung later (lying on that hat’s boundary already counts as covered). Furthermore, if a mage tries to hammer a nail at a point that is already covered by some hanging hat (boundary included), that mage is expelled and both the nail and the hat are discarded — the hat is never hung.

After every mage acts, report how many glowing nail heads are visible.

Input

The first line contains the number of test cases ZZ (1≤Z≤301 \le Z \le 30). The test cases follow one after another.

Each test case starts with a line containing an integer nn (1≤n≤1051 \le n \le 10^5), the number of mages. Each of the next nn lines describes one mage, in the order they go to sleep, and contains two integers xix_i (−109≤xi≤109-10^9 \le x_i \le 10^9) and yiy_i (1≤yi≤1091 \le y_i \le 10^9) followed by a single letter: W for a wide hat or N for a narrow hat.

Output

For each test case output nn lines. The ii-th line must be FAIL if the ii-th mage was expelled while hammering the nail. Otherwise it must contain a single integer: the number of glowing nail heads visible immediately after the ii-th mage hangs their hat.

Examples4

  1. Example 1

    Input
    2
    3
    0 1 W
    0 2 N
    0 1 W
    7
    4 3 W
    8 8 N
    3 2 W
    9 5 W
    12 1 W
    14 2 N
    13 4 W
    
    Expected output
    1
    1
    FAIL
    1
    2
    FAIL
    FAIL
    3
    4
    3
    
  2. Example 2

    Input
    1
    1
    5 10 W
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    2
    0 10 W
    9 1 W
    
    Expected output
    1
    FAIL
    
  4. Example 4

    Input
    2
    2
    5 1 N
    0 10 W
    2
    5 1 N
    0 10 N
    
    Expected output
    1
    1
    1
    2