#include <bits/stdc++.h>
using namespace std;
long long n, ans, s[1000000], w[1000000], dep[1000000];
long long size[1000000], fa[1000000], f[1000000];
long long read() {
  long long x = 0, k = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * k;
}
struct edge {
  long long cnp, to[1000000], last[1000000], head[1000000];
  edge() { cnp = 2; }
  void add(long long u, long long v) {
    to[cnp] = v, last[cnp] = head[u], head[u] = cnp++;
    to[cnp] = u, last[cnp] = head[v], head[v] = cnp++;
  }
} E1;
void dfs(long long u) {
  size[u] = 1;
  dep[u] = dep[fa[u]] + 1;
  for (long long i = E1.head[u]; i; i = E1.last[i]) {
    long long v = E1.to[i];
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    size[u] += size[v];
    w[u] += size[v] * size[v];
  }
  w[u] += (n - size[u]) * (n - size[u]);
  ans -= w[u];
}
long long Cal(long long u) { return max(s[u] * (s[u] - 1) * (s[u] - 2), 0LL); }
long long find(long long x) { return f[x] == x ? x : f[x] = find(f[x]); }
void merge(long long u, long long v) {
  ans -= (n - s[u]) * (n - s[u]) * s[u] - w[u] * s[u];
  ans -= (n - s[v]) * (n - s[v]) * s[v] - w[v] * s[v];
  ans -= (n - s[u]) * s[u] * (s[u] - 1) * 2;
  ans -= (n - s[v]) * s[v] * (s[v] - 1) * 2;
  ans -= Cal(u) + Cal(v);
  f[v] = u, s[u] += s[v];
  w[u] += w[v] - size[v] * size[v] - (n - size[v]) * (n - size[v]);
  ans += (n - s[u]) * (n - s[u]) * s[u] - w[u] * s[u] + Cal(u);
  ans += (n - s[u]) * s[u] * (s[u] - 1) * 2;
}
signed main() {
  n = read();
  for (long long i = 1; i < n; i++) {
    long long u = read(), v = read();
    E1.add(u, v);
  }
  ans = n * (n - 1) * (n - 1);
  dfs(1);
  for (long long i = 1; i <= n; i++) f[i] = i, s[i] = 1;
  long long q = read();
  printf("%lld\n", ans);
  for (long long i = 1; i <= q; i++) {
    long long u = read(), v = read();
    u = find(u), v = find(v);
    while (u != v) {
      if (dep[u] < dep[v]) swap(u, v);
      long long fu = find(fa[u]);
      merge(fu, u);
      u = fu;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
