SP839 OPTM - Optimal Marks

Description

You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range \[0..2 $ ^{31} $ – 1\]. Different vertexes may have the same mark. For an edge (u, v), we define Cost(u, v) = mark\[u\] xor mark\[v\]. Now we know the marks of some certain nodes. You have to determine the marks of other nodes so that the total cost of edges is as small as possible.

Input Format

The first line of the input data contains integer **T** (1 ≤ **T** ≤ 10) - the number of testcases. Then the descriptions of T testcases follow. First line of each testcase contains 2 integers **N** and **M** (0 < **N**

Output Format

For each testcase you should print **N** lines integer the output. The **K**th line contains an integer number representing the mark of node **K**. If there are several solutions, you have to output the one which minimize the sum of marks. If there are several solutions, just output any of them.