@staticmethod
def d():
    n = int(sys.stdin.readline().rstrip())
    g = GeometryTopology.Graph()
    for _ in range((n - 1)):
        (x, y) = map(int, sys.stdin.readline().split())
        x -= 1
        y -= 1
        g.add_edge(x, y, weight=1)
        g.add_edge(y, x, weight=1)
    g.init_tree()
    (q, *ab) = map(int, sys.stdin.read().split())
    for (a, b) in zip(*([iter(ab)] * 2)):
        a -= 1
        b -= 1
        print((g.find_dist(a, b) + 1))
@staticmethod
def d():
    n = int(sys.stdin.readline().rstrip())
    g = GeometryTopology.Graph()
    for _ in range((n - 1)):
        (x, y) = map(int, sys.stdin.readline().split())
        x -= 1
        y -= 1
        g.add_edge(x, y, weight=1)
        g.add_edge(y, x, weight=1)
    g.init_tree()
    (q, *ab) = map(int, sys.stdin.read().split())
    for (a, b) in zip(*([iter(ab)] * 2)):
        a -= 1
        b -= 1
        print((g.find_dist(a, b) + 1))