Horizontally Visible Segments

Time limit1sMemory limit128 MB

Problem

You are given a set of pairwise disjoint vertical line segments in the plane (no two segments share any point).

Two segments are said to be horizontally visible if they can be joined by a horizontal segment that has no common point with any other vertical segment. Three distinct vertical segments form a triangle of segments if each of the three pairs among them is horizontally visible.

For each data set, read the description of a set of vertical segments and report how many triangles of segments it contains.

Input

The first line contains one positive integer $d$, the number of data sets, with $1 \le d \le 20$. The data sets follow.

The first line of each data set contains one integer $n$ with $1 \le n \le 8000$, the number of vertical segments. Each of the next $n$ lines contains three non-negative integers $y_i'$, $y_i''$, $x_i$ separated by single spaces: the $y$-coordinate of the lower endpoint, the $y$-coordinate of the upper endpoint, and the $x$-coordinate of the $i$-th segment. The coordinates satisfy $0 \le y_i' < y_i'' \le 8000$ and $0 \le x_i \le 8000$, and the segments are pairwise disjoint.

Output

Print exactly $d$ lines, one per data set. The $i$-th line must contain a single integer: the number of triangles of segments in the $i$-th data set.