#include <bits/stdc++.h>
using namespace std;
inline int Rd() {
  int s = 0;
  char fl = 0, c = getchar();
  while (c < '0' || c > '9') fl |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return fl ? -s : s;
}
const int N = 1e6 + 5;
int n, cnt;
long long ans;
int to[N << 1], nxt[N << 1], h[N], dep[N], siz[N], prt[N], fa[N];
long long s[N], w[N];
inline void AddEdge(int x, int y) {
  to[++cnt] = y, nxt[cnt] = h[x], h[x] = cnt;
}
void DFS(int x) {
  siz[x] = 1;
  dep[x] = dep[prt[x]] + 1;
  for (int i = h[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == prt[x]) continue;
    prt[y] = x, DFS(y), siz[x] += siz[y];
    w[x] += 1ll * siz[y] * siz[y];
  }
  w[x] += 1ll * (n - siz[x]) * (n - siz[x]);
  ans -= w[x];
}
inline long long Calc(int x) {
  return max(s[x] * (s[x] - 1) * (s[x] - 2), 0ll);
};
inline int Getf(int x) { return x == fa[x] ? x : fa[x] = Getf(fa[x]); }
inline void Merge(int x, int y) {
  ans -= (n - s[x]) * (n - s[x]) * s[x] - w[x] * s[x];
  ans -= (n - s[y]) * (n - s[y]) * s[y] - w[y] * s[y];
  ans -= (n - s[x]) * s[x] * (s[x] - 1) * 2;
  ans -= (n - s[y]) * s[y] * (s[y] - 1) * 2;
  ans -= Calc(x) + Calc(y);
  fa[y] = x, s[x] += s[y];
  w[x] += w[y] - 1ll * siz[y] * siz[y] - 1ll * (n - siz[y]) * (n - siz[y]);
  ans += (n - s[x]) * (n - s[x]) * s[x] - w[x] * s[x];
  ans += (n - s[x]) * s[x] * (s[x] - 1) * 2 + Calc(x);
}
int main() {
  n = Rd();
  for (int i = 1; i < n; ++i) {
    int x = Rd(), y = Rd();
    AddEdge(x, y), AddEdge(y, x);
  }
  ans = 1ll * n * (n - 1) * (n - 1);
  DFS(1);
  for (int i = 1; i <= n; ++i) fa[i] = i, s[i] = 1;
  printf("%lld\n", ans);
  int Q = Rd();
  while (Q--) {
    int x = Rd(), y = Rd();
    x = Getf(x), y = Getf(y);
    while (x ^ y) {
      if (dep[x] < dep[y]) swap(x, y);
      int fx = Getf(prt[x]);
      Merge(fx, x), x = fx;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
