logo AlgoBeat OnlineJudge
登录 注册

#210371. [ICPC 2024 Xi'an I] Yet Another Maximum Matching Counting Problem

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

题目描述

There is a two-dimensional plane.

You have a set of points that satisfies (Both and are integers), and there are no two points with the same coordinates.

If two points have the same horizontal or vertical coordinates, we will connect an edge between these two points. This forms a graph.

You need to find the sum of the maximum number of matches in the graphs formed by all possible non empty sets, and output the result modulo .

Here, the maximum number of matches in a graph is defined as: selecting the most edges so that there are no common vertices between any two edges.

输入格式

There are multiple testcases in this problem.

The first line contains an integer , which represents the number of testcases.

Each of the testcases contains two integers .

输出格式

For each of the testcases, print an integer representing the result modulo .

样例

样例输入 1

10
1 1
1 2
2 2
4 4
3 3
5 5
1 8
20 20
100 100
500 500

样例输出 1

0
1
10
241456
964
200419152
448
985051144
370696900
357517517