문제1640--City Horizon

### 1640: City Horizon

실행시간 제한: 1 Sec  메모리사용 제한: 128 MB
제출: 109  통과: 21
[제출] [채점기록] [묻고답하기]

#### 문제 설명

Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings.

The entire horizon is represented by a number line with N (1 ≤ N ≤ 40,000) buildings. Building i's silhouette has a base that spans locations Ai through Bialong the horizon (1 ≤ Ai < Bi ≤ 1,000,000,000) and has height Hi (1 ≤ Hi ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by all N buildings.

#### 입력 설명

Input consists of several test cases. The first line of whole input contains a single integer T, the number of test cases.

Then T test cases follow. The first line of each test case contains a single integer N. Then N lines follow, describing each building with three space-separated integers  AiBi, and Hi .

#### 출력 설명

For each test case, write a single line which contains the total area, in square units, of the silhouettes formed by all N buildings.

#### 입력 예시 Copy

1
4
2 5 1
9 10 4
6 8 2
4 6 3

#### 출력 예시 Copy

16