This page is still under construction.

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

Food Cubes

Interview

Time limit1sMemory limit128 MB

Summary
Count the empty unit cells trapped inside a set of food cubes, where a hole is a maximal face-connected empty region that cannot reach the outside.
Level

Medium6 of 10

Topics
BFS, Graph, Simulation, Implementation
Solved
No attempts yet

Problem

The astronauts aboard a space shuttle are waiting for the next window to leave orbit and return to Earth. Bored with nothing to do, they decide to play a game with unit-size food cubes. In the zero-gravity cabin, anything stays exactly where it is placed. One astronaut arranges several food cubes in space, and empty gaps (holes) may appear between them. Given the coordinates of the cubes, the others must count the holes.

Partition 3D space into unit cells of side length 1. Each food cube occupies exactly one unit cell identified by integer coordinates (x,y,z)(x, y, z). A cell that holds no food cube is called empty. Two cells are adjacent when they share a face, i.e. exactly one of their three coordinates differs by 11.

A hole is a maximal group of empty cells connected through shared faces that is completely surrounded by food cubes on all six sides, so it cannot reach the infinite space outside. Write a program that reads the coordinates of the food cubes and computes the number of holes.

Input

The first line contains an integer tt (1≤t≤201 \le t \le 20), the number of test cases. Each test case begins with an integer MM, the number of food cubes. Each of the following MM lines contains the three coordinates xix_i, yiy_i, ziz_i of one food cube, all integers between 11 and 100100 inclusive.

Output

For each test case, print the number of holes on its own line.

Examples3

  1. Example 1

    Input
    2
    26
    1 1 1
    1 2 1
    1 3 1
    2 1 1
    2 2 1
    2 3 1
    3 1 1
    3 2 1
    3 3 1
    1 1 2
    1 2 2
    1 3 2
    2 1 2
    2 3 2
    3 1 2
    3 2 2
    3 3 2
    1 1 3
    1 2 3
    1 3 3
    2 1 3
    2 2 3
    2 3 3
    3 1 3
    3 2 3
    3 3 3
    7
    1 1 1
    1 1 2
    1 2 1
    1 2 2
    2 1 1
    2 1 2
    2 2 1
    
    Expected output
    1
    0
    
  2. Example 2

    Input
    1
    1
    5 5 5
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    26
    1 1 1
    1 1 2
    1 1 3
    1 2 1
    1 2 2
    1 2 3
    1 3 1
    1 3 2
    1 3 3
    2 1 1
    2 1 2
    2 1 3
    2 2 1
    2 2 3
    2 3 1
    2 3 2
    2 3 3
    3 1 1
    3 1 2
    3 1 3
    3 2 1
    3 2 2
    3 2 3
    3 3 1
    3 3 2
    3 3 3
    
    Expected output
    1