Equivalence in Connectivity

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Two undirected graphs of size nn are equivalent in connectivity when there is a path from uu to vv in one graph if and only if there is a path from uu to vv in the other graph for all 1u\<vn1\le u\<v\le n.

Given is a sequence of kk graphs G_1,G_2,,G_kG\_1, G\_2, \ldots, G\_k. Each graph is of size nn. In this sequence, for each i=2,3,,ki = 2, 3, \ldots, k, there exists p_i\<ip\_i\<i such that G_iG\_i can be obtained from G_p_iG\_{p\_i} by adding or removing an edge. Divide the given graphs into groups: two graphs must be in the same group if and only if they are equivalent in connectivity.

입력

There are multiple test cases. The first line of input contains an integer TT (1T1051\le T\le 10^5), the number of test cases. For each test case:

The first line contains three integers kk, nn, and mm (1k,n1051 \le k, n \le 10^5, 0mmin(105,n(n1)2)0 \le m \le \min \left( 10^5, \frac{n(n - 1)}{2} \right)): the number of graphs, the number of vertices in each graph, and the number of edges in G_1G\_1.

Each of the following mm lines contains two integers uu and vv (1u<vn1\le u < v\le n), denoting an edge of G_1G\_1 connecting uu and vv. It is guaranteed that there are no multiple edges in G_1G\_1.

The ii-th of the following k1k-1 lines contains an integer p_i+1p\_{i+1}, a string t_i+1t\_{i+1}, and two integers x_i+1x\_{i+1} and y_i+1y\_{i+1} (1p_i+1i1\le p\_{i+1}\le i, 1x_i+1\<y_i+1n1\le x\_{i+1}\<y\_{i+1}\le n). Each string t_i+1t\_{i+1} is either "add" or "remove".

If t_i+1t\_{i+1} is "add", then G_i+1G\_{i+1} is obtained from G_p_i+1G\_{p\_{i+1}} by adding an edge connecting x_i+1x\_{i+1} and y_i+1y\_{i+1}. It is guaranteed that this edge does not exist in G_p_i+1G\_{p\_{i+1}}.

If t_i+1t\_{i+1} is "remove", then G_i+1G\_{i+1} is obtained from G_p_i+1G\_{p\_{i+1}} by removing an edge connecting x_i+1x\_{i+1} and y_i+1y\_{i+1}. It is guaranteed that this edge exists in G_p_i+1G\_{p\_{i+1}}.

It is guaranteed that the sum of nn, the sum of mm, and the sum of kk in all test cases do not exceed 10510^5.

출력

For each test case:

On the first line, output an integer rr: the number of groups.

For each group, output a single line which contains an integer kk followed by kk integers: the size of the group and the numbers of graphs in the group.

You can output the groups and the graphs in any order.