logo AlgoBeat OnlineJudge
登录 注册

#209258. [ICPC 2022 Jinan R] Set of Intervals

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Prof. Pang has a multi-set of intervals ().

Prof. Pang will perform the following operation for times:

  • Select two intervals and from , and then choose two integers satisfying . After that, delete and from , and add to .

It's easy to find that contains exactly one interval after the operations, and Prof. Pang will get the interval as a gift.

Now Prof. Pang wants you to calculate how many different intervals he can get.

输入格式

The first line contains one integer (), the number of test cases.

For each test case, the first line contains one integer () --- the size of . Each of the following lines contains two integers and (), describing the -th interval in .

It is guaranteed that the sum of over all test cases is no more than .

输出格式

For each test case, output one line containing the answer to Prof. Pang's question.

样例

样例输入 1

4
1
1 1000000000
2
1 1000000000
1 1000000000
4
1 2
3 4
5 6
7 8
4
1 3
2 4
5 8
6 7

样例输出 1

1
499999999500000000
26
28