#include <bits/stdc++.h>
inline int getint() {
  register char ch;
  while (!isdigit(ch = getchar()))
    ;
  register int x = ch ^ '0';
  while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ '0');
  return x;
}
const int N = 1e5 + 1;
std::vector<int> e[N];
inline void add_edge(const int &u, const int &v) {
  e[u].push_back(v);
  e[v].push_back(u);
}
long long ans, val[N], tmp[N];
int n, par[N], dep[N], size[N], tsize[N];
struct DisjointSet {
  int anc[N];
  void reset(const int &n) { std::iota(&anc[1], &anc[n] + 1, 1); }
  int find(const int &x) { return x == anc[x] ? x : anc[x] = find(anc[x]); }
  void merge(const int &x, const int &y) { anc[find(x)] = find(y); }
  bool same(const int &x, const int &y) { return find(x) == find(y); }
};
DisjointSet djs;
void dfs(const int &x, const int &par) {
  ::par[x] = par;
  dep[x] = dep[par] + 1;
  size[x] = tsize[x] = 1;
  for (int y : e[x]) {
    if (y == par) continue;
    dfs(y, x);
    tsize[x] += tsize[y];
  }
}
long long calc(const int &x) {
  long long ans = 0;
  ans += 1ll * size[x] * (size[x] - 1) * (size[x] - 2);
  ans += 2ll * size[x] * (size[x] - 1) * (n - size[x]);
  ans += 1ll * (n - size[x]) * (n - size[x]) * size[x];
  for (int y : e[x]) {
    if (djs.same(x, y)) continue;
    const int z = djs.find(y);
    const int sz = y == par[x] ? n - tsize[x] : tsize[z];
    ans -= 1ll * sz * sz * size[x];
    tmp[x] += 1ll * sz * sz;
  }
  return val[x] = ans;
}
long long calc2(const int &x) {
  long long ans = 0;
  ans += 1ll * size[x] * (size[x] - 1) * (size[x] - 2);
  ans += 2ll * size[x] * (size[x] - 1) * (n - size[x]);
  ans += 1ll * (n - size[x]) * (n - size[x]) * size[x];
  ans -= tmp[x] * size[x];
  return val[x] = ans;
}
void merge(int u, int v) {
  u = djs.find(u);
  v = djs.find(v);
  while (u != v) {
    if (dep[u] < dep[v]) std::swap(u, v);
    const int w = djs.find(par[u]);
    tmp[w] -= 1ll * tsize[u] * tsize[u];
    tmp[w] += tmp[u] - 1ll * (n - tsize[u]) * (n - tsize[u]);
    ans -= val[u];
    size[w] += size[u];
    djs.merge(u, w);
    u = w;
  }
  ans -= val[u];
  ans += calc2(u);
}
int main() {
  n = getint();
  for (register int i = 1; i < n; i++) {
    add_edge(getint(), getint());
  }
  djs.reset(n);
  dfs(1, 0);
  for (register int x = 1; x <= n; x++) {
    ans += calc(x);
  }
  printf("%lld\n", ans);
  const int q = getint();
  for (register int i = 0; i < q; i++) {
    merge(getint(), getint());
    printf("%lld\n", ans);
  }
  return 0;
}
