Stingy Country time limit:MS | Memory limit:65535 KB Difficulty:3
-
Describe
-
there are n cities in a stingy country, and only N-1 roads connect the n cities between the N cities. Now, Tom in City number one, he has a map of the country, he wants to know if you want to visit the city of T, must go past the city is the number of cities (assuming you do not go the way of repetition).
-
Input
-
The first line enters an integer m for the test data Total m (1<=m<=5) group the first row of each set of test data enter a positive integer n (1<=n<=100000) and a positive integer S (1<=s<=100000), N indicates the total number of cities , s indicates the number of the city where the visitor is located followed by the N-1 line, with two positive integers a, B (1<=a,b<=n) per line, indicating a link between City A and City B.
-
Output
-
Each set of test data outputs n positive integers, where the number of I represents the number of the previous city that must pass from S to City I. (When i=s, please output-1)
-
Sample input
-
110 11 91 88 1010 38 61 210 49 53 7
-
Sample output
-
-1 1 10 10 9 8 3 1 1 8
Nyoj 20 Stingy Kingdom