logo AlgoBeat OnlineJudge
登录 注册

#209290. [EC Final 2022] Rectangle

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

题目描述

Prof. Pang has rectangles, the coordinate of the lower left corner of the -th rectangle is , and the coordinate of the upper right corner is . Rectangles may overlap.

You need to choose three straight lines such that:

  • Each line should be parallel to the -axis or the -axis, which means its formula is or .
  • In the formula or , should be an integer in .
  • These three lines should be distinct.
  • Each rectangle is by at least one line. A line touches a rectangle if it intersects with the boundary and/or the interior of the rectangle.

You need to compute the number of ways to choose three lines. Since the answer can be very large, output it modulo . Two ways are considered the same if only the order of three lines differs in these two ways.

输入格式

The first line contains a single integer , denoting the number of test cases.

For each test case, the first line contains an integer . The -th line of the next lines contains four integers .

It is guaranteed that the sum of over all test cases does not exceed .

输出格式

For each test case, output one integer representing the answer in one line.

样例

样例输入 1

3
1
1 1 1000000000 1000000000
3
1 1 2 2
3 3 4 4
5 5 6 6
5
581574116 47617804 999010750 826131769
223840663 366320907 613364068 926991396
267630832 51913575 488301124 223957497
217461197 492085159 999485867 913732845
28144453 603781668 912516656 993160442

样例输出 1

230616300
64
977066618