#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long Q, n, tot, head[N];
long long dep[N], siz[N], sz[N];
long long f[N], fa[N], w[N];
long long ans;
long long read() {
  long long ret = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) ret = ret * 10 + (c ^ 48), c = getchar();
  return ret;
}
void write(long long x) {
  if (x > 9) write((long long)x / 10);
  putchar((x % 10) ^ 48);
}
void writeln(long long x) {
  write(x);
  puts("");
}
struct Tway {
  long long v, nex;
} e[N << 1];
void add(long long u, long long v) {
  e[++tot] = (Tway){v, head[u]};
  head[u] = tot;
  e[++tot] = (Tway){u, head[v]};
  head[v] = tot;
}
long long sqr(long long x) { return (long long)x * x; }
void dfs(long long x) {
  siz[x] = 1;
  dep[x] = dep[fa[x]] + 1;
  for (long long i = head[x]; i; i = e[i].nex) {
    long long v = e[i].v;
    if (v == fa[x]) continue;
    fa[v] = x;
    dfs(v);
    siz[x] += siz[v];
    w[x] += sqr(siz[v]);
  }
  ans -= (long long)(w[x] += sqr(n - siz[x]));
}
long long findf(long long x) { return f[x] == x ? x : f[x] = findf(f[x]); }
long long get(long long x) {
  return (long long)sz[x] * (sz[x] - 1) * (sz[x] - 2);
}
void merge(long long x, long long y) {
  ans -= (sqr(n - sz[x]) - w[x]) * sz[x];
  ans -= (sqr(n - sz[y]) - w[y]) * sz[y];
  ans -= (n - sz[x]) * sz[x] * (sz[x] - 1) * 2;
  ans -= (n - sz[y]) * sz[y] * (sz[y] - 1) * 2;
  ans -= get(x) + get(y);
  f[y] = x;
  sz[x] += sz[y];
  w[x] += w[y] - sqr(siz[y]) - sqr(n - siz[y]);
  ans += (sqr(n - sz[x]) - w[x]) * sz[x] + get(x);
  ans += (n - sz[x]) * sz[x] * (sz[x] - 1) * 2;
  cerr << ans << "\n";
}
int main() {
  n = read();
  for (long long i = 1; i < n; ++i) add(read(), read());
  ans = n * (n - 1) * (n - 1);
  dfs(1);
  for (long long i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;
  Q = read();
  writeln(ans);
  while (Q--) {
    long long u = findf(read()), v = findf(read());
    while (u ^ v) {
      if (dep[u] < dep[v]) swap(u, v);
      long long t = findf(fa[u]);
      merge(t, u);
      u = t;
    }
    writeln(ans);
  }
  return 0;
}
