#include <bits/stdc++.h>
const int N = 2e5 + 5;
int n, q, sz[N], ff[N], k[N];
long long S[N], ans;
int dep[N], fa[N], to[N], nx[N], hd[N], sze;
inline int find(int x) { return x == ff[x] ? x : ff[x] = find(ff[x]); }
inline void add(int u, int v) { to[++sze] = v, nx[sze] = hd[u], hd[u] = sze; }
inline void merge(int x, int y) {
  int z = find(y);
  ans += (long long)k[z] * (S[x] - (long long)sz[x] * (n - sz[x])) +
         (long long)k[x] * (S[z] - (long long)sz[x] * (n - sz[x]));
  ff[x] = z, k[z] += k[x], S[z] += S[x] - (long long)sz[x] * (n - sz[x]);
}
inline void dfs(int u, int p) {
  dep[u] = dep[p] + 1, fa[u] = p;
  int i, v;
  for (i = hd[u]; i; i = nx[i])
    if ((v = to[i]) != p)
      dfs(v, u), S[u] += (long long)sz[u] * sz[v], sz[u] += sz[v];
  ans += S[u] += (long long)sz[u] * (n - sz[u] - 1), S[u] += n - 1, sz[u]++;
}
int main() {
  scanf("%d", &n);
  int i, u, v;
  for (i = 1; i < n; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u);
  for (i = 1; i <= n; i++) ff[i] = i, k[i] = 1;
  dfs(1, 0), printf("%lld\n", 2 * ans);
  for (scanf("%d", &q); q; printf("%lld\n", 2 * ans), q--)
    for (scanf("%d%d", &u, &v); (u = find(u)) != (v = find(v)); merge(u, fa[u]))
      if (dep[u] < dep[v]) std::swap(u, v);
  return 0;
}
