Under construction

Still being built. Things may change

Jaeha's Toy

Time limit1sMemory limit1024 MB

Summary
Given a closed polyline whose segments may cross each other, count the bounded regions with positive area that it forms.
Level

Medium6 of 10

Topics
Geometry, Graph, Implementation
Solved
No attempts yet

Problem

Jaeha is a star baby who was born not long ago, and he grew up in no time. He is so curious, like whoever he takes after, that he keeps reaching out to touch things around him. Jaeha's father and mother bought him a toy for this. The toy is a ring of line segments joined end to end, so it is hard for a baby to put in his mouth.

Jaeha got mischievous and began twisting the toy into all sorts of shapes, like these.

Strictly speaking, the toy is a polygon defined by the points (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), ⋯\cdots, (xn,yn)(x_n, y_n), and back to (x1,y1)(x_1, y_1), where adjacent points are joined by line segments. The segments may cross each other.

Count the regions with an area greater than 0 that the toy forms. The infinite outer region that existed from the start is not counted.

Input

The input consists of TT test cases. The first line contains TT.

The first line of each test case contains NN (3≤N≤1003 \le N \le 100), the number of vertices of the toy. The next NN lines each contain the coordinates xix_i and yiy_i (0≤xi,yi≤1000 \le x_i, y_i \le 100) of a vertex. Within a test case, no two vertices have the same coordinates.

Output

For each test case, print on its own line the number of regions described in the problem.

Examples1

  1. Example 1

    Input
    2
    4
    0 1
    1 0
    1 1
    0 0
    6
    0 0
    1 0
    1 1
    2 1
    2 0
    3 0
    
    Expected output
    2
    1