Ants and the Ladybug

No attempts yetTime limit1sMemory limit128 MB

Problem

Ants farm aphids: the aphids give off sweet honeydew that the ants drink, so the ants protect the aphids from their fiercest enemy, the ladybug. On a tree beside the anthill lives a colony of aphids that feeds on the tree's leaves and branch points.

The tree has nn places, its leaves and branch points, numbered from 11 to nn and joined by n1n-1 branches, so between any two places there is exactly one simple route. The tree is patrolled by kk guard-ants, numbered from 11 to kk; each ant stands on a place of its own, and no place holds more than one ant.

A ladybug lands on one of the places. The ants then try to chase her away, and they all move at the same speed: crossing one branch takes one unit of time. Each landing is resolved by the following rules:

  • If an ant already stands on the ladybug's place, she takes off at once, that ant is credited with chasing her away, and no ant moves for this landing.
  • Otherwise every ant heads toward her along the unique route from its place to hers, but an ant sets off only if no other ant stands on that route (its own place excepted); an ant that is blocked this way does not move at all and stays where it is.
  • All ants that set off advance together, one branch per unit of time.
  • If two or more ants would enter the same place at the same moment, only the lowest-numbered of them enters it; each of the others stops on its place and wanders no further.
  • The moment an ant reaches the ladybug's place it chases her away and stays there; at that instant every other ant also stops on the place it currently occupies.

The ladybug is stubborn and keeps returning, landing on the tree again and again. Each time she lands, the ants set off afresh from wherever they now stand.

Write a program that, given the tree, the ants' starting places, and the ladybug's successive landing places, reports for each ant its final place and how many times that ant chased the ladybug away.

Input

The first line holds one integer nn (1n50001 \le n \le 5000), the number of places. Each of the next n1n - 1 lines holds two integers aa and bb (1a,bn1 \le a, b \le n): a branch joins places aa and bb.

The next line holds one integer kk (1k10001 \le k \le 1000 and knk \le n), the number of ants. Each of the following kk lines holds one integer in [1,n][1, n]: the starting place of the ii-th ant. All starting places are distinct.

The next line holds one integer ll (1l5001 \le l \le 500), how many times the ladybug lands. Each of the following ll lines holds one integer in [1,n][1, n]: a landing place, given in the order the landings happen.

Output

Print kk lines. On the ii-th line print two integers separated by a single space: the final place of the ii-th ant and the number of times that ant chased the ladybug away.

Hint

The picture below shows the tree of the first example.

In that example the branches are 121-2, 131-3, and 242-4; ant 11 starts at place 11 and ant 22 starts at place 22. The ladybug first lands on place 22: ant 22 is already there, so it chases her away at once and nobody moves. She then lands on place 44: the route from ant 11 (place 11) to place 44 runs through place 22, where ant 22 stands, so ant 11 stays put, while ant 22 walks from place 22 to place 44 in one step and chases her away again. In the end ant 11 is still at place 11 with 00 chases, and ant 22 is at place 44 with 22 chases.