#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int gi() {
  int w = 0;
  bool q = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 0, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? w : -w;
}
int head[N], nxt[N], to[N];
int fa[N], siz[N], in[N], dep[N], n;
long long sum[N];
int G[N];
inline int find(int x) { return G[x] == x ? x : G[x] = find(G[x]); }
inline long long f(int k) {
  return -in[k] * sum[k] - 1LL * in[k] * (n - siz[k]) * (n - siz[k] - 1);
}
inline void dfs(int k) {
  siz[k] = in[k] = 1;
  dep[k] = dep[fa[k]] + 1;
  for (int i = head[k]; i; i = nxt[i])
    if (to[i] != fa[k]) {
      fa[to[i]] = k;
      dfs(to[i]);
      siz[k] += siz[to[i]];
      sum[k] += 1LL * siz[to[i]] * (siz[to[i]] - 1);
    }
}
int main() {
  int i, s, a, b, tot = 0, m, A, B;
  n = gi();
  for (i = 1; i < n; i++) {
    a = gi(), b = gi();
    to[++tot] = b, nxt[tot] = head[a], head[a] = tot;
    to[++tot] = a, nxt[tot] = head[b], head[b] = tot;
  }
  for (i = 1; i <= n; i++) G[i] = i;
  dfs(1);
  long long ans = 1LL * n * (n - 1) * (n - 2), S;
  for (i = 1; i <= n; i++) ans += f(i);
  printf("%I64d\n", ans);
  for (m = gi(); m--;) {
    a = find(gi()), b = find(gi());
    S = s = A = B = 0;
    while (a != b)
      if (dep[a] > dep[b]) {
        s += in[a];
        S += sum[a] - 1LL * siz[a] * (siz[a] - 1);
        ans -= f(a);
        G[a] = fa[a], a = find(fa[A = a]);
      } else {
        s += in[b];
        S += sum[b] - 1LL * siz[b] * (siz[b] - 1);
        ans -= f(b);
        G[b] = fa[b], b = find(fa[b]);
      }
    S += sum[a];
    ans -= f(a);
    in[a] += s;
    sum[a] = S;
    ans += f(a);
    printf("%I64d\n", ans);
  }
  return 0;
}
