The following languages are only available languages for the problems from the contest

Kotlin Heroes: Episode 2:

- Kotlin 1.4.31

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
H. Road Repair in Treeland

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThere are $$$n$$$ cities and $$$n-1$$$ two-way roads in Treeland. Each road connects a pair of different cities. From any city you can drive to any other, moving only along the roads. Cities are numbered from $$$1$$$ to $$$n$$$. Yes, of course, you recognized an undirected tree in this description.

The government plans to repair all the roads. Each road will be repaired by some private company. In total, the country has $$$10^6$$$ private companies that are numbered from $$$1$$$ to $$$10^6$$$. It is possible that some companies will not repair roads at all, and some will repair many roads.

To simplify the control over the work of private companies, the following restriction was introduced: for each city, we calculate the number of different companies that repair roads that have this city at one end. This number for each city should not exceed $$$2$$$. In other words, for each city, there should be no more than two different companies that repair roads related to this city.

The National Anti-Corruption Committee of Treeland raises concerns that all (or almost all) of the work will go to one private company. For this reason, the committee requires that roads be distributed among companies in such a way as to minimize the value of $$$r$$$. For each company, we calculate the number of roads assigned to it, the maximum among all companies is called the number $$$r$$$.

Help the government find such a way to distribute all roads among companies in the required way.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of input cases in the input. Next, the input cases themselves are given. The first line of each test case set contains an integer $$$n$$$ ($$$2 \le n \le 3000$$$) — the number of cities in Treeland. Next, in the $$$n-1$$$ lines the roads are written: a line contains two integers $$$x_i$$$, $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$), indicating that the $$$i$$$-th road connects the cities $$$x_i$$$ and $$$y_i$$$.

It is guaranteed that the sum of all values $$$n$$$ for all test cases in the input does not exceed $$$3000$$$.

Output

Print the answers for all $$$t$$$ test cases in the input. Each test case must begin with a line that contains $$$r$$$ — the minimum possible number of roads assigned to the most used company. Next, in the next line print $$$n-1$$$ the number $$$c_1, c_2, \dots, c_{n-1}$$$ ($$$1 \le c_i \le 10^6$$$), where $$$c_i$$$ indicates the company to repair the $$$i$$$-th road. If there are several optimal assignments, print any of them.

Example

Input

3 3 1 2 2 3 6 1 2 1 3 1 4 1 5 1 6 7 3 1 1 4 4 6 5 1 2 4 1 7

Output

1 10 20 3 1 1 1 2 2 2 11 11 12 13 12 13

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/03/2022 21:16:23 (j3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|