After destroying all of Voldemort's Horcruxes, Harry and Voldemort are up for the final battle. They each cast spells from their wands and the spells collide.

The battle scene is Hogwarts, which can be represented in the form of a tree. There are, in total, n places in Hogwarts joined using n - 1 undirected roads.

Ron, who was viewing this battle between Harry and Voldemort, wondered how many triplets of places (u, v, w) are there such that if Harry is standing at place u and Voldemort is standing at place v, their spells collide at a place w. This is possible for a triplet only when u, v and w are distinct, and there exist paths from u to w and from v to w which do not pass through the same roads.

Now, due to the battle havoc, new paths are being added all the time. You have to tell Ron the answer after each addition.

Formally, you are given a tree with n vertices and n - 1 edges. q new edges are being added between the nodes of the tree. After each addition you need to tell the number of triplets (u, v, w) such that u, v and w are distinct and there exist two paths, one between u and w, another between v and w such that these paths do not have an edge in common.

Input

First line contains an integer n (1 ≤ n ≤ 105), the number of places in Hogwarts.

Each of the next n - 1 lines contains two space separated integers u and v (1 ≤ u, v ≤ n) indicating a road between places u and v. It is guaranteed that the given roads form a connected tree.

Next line contains a single integer q (1 ≤ q ≤ 105), the number of new edges being added.

Each of the next q lines contains two space separated integers u and v (1 ≤ u, v ≤ n) representing the new road being added.

Note that it is possible that a newly added road connects places that were connected by a road before. Also, a newly added road may connect a place to itself.

Output

In the first line print the value for the number of triplets before any changes occurred.

After that print q lines, a single integer ansi in each line containing the value for the number of triplets after i-th edge addition.

Examples

Input

3
1 2
2 3
1
2 3


Output

2
4


Input

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


Output

6
18
24


Input

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


Output

20
60

Note

In the first sample case, for the initial tree, we have (1, 3, 2) and (3, 1, 2) as the only possible triplets (u, v, w).

After addition of edge from 2 to 3, we have (1, 3, 2), (3, 1, 2), (1, 2, 3) and (2, 1, 3) as the possible triplets.
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  int next;
} e[200005];
int n, tot = 0, sz[100005], dep[100005], fa[100005], last[100005], s[100005],
       f[100005];
long long ans = 0, val[100005];
int ff(int x) {
  if (f[x] == x) {
    return x;
  } else {
    return f[x] = ff(f[x]);
  }
}
void add_edge(int u, int v) {
  ++tot;
  e[tot].to = v;
  e[tot].next = last[u];
  last[u] = tot;
  return;
}
void insert_edge(int u, int v) {
  add_edge(u, v);
  add_edge(v, u);
  return;
}
void dfs(int x) {
  dep[x] = dep[fa[x]] + 1;
  sz[x] = 1;
  for (register int i = last[x]; i; i = e[i].next) {
    if (e[i].to == fa[x]) {
      continue;
    }
    fa[e[i].to] = x;
    dfs(e[i].to);
    sz[x] += sz[e[i].to];
    val[x] += 1LL * sz[e[i].to] * sz[e[i].to];
  }
  val[x] += 1LL * (n - sz[x]) * (n - sz[x]);
  ans -= val[x];
  return;
}
long long fact(int s) { return 1LL * s * (s - 1) * (s - 2); }
void merge(int x, int y) {
  ans -= 1LL * (n - s[x]) * (n - s[x]) * s[x] +
         1LL * (n - s[y]) * (n - s[y]) * s[y] - val[x] * s[x] - val[y] * s[y] +
         fact(s[x]) + fact(s[y]) + 1LL * s[x] * (s[x] - 1) * (n - s[x]) * 2 +
         1LL * s[y] * (s[y] - 1) * (n - s[y]) * 2;
  f[y] = x;
  s[x] += s[y];
  val[x] += val[y] - 1LL * sz[y] * sz[y] - 1LL * (n - sz[y]) * (n - sz[y]);
  ans += 1LL * (n - s[x]) * (n - s[x]) * s[x] - val[x] * s[x] + fact(s[x]) +
         1LL * s[x] * (s[x] - 1) * (n - s[x]) * 2;
  return;
}
int main() {
  int u, v, q, x, y;
  scanf("%d", &n);
  for (register int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    insert_edge(u, v);
  }
  ans = 1LL * n * (n - 1) * (n - 1);
  dfs(1);
  printf("%lld", ans);
  for (register int i = 1; i <= n; ++i) {
    f[i] = i;
    s[i] = 1;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &x, &y);
    int fx = ff(x);
    int fy = ff(y);
    if (dep[fx] < dep[fy]) {
      swap(fx, fy);
    }
    while (fx != fy) {
      if (dep[fx] < dep[fy]) {
        swap(fx, fy);
      }
      merge(ff(fa[fx]), fx);
      fx = ff(fa[fx]);
    }
    printf("\n%lld", ans);
  }
}
