Rectangles

You have n rectangles, each of which is described by three integers i, j and k. This indicates that the lower-left corner of the rectangle will be located at the point (i, 0) and the upper-right corner of the rectangle will be located at the point (j, k). For example, if you have a description of four rectangles like this: 0 2 3 0 3 1 1 2 2 2 4 4 The area occupied by these rectangles will be as follows:

The total area in this case will be 14. You are given n and n triples (i, j, k), your task is to compute the total area occupied by the rectangles which are described by the n triples.

Input

The first line will contain a single integer T indicates the number of test cases. Each test case will consist of n + 1 lines, the first one will contain the number of rectangles n and the following n lines will be the description of the rectangles. Each description will be a triple (i, j, k) as mentioned above. The Constraints: 10 <= T <= 20 1 <= n <= 100 0 <= i < 100 1 <= j < 100 i != j 1 <= k <= 100

Output

For each test case, print a single integer in a separated line indicates the total area occupied by the rectangles.

Examples

input

Copy

1
4
0 2 3
0 3 1
1 2 2
2 4 4


output

Copy

14


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int t,n,j,i,k,o,x,y,s,c[300][300];
scanf("%d",&t);
while(t--)
{
memset(c,0,sizeof(c));
s=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d%d",&x,&y,&o);
for(j=x;j<y;j++）
for(k=0;k<o;k++)
c[j][k]++;
}
for(j=0;j<110;j++)
{
for(k=0;k<110;k++)
{
if(c[j][k]>0)
s++;
}
}
printf("%d\n",s);
}
return 0;
}

• 写评论