Education Nightmare

아직 제출이 없습니다시간 제한10초메모리 제한512 MB

문제

You are having a nightmare! In the dream, you have finished your education and you are now to start teaching others. And today is your first day! You enter the school building (being a little late) and... of course, you have forgotten which room your class takes place in.

The building consists of nn rooms, numbered 1,2,,n1, 2, \ldots, n. Some pairs of rooms are connected with a passage. You may move between connected rooms, each transfer taking exactly one second. There are exactly n1n - 1 passages in the building, and every room can be reached, given enough time. In other words, the rooms and passages form a tree.

You start in room ss. If you enter the correct room, you will immediately recognize it and end your quest. Even so, searching all the rooms could take really long... Fortunately, there is one more trick you can use: in the room mm there is a complete timetable of all classes. If you ever enter room mm, you immediately learn where the class is, and you may go there at once, using the shortest route (be advised, though: the room mm does not provide any printing, faxing, scanning or photocopy services. You shouldn't ask them about it).

Find the minimal time tt needed to find your class in the worst case, that is, the minimal number tt for which there is a strategy guaranteeing finding the correct room in tt seconds.

입력

The first line of input contains the number of test cases zz (1z1091 \leq z \leq 10^9). The descriptions of the test cases follow.

The first line of each test case contains three integers: the number of rooms nn, the starting room ss, and the room with the timetable mm (1n200,0001 \leq n \leq 200\\,000, 1s,mn1 \leq s, m \leq n). Then, n1n - 1 lines follow, each containing two integers a,ba, b (1a,bn1 \leq a, b \leq n, aba \neq b), denoting a passage between rooms aa and bb. It is guaranteed that every room can be reached from every other one.

It is possible for the class to take part in room ss or in room mm. It is also possible to start in room mm.

The total number of rooms in all test cases does not exceed 10710^7.

출력

For each test case, output a single integer: the total number of seconds needed to reach the classroom, assuming the best possible strategy.