Equivalence in Connectivity
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

Two undirected graphs of size n are equivalent in connectivity when there is a path from u to v in one graph if and only if there is a path from u to v in the other graph for all .

Given k graphs G_1, G_2, , G_k of size n, for each , 3, , k, there exists such that G_i can be derived from by adding or removing an edge. Divide them into groups, such that two graphs are in the same groups if and only if they are equivalent in connectivity.

输入描述:

There are multiple test cases. The first line of input contains an integer T(), the number of test cases. For each test case:
The first line contains three integers k, n and m (, , ) - the number of graphs, the number of vertices of each graph, and the number of edges of G_1.

Each of the following m lines contains two integers u and v (), denoting an edge of G_1 connecting u and v. It is guaranteed that there are no multiple edges in G_1.

The i-th of following k-1 lines contains an integer , a string , and two integers and (, ). t_i is one of "add" and "remove"

If "add", is derived from by adding an edge connecting and . It is guaranteed that there does not exist the edge in .

If "remove", is derived from by removing an edge connecting and . It is guaranteed that there exists the edge in .

It is guaranteed that the sum of n, the sum of m, and the sum of k in all test cases do not exceed .

输出描述:

For each test case:

Output an integer r - the number of the groups in the first line.

For each group, output an integer k and k integers - the size of the group and the numbers of graphs in one line.

You can output the groups and the graphs in any order.
示例1

输入

复制
2
15 11 8
6 11
1 6
6 9
6 8
1 2
1 5
9 10
2 5
1 add 3 11
1 add 2 3
3 add 5 8
4 add 5 11
3 add 7 10
1 add 6 10
3 add 3 10
1 remove 6 8
5 add 4 9
1 add 2 9
8 add 7 8
3 add 2 4
1 remove 6 9
10 remove 6 9
14 5 2
1 5
1 4
1 add 2 4
1 add 3 4
1 add 2 4
4 add 3 4
4 add 1 3
5 add 1 3
2 add 2 3
1 add 1 2
4 add 3 4
3 add 4 5
9 add 2 3
3 remove 1 5
3 remove 3 4

输出

复制
7
2 10 13
5 2 3 4 5 8
3 1 7 11
1 14
2 6 12
1 9
1 15
5
3 2 4 9
6 5 6 7 8 10 12
2 1 14
2 3 11
1 13