Megalopolis

No attempts yetTime limit1sMemory limit128 MB

Problem

Byteotia has nn villages, numbered from 11 to nn. Long ago they were joined by n1n - 1 bidirectional dirt roads, called country roads, so that village 11 (named Bitburg) could be reached from every other village in exactly one way. On that unique route from a village toward Bitburg, every village along the way had a number less than or equal to the village it started from, and each road joined exactly two distinct villages.

As time passed, the country roads were rebuilt into motorways one after another, until not a single dirt road remained. Byteasar the postman remembers the exact moment each road was rebuilt. He also recalls his deliveries: every trip began at Bitburg (village 11) and ended at some village, and he now wonders how many country roads he walked along on each trip.

You are given the road network and a chronological list of events. Each event is either a road being turned into a motorway or one of Byteasar's trips. For every trip, report how many country roads lay on the path from village 11 to the destination village at that moment.

Input

The first line contains an integer nn (1n2500001 \le n \le 250000), the number of villages.

Each of the next n1n - 1 lines contains two integers aa and bb (1a<bn1 \le a < b \le n), meaning that a country road joins villages aa and bb.

The next line contains an integer mm (1m2500001 \le m \le 250000), the number of trips.

The following n+m1n + m - 1 lines describe the events in chronological order, one per line:

  • A a b (with a<ba < b): the country road between villages aa and bb is turned into a motorway at this moment.
  • W a: Byteasar makes a trip from Bitburg (village 11) to village aa.

Output

Print exactly mm integers, one per line. The ii-th line is the number of country roads on the path from village 11 to the destination of Byteasar's ii-th trip, counted at the moment that trip is made.

Hint

The figure below illustrates the tree of the first example.