#include <bits/stdc++.h>
template <class T>
inline void read(T &res) {
  char ch;
  while (ch = getchar(), !isdigit(ch) && ch != '-')
    ;
  res = ch ^ 48;
  while (ch = getchar(), isdigit(ch)) res = res * 10 + ch - 48;
}
template <class T>
inline void put(T x) {
  if (x > 9) put(x / 10);
  putchar(x % 10 + 48);
}
const int N = 1e5 + 5;
int dep[N], sze[N], cnt[N], anc[N], fa[N];
int n, Q;
long long ans, val[N];
struct Edge {
  int to;
  Edge *nxt;
} p[N << 1], *lst[N], *P = p;
inline void Link(int x, int y) {
  (++P)->nxt = lst[x];
  lst[x] = P;
  P->to = y;
  (++P)->nxt = lst[y];
  lst[y] = P;
  P->to = x;
}
inline void Dfs(int x, int Fa) {
  dep[x] = dep[Fa] + 1;
  sze[x] = 1;
  for (Edge *e = lst[x]; e; e = e->nxt) {
    int y = e->to;
    if (y == Fa) continue;
    fa[y] = x;
    Dfs(y, x);
    sze[x] += sze[y];
  }
  val[x] += 2ll * (sze[x] - 1) * (n - sze[x]);
  for (Edge *e = lst[x]; e; e = e->nxt) {
    int y = e->to;
    if (y == Fa) continue;
    val[x] += 1ll * sze[y] * (sze[x] - sze[y] - 1);
  }
  ans += val[x];
}
inline int ufs_find(int x) {
  if (anc[x] != x) return anc[x] = ufs_find(anc[x]);
  return x;
}
int main() {
  read(n);
  for (int i = 1, u, v; i < n; ++i) {
    read(u);
    read(v);
    Link(u, v);
  }
  Dfs(1, 0);
  put(ans), putchar('\n');
  for (int i = 1; i <= n; ++i) anc[i] = i, cnt[i] = 1;
  read(Q);
  int x, y, t;
  while (Q--) {
    read(x);
    read(y);
    x = ufs_find(x);
    y = ufs_find(y);
    while (x != y) {
      if (dep[x] < dep[y]) std::swap(x, y);
      t = ufs_find(fa[x]);
      ans += 1ll * cnt[x] * cnt[t] * (cnt[t] - 1);
      ans += 1ll * cnt[t] * cnt[x] * (cnt[x] - 1);
      ans += 2ll * cnt[x] * cnt[t] * (n - cnt[x] - cnt[t]);
      ans += 1ll * cnt[x] * (val[t] - 2ll * sze[x] * (n - sze[x] - cnt[t]));
      ans += 1ll * cnt[t] * (val[x] - 2ll * (n - sze[x]) * (sze[x] - cnt[x]));
      val[t] += val[x] - 2ll * cnt[x] * (n - sze[x] - cnt[t]) -
                2ll * (sze[x] - cnt[x]) * (n - sze[x]);
      anc[x] = t;
      cnt[t] += cnt[x];
      x = t;
    }
    put(ans), putchar('\n');
  }
  return 0;
}
