#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q, tot, ver[N], nxt[N], head[N], f[N], d[N], sz[N], s[N], p[N];
long long ans, g[N];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
  return f ? x : -x;
}
void add(int x, int y) { ver[++tot] = y, nxt[tot] = head[x], head[x] = tot; }
int getf(int x) { return x == p[x] ? x : p[x] = getf(p[x]); }
void dfs(int x) {
  s[x] = 1;
  for (int i = head[x]; i; i = nxt[i])
    if (ver[i] != f[x])
      f[ver[i]] = x, d[ver[i]] = d[x] + 1, dfs(ver[i]), s[x] += s[ver[i]],
      g[x] += 1ll * s[ver[i]] * s[ver[i]];
  g[x] += 1ll * (n - s[x]) * (n - s[x]), ans -= g[x];
}
long long calc(int x) {
  return sz[x] * (1ll * (sz[x] - 1) * ((n << 1) - sz[x] - 2) +
                  1ll * (n - sz[x]) * (n - sz[x]) - g[x]);
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y), add(y, x);
  }
  for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;
  ans = 1ll * n * (n - 1) * (n - 1), d[1] = 1, dfs(1), q = read(),
  printf("%lld", ans);
  while (q--) {
    int x = getf(read()), y = getf(read());
    while (x != y) {
      if (d[x] < d[y]) swap(x, y);
      int z = getf(f[x]);
      ans -= calc(x) + calc(z),
          p[x] = z, sz[z] += sz[x],
          g[z] += g[x] - 1ll * s[x] * s[x] - 1ll * (n - s[x]) * (n - s[x]),
          ans += calc(z), x = z;
    }
    printf("\n%lld", ans);
  }
  return 0;
}
