#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  T f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
const int MAXN = 1e5 + 5;
int head[MAXN], to[MAXN << 1], nxt[MAXN << 1], cnt, fa[MAXN], dep[MAXN],
    f[MAXN];
long long siz[MAXN], w[MAXN], ans, s[MAXN], n;
void add(int u, int v) {
  nxt[++cnt] = head[u];
  to[cnt] = v;
  head[u] = cnt;
}
int findSet(int x) {
  if (f[x] != x) return f[x] = findSet(f[x]);
  return f[x];
}
void dfs(int x, int fat) {
  dep[x] = dep[fat] + 1;
  siz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == fat) continue;
    dfs(to[i], x);
    siz[x] += siz[to[i]];
    fa[to[i]] = x;
    w[x] += siz[to[i]] * siz[to[i]];
  }
  w[x] += (n - siz[x]) * (n - siz[x]);
  ans -= w[x];
}
long long Cal(int x) { return max(s[x] * (s[x] - 1) * (s[x] - 2), 0ll); }
void merge(int u, int v) {
  ans -= (long long)(n - s[u]) * (long long)(n - s[u]) * s[u] - w[u] * s[u];
  ans -= (long long)(n - s[v]) * (long long)(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] - siz[v] * siz[v] - (n - siz[v]) * (n - siz[v]);
  ans = ans + (n - s[u]) * (n - s[u]) * s[u] - w[u] * s[u] + Cal(u) +
        (n - s[u]) * s[u] * (s[u] - 1) * 2;
}
int main() {
  read(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u);
    read(v);
    add(u, v);
    add(v, u);
  }
  ans = n * (n - 1) * (n - 1);
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) s[i] = 1, f[i] = i;
  printf("%lld\n", ans);
  int Q;
  read(Q);
  while (Q-- > 0) {
    int u, v;
    read(u);
    read(v);
    u = findSet(u);
    v = findSet(v);
    while (u != v) {
      if (dep[u] < dep[v]) swap(u, v);
      int fu = findSet(fa[u]);
      merge(fu, u);
      u = fu;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
