Sky Tax

On a tree with a moving capital, each vertex answers for all vertices whose path to the capital passes through it; move the capital or query a vertex's count.

Hard8TreeDFSImplementationPrefix sumNo attempts yetTime limit1sMemory limit512 MB

Problem

New Bangkok is a newly built province of Thailand that floats in the sky. To keep the province in the air, one spaceship holds up each city. All the spaceships move in the same direction at the same speed, so the structure of the province stays still.

The cities are connected by sky ways. A sky way is a floating road between two cities, and a citizen can travel from any city to any other city using sky ways alone. Urban planning is thorough, so between one city and another there is exactly one simple route, meaning no route uses the same sky way twice.

The province is new and moves its capital often. Its tax rule is unusual: if the route from city BB to the capital passes through city AA, then AA must handle the tax of BB. The route includes both of its endpoints, BB and the capital, so every city handles at least its own tax. One city can end up handling the taxes of many cities.

You are given the structure of the province, the initial capital, and a number of queries. Each query is one of the following.

  1. Move the capital to city UU.
  2. Report how many cities city UU has to handle taxes for.

Input

The first line contains the number of test cases TT. (T10T \le 10)

The first line of each test case contains the number of cities NN, the number of queries QQ, and the initial capital RR, in that order. (1N1000001 \le N \le 100000, 1Q500001 \le Q \le 50000, 1RN1 \le R \le N)

Each of the next N1N - 1 lines describes one sky way with two integers AA and BB, meaning city AA and city BB are connected by a sky way. (1AN1 \le A \le N, 1BN1 \le B \le N, ABA \ne B)

Each of the next QQ lines describes one query with two integers SS and UU. (0S10 \le S \le 1, 1UN1 \le U \le N) If SS is 00, move the capital to city UU. If SS is 11, report the number of cities that city UU has to handle taxes for.

Output

Process the test cases and the queries in the order they appear in the input.

At the start of test case II, print a line of the form Case #I:, where I is the test case number.

Then print the answer to each query that asks for one, one answer per line. A query that moves the capital prints nothing.