#K55997. Tournament Node Strengths

    ID: 30099 Type: Default 1000ms 256MiB

Tournament Node Strengths

Tournament Node Strengths

You are given a tree with (n) nodes and exactly (n-1) edges where each edge connects two nodes. The strength of a node is defined as its degree (the number of edges incident to the node). In a tournament, two nodes compete in each game. Your task is to determine the strengths of both nodes in each game.

For a game involving nodes (a) and (b), if the degree of node (i) is (d(i)), then output (d(a)) and (d(b)) separated by a space.

For example, if the tree has 5 nodes with edges: (1,2), (1,3), (2,4), (3,5), then the degrees are: (d(1)=2, d(2)=2, d(3)=2, d(4)=1, d(5)=1). For a game between nodes 1 and 2, the result is "2 2".

inputFormat

Input is given via standard input (stdin) in the following format:

  1. The first line contains an integer (n), the number of nodes in the tree.
  2. The next (n-1) lines each contain two integers (u) and (v), representing an edge between nodes (u) and (v).
  3. The following line contains an integer (q), the number of games.
  4. The next (q) lines each contain two integers (a) and (b), representing a game between nodes (a) and (b).

outputFormat

For each game, print a line containing two integers separated by a space: the degree of node (a) and the degree of node (b). The output is to be printed to standard output (stdout).## sample

5
1 2
1 3
2 4
3 5
3
1 2
4 5
3 5
2 2

1 1 2 1

</p>