#include <bits/stdc++.h>
const int MAXN = 1000000;
int N;
long long Ans;
std::vector<int> G[MAXN + 5];
long long Val[MAXN + 5];
int Size[MAXN + 5];
int Fa[MAXN + 5], Dep[MAXN + 5];
void Dfs(int u, int fa, int dep) {
  Size[u] = 1;
  Fa[u] = fa;
  Dep[u] = dep;
  for (int i = 0; i < int(G[u].size()); i++) {
    int v = G[u][i];
    if (v != fa) {
      Dfs(v, u, dep + 1);
      Size[u] += Size[v];
      Val[u] += (long long)Size[v] * Size[v];
    }
  }
  Val[u] += (long long)(N - Size[u]) * (N - Size[u]);
  Ans -= Val[u];
}
int Pa[MAXN + 5], Num[MAXN + 5];
int Find(int u) { return Pa[u] == u ? u : Pa[u] = Find(Pa[u]); }
long long In1(int u) {
  return (long long)(N - Num[u]) * (N - Num[u]) * Num[u] - Val[u] * Num[u];
}
long long In2(int u) {
  return (long long)Num[u] * (Num[u] - 1) * 2 * (N - Num[u]);
}
long long In3(int u) {
  return std::max((long long)Num[u] * (Num[u] - 1) * (Num[u] - 2), 0ll);
}
void Merge(int u, int v) {
  Ans -= In1(u) + In2(u) + In3(u);
  Ans -= In1(v) + In2(v) + In3(v);
  Pa[v] = u, Num[u] += Num[v];
  Val[u] += Val[v] - (long long)Size[v] * Size[v] -
            (long long)(N - Size[v]) * (N - Size[v]);
  Ans += In1(u) + In2(u) + In3(u);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v), G[v].push_back(u);
  }
  Ans = (long long)N * (N - 1) * (N - 1);
  Dfs(1, 0, 0);
  printf("%lld\n", Ans);
  for (int i = 1; i <= N; i++) Pa[i] = i, Num[i] = 1;
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    u = Find(u), v = Find(v);
    while (u != v) {
      if (Dep[u] < Dep[v]) std::swap(u, v);
      int anc = Find(Fa[u]);
      Merge(anc, u), u = anc;
    }
    printf("%lld\n", Ans);
  }
  return 0;
}
