#include <bits/stdc++.h>
using namespace std;
void Freopen() {
  freopen(
      "title"
      ".in",
      "r", stdin);
  freopen(
      "title"
      ".out",
      "w", stdout);
}
int read() {
  int g = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    g = g * 10 + ch - '0';
    ch = getchar();
  }
  return g * f;
}
const int N = 1e5 + 5;
long long ans, w[N];
int size[N], sz[N], f[N], pr[N], dep[N], n;
vector<int> G[N];
long long sqr(int x) { return 1ll * x * x; }
long long calc(int x) { return 1ll * sz[x] * (sz[x] - 1) * (sz[x] - 2); }
void dfs(int x, int fa) {
  size[x] = 1;
  dep[x] = dep[fa] + 1;
  pr[x] = fa;
  for (auto y : G[x])
    if (y ^ fa) {
      dfs(y, x);
      size[x] += size[y];
      w[x] += sqr(size[y]);
    }
  ans -= (long long)(w[x] += sqr(n - size[x]));
}
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
void merge(int x, int y) {
  ans -= 1ll * (sqr(n - sz[x]) - w[x]) * sz[x];
  ans -= 1ll * (sqr(n - sz[y]) - w[y]) * sz[y];
  ans -= 1ll * (n - sz[x]) * sz[x] * (sz[x] - 1) * 2;
  ans -= 1ll * (n - sz[y]) * sz[y] * (sz[y] - 1) * 2;
  ans -= calc(x) + calc(y);
  f[y] = x;
  sz[x] += sz[y];
  w[x] += w[y] - sqr(size[y]) - sqr(n - size[y]);
  ans += 1ll * (sqr(n - sz[x]) - w[x]) * sz[x];
  ans += calc(x);
  ans += 1ll * (n - sz[x]) * sz[x] * (sz[x] - 1) * 2;
}
signed main() {
  n = read();
  for (int i = (1); i <= (n - 1); i++) {
    int x = read(), y = read();
    G[x].push_back(y), G[y].push_back(x);
  }
  ans = 1ll * n * (n - 1) * (n - 1);
  dfs(1, 0);
  for (int i = (1); i <= (n); i++) f[i] = i, sz[i] = 1;
  cout << ans << '\n';
  for (int T = read(); T--;) {
    int x = get(read()), y = get(read());
    while (x != y) {
      if (dep[x] < dep[y]) swap(x, y);
      int t = get(pr[x]);
      merge(t, x);
      x = t;
    }
    cout << ans << '\n';
  }
  return signed();
}
