#P9833. Teyvat

Teyvat

Teyvat

Problem Description

Yoshinow2001 has not logged in the GenshinImpact for a long time, and there are many more Dendroculus on the map of the Teyvat continent. The map of the GenshinImpact can be seen as an undirected connected graph\textbf{undirected connected graph} G=(V,E)G=(V,E) of nn points, mm edges, where each vertex vVv\in V represents a location on the map, and each edge e=(vs,vt)e=(v_s,v_t) represents a road from the point vsv_s to vtv_t. Since Yoshinow2001 has a lot of Dendroculus did not take, so he will give you a total of QQ queries, each query indicates that there are kk vertexs {a1,a2,,ak}\{a_1,a_2,\dots,a_k\} on the graph GG, these vertexs need to take Dendroculus. He wants to know how many vertex pairs (S,T)(S,T) satisfy 1STn1\leq S\leq T\leq n so that any simple path from SS to TT passes through all vertexs in the set {a1,,ak}\{a_1,\dots,a_k\} exactly once.

Input

Each test contains multiple test cases.The first line of input contains a single integer T(1T1×104)T(1\leq T\leq 1\times 10^4)----the number of test cases.The description of test cases follows. The first line contains three integers $n,m,Q(1\leq n\leq 5\times 10^5,1\leq m,Q\leq 1\times 10^6)$ correspondingly represent the number of vertexs, the number of edges, the number of queries. The following mm lines contains two integers ui,vi(uivi) u_i,v_i ( u_i \neq v_i ) indicating an undirected edge between uiu_i and viv_i. It is guaranteed that i,j:1i<jm\forall i,j:1\leq i\lt j\leq m satisfy (ui,vi)(uj,vj)(u_i,v_i)\neq (u_j,v_j). The following QQ lines. Each line begins with an integer kk, representing the number of vertexs queried. Next kk integers a1,,aka_1,\dots,a_k, representing the vertexs. It is guaranteed that the sum of nn for each test cases does not exceed 1.5×1061.5\times 10^6, the sum of m,Q,i=1Qkim,Q,\sum_{i=1}^{Q}{k_i} for each test cases does not exceed 3×1063\times 10^6.

Output

For each test case, output QQ lines, where the ii-th line contains an integer, representing the answer to the ii-th query. Notes: In this problem, you may need more stack space to pass this problem. We suggest you to add the following code into your main function if you use C++.

int main() {
int size(512<<20); // 512M
__asm__ ( "movq %0, %%rsp\n"::"r"((char*)malloc(size)+size));
// YOUR CODE
...
exit(0);
}

And if you use the code above please DON’T forget to add exit(0)\textbf{DON'T forget to add exit(0)}; in the end of your main function, otherwise your code may get RE.

Sample Input

1
3 3 3
1 3
3 2
1 2
1 1
2 2 3
3 1 2 3

Sample Output

3
1
0

Source

2023“钉耙编程”中国大学生算法设计超级联赛(4)