#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int E = N << 1;
int fa[N], last[N], bcnt[N], bsum[N], eid[N], fa_[N], depth[N];
int tov[E], nxt[E];
long long bsum2[N];
int n, q, tot;
long long ans;
int getfather(int son) {
  return fa_[son] == son ? son : fa_[son] = getfather(fa_[son]);
}
inline void insert(int x, int y) {
  tov[++tot] = y, nxt[tot] = last[x], last[x] = tot;
}
inline long long sqr(int x) { return 1ll * x * x; }
void dfs(int x) {
  bsum[x] = bcnt[x] = 1, fa_[x] = x;
  for (int i = last[x], y; i; i = nxt[i])
    if ((y = tov[i]) != fa[x]) {
      depth[y] = depth[fa[y] = x] + 1, dfs(y);
      bsum[x] += bsum[y], bsum2[x] += sqr(bsum[y]);
    }
  bsum2[x] += sqr(n - bsum[x]);
  ans += (1ll * (bcnt[x] - 1) * (bcnt[x] - 2) +
          2ll * (bcnt[x] - 1) * (n - bcnt[x]) + (sqr(n - bcnt[x]) - bsum2[x])) *
         bcnt[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i < n; ++i)
    scanf("%d%d", &x, &y), insert(x, y), insert(y, x);
  depth[1] = 1, dfs(1), printf("%lld\n", ans), scanf("%d", &q);
  for (int i = 1, x, y, x_, y_; i <= q; ++i) {
    scanf("%d%d", &x, &y), x_ = x = getfather(x), y_ = y = getfather(y);
    for (; x != y; x = getfather(fa[x])) {
      if (depth[x] < depth[y]) swap(x, y);
      ans -= (1ll * (bcnt[x] - 1) * (bcnt[x] - 2) +
              2ll * (bcnt[x] - 1) * (n - bcnt[x]) +
              (sqr(n - bcnt[x]) - bsum2[x])) *
             bcnt[x];
    }
    ans -=
        (1ll * (bcnt[x] - 1) * (bcnt[x] - 2) +
         2ll * (bcnt[x] - 1) * (n - bcnt[x]) + (sqr(n - bcnt[x]) - bsum2[x])) *
        bcnt[x];
    x = x_, y = y_;
    for (int z; x != y; x = z) {
      if (depth[x] < depth[y]) swap(x, y);
      fa_[x] = z = getfather(fa[x]);
      bcnt[z] += bcnt[x];
      bsum2[z] -= sqr(bsum[x]) - bsum2[x] + sqr(n - bsum[x]);
    }
    ans +=
        (1ll * (bcnt[x] - 1) * (bcnt[x] - 2) +
         2ll * (bcnt[x] - 1) * (n - bcnt[x]) + (sqr(n - bcnt[x]) - bsum2[x])) *
        bcnt[x];
    printf("%lld\n", ans);
  }
  return 0;
}
