#include <bits/stdc++.h>
using namespace std;
struct arr {
  int to, ne;
} e[200006 << 1];
long long ans, tmp[200006], val[200006];
int x, y, n, m, cnt, d[200006], h[200006], p[200006], f[200006], tsiz[200006],
    siz[200006];
void add(int x, int y) {
  e[++cnt].to = y;
  e[cnt].ne = h[x];
  h[x] = cnt;
}
int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }
void dfs(int x, int fa) {
  siz[x] = tsiz[x] = 1;
  d[x] = d[fa] + 1;
  p[x] = fa;
  for (int i = h[x]; i; i = e[i].ne)
    if (e[i].to != fa) {
      dfs(e[i].to, x);
      tsiz[x] += tsiz[e[i].to];
      tmp[x] += 1ll * tsiz[e[i].to] * tsiz[e[i].to];
    }
  tmp[x] += 1ll * (n - tsiz[x]) * (n - tsiz[x]);
}
long long updata(int x) {
  long long t1 = 0, t2 = 0, t3 = 0;
  t1 = 1LL * siz[x] * (siz[x] - 1) * (siz[x] - 2);
  t2 = 2LL * siz[x] * (siz[x] - 1) * (n - siz[x]);
  t3 = 1LL * siz[x] * (1LL * (n - siz[x]) * (n - siz[x]) - tmp[x]);
  return t1 + t2 + t3;
}
void work(int x, int y) {
  x = get(x);
  y = get(y);
  while (x != y) {
    if (d[x] < d[y]) swap(x, y);
    if (d[x] > d[y]) {
      int z = get(p[x]);
      siz[z] += siz[x];
      tmp[z] = tmp[z] + tmp[x] - 1LL * tsiz[x] * tsiz[x] -
               1LL * (n - tsiz[x]) * (n - tsiz[x]);
      ans = ans - val[x] - val[z];
      val[z] = updata(z);
      ans += val[z];
      f[x] = z;
      x = z;
    } else {
      int z = get(p[x]);
      siz[z] += siz[x];
      tmp[z] = tmp[z] + tmp[x] - 1LL * tsiz[x] * tsiz[x] -
               1LL * (n - tsiz[x]) * (n - tsiz[x]);
      ans = ans - val[x] - val[z];
      val[z] = updata(z);
      ans += val[z];
      f[x] = z;
      x = z;
      z = get(p[y]);
      siz[z] += siz[y];
      tmp[z] = tmp[z] + tmp[y] - 1LL * tsiz[y] * tsiz[y] -
               1LL * (n - tsiz[y]) * (n - tsiz[y]);
      ans = ans - val[y] - val[z];
      val[z] = updata(z);
      ans += val[z];
      f[y] = z;
      y = z;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d%d", &x, &y), add(x, y), add(y, x);
  for (int i = 1; i <= n; i++) f[i] = i;
  dfs(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    val[i] = 1LL * siz[i] * (1LL * (n - siz[i]) * (n - siz[i]) - tmp[i]);
    ans += val[i];
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    work(x, y);
    printf("%lld\n", ans);
  }
}
