Operating on a Graph
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You are given a graph containing n vertices and m edges. Vertices are numbered from 0 to n-1. Initially, vertex i belongs to group i. We define a group A is connected to group B if and only if there exists at least an edge that connects the two vertices which belong to A and B respectively.

Now we will do q operations on this graph. The i-th operation is represented by an integer o_i.

In i-th operation, if there are no vertices belong to group o_i, nothing happens. Otherwise, for all vertices belong to a group which is connected to o_i, those vertices will belong to group  o_i after this operation.

Now you are also given the q operations. Please answer each vertex belongs to which group after all operations.

输入描述:

The first line contains one integer t () --- the number of test cases.

The first line of each test contains two positive integers n and m (, ) --- the number of vertices and edges in the given graph.

The following are m lines. Each of them contains two integers x and y, indicating there is an edge between vertex x and vertex y (, there are no duplicate edges in the same test)

The following line contains one integer q () -- the number of operations in this test. Then there is one more line contains q integers ().

The sum of n across the test cases doesn't exceed .

The sum of m across the test cases doesn't exceed .

And the sum of q across the test cases doesn't exceed .

输出描述:

For each test, output one line contains n integers --- the i-th integer of them representing the group that the vertex i-1 belongs to.
示例1

输入

复制
5
4 3
0 1
1 2
2 3
4
0 1 3 0
4 3
0 1
1 2
2 3
2
0 2
4 3
0 1
1 2
2 3
2
0 3
4 1
1 3
1
2
5 5
0 1
0 2
1 2
1 3
3 4
3
4 4 0

输出

复制
0 0 0 0
2 2 2 2
0 0 3 3
0 1 2 3
0 0 0 0 0

说明

Take the first test for example:

Initially, the four vertex is belong to 0, 1, 2, 3 respectively.

After the first operation, the four vertex is belong to 0, 0, 2, 3 respectively.

After the second operation, because there is no vertex belong to 1 now. The four vertex is still belong to 0, 0, 2, 3 respectively.

After the third operation, the four vertex is belong to 0, 0, 3, 3 respectively.

After the last operation, the four vertex is belong to 0, 0, 0, 0 respectively.