#include <bits/stdc++.h>
struct Point {
  long long size, depth, fa, val;
} point[100100];
struct Edge {
  long long to, nxt;
} edge[200100];
long long cnt, head[100100], n, Q, fa[100100], size[100100], x, y;
long long ans;
void addedge(long long x, long long y) {
  edge[++cnt].to = y;
  edge[cnt].nxt = head[x];
  head[x] = cnt;
}
void dfs(long long x, long long fa) {
  point[x].depth = point[fa].depth + 1;
  point[x].fa = fa;
  point[x].size = 1;
  for (long long i = head[x]; i; i = edge[i].nxt) {
    long long upup = edge[i].to;
    if (upup == fa) continue;
    dfs(upup, x);
    point[x].size += point[upup].size;
    point[x].val += point[upup].size * point[upup].size;
  }
  ans -= (point[x].val += (n - point[x].size) * (n - point[x].size));
}
long long find(long long x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
long long calc(long long x) {
  long long res = size[x];
  return res * (res - 1) * (res - 2);
}
void merge(long long x, long long y) {
  ans -= ((n - size[x]) * (n - size[x]) - point[x].val) * size[x];
  ans -= ((n - size[y]) * (n - size[y]) - point[y].val) * size[y];
  ans -= (n - size[x]) * size[x] * (size[x] - 1) * 2;
  ans -= (n - size[y]) * size[y] * (size[y] - 1) * 2;
  ans -= calc(x) + calc(y);
  fa[y] = x;
  size[x] += size[y];
  point[x].val += point[y].val - point[y].size * point[y].size -
                  (n - point[y].size) * (n - point[y].size);
  ans += ((n - size[x]) * (n - size[x]) - point[x].val) * size[x] + calc(x);
  ans += (n - size[x]) * size[x] * (size[x] - 1) * 2;
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    addedge(x, y);
    addedge(y, x);
  }
  ans = n * (n - 1) * (n - 1);
  dfs(1, 0);
  for (long long i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
  printf("%lld\n", ans);
  scanf("%lld", &Q);
  while (Q--) {
    scanf("%lld%lld", &x, &y);
    x = find(x), y = find(y);
    while (x != y) {
      if (point[x].depth < point[y].depth) x ^= y ^= x ^= y;
      long long tmp = find(point[x].fa);
      merge(tmp, x);
      x = tmp;
    }
    printf("%lld\n", ans);
  }
}
