#include <bits/stdc++.h>
using namespace std;
long long Ans, val[100005], sum[100005];
int n, m, cnt;
int head[100005], to[200005], Next[200005];
int fa[100005], dep[100005], siz1[100005], siz2[100005];
struct Find_Union {
  int fa[100005];
  void Initialize() {
    for (register int i = 1; i <= n; ++i) fa[i] = i;
    return;
  }
  inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
} T;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void add(int u, int v) {
  to[++cnt] = v;
  Next[cnt] = head[u];
  head[u] = cnt;
}
void Dfs(int u, int f) {
  dep[u] = dep[fa[u] = f] + (siz1[u] = siz2[u] = 1);
  for (register int i = head[u]; i; i = Next[i]) {
    int v = to[i];
    if (v != f) {
      Dfs(v, u);
      siz1[u] += siz1[v];
      sum[u] += 1LL * siz1[v] * (n - siz1[v] - 1);
    }
  }
  sum[u] += 1LL * (siz1[u] - 1) * (n - siz1[u]);
  val[u] = sum[u];
  Ans += val[u];
  return;
}
void Merge(int x, int y) {
  while (x != y) {
    if (dep[x] < dep[y]) swap(x, y);
    int f = T.find(fa[x]);
    Ans -= 1LL * val[x] * siz2[x];
    Ans -= 1LL * val[f] * siz2[f];
    sum[f] -= 1LL * siz1[x] * (n - siz1[x] - 1);
    sum[x] -= 1LL * (siz1[x] - 1) * (n - siz1[x]);
    sum[f] += sum[x];
    siz2[f] += siz2[x];
    val[f] = sum[f] + 1LL * (siz2[f] - 1) * (n - 2);
    Ans += 1LL * val[f] * siz2[f];
    T.fa[x] = T.fa[fa[x]];
    x = T.find(fa[x]);
  }
  return;
}
int main() {
  n = read();
  for (register int i = 2; i <= n; ++i) {
    int u, v;
    u = read();
    v = read();
    add(u, v);
    add(v, u);
  }
  Dfs(1, 0);
  T.Initialize();
  printf("%lld\n", Ans);
  m = read();
  for (register int i = 1; i <= m; ++i) {
    int u = T.find(read());
    int v = T.find(read());
    Merge(u, v);
    printf("%lld\n", Ans);
  }
  return 0;
}
