#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 7;
int n, q;
long long ans;
long long dsu[MAXN], g[MAXN], val[MAXN], siz[MAXN], dep[MAXN];
int find(int A) { return dsu[A] == A ? A : dsu[A] = find(dsu[A]); }
struct side {
  int from, to, nex;
} edge[MAXN];
int head[MAXN], cntm;
void link(int from, int to) {
  edge[++cntm].from = from;
  edge[cntm].to = to;
  edge[cntm].nex = head[from];
  head[from] = cntm;
}
int fa[MAXN];
void dfs(int now) {
  siz[now] = 1;
  g[now] = 1;
  for (int i = head[now], v; i; i = edge[i].nex) {
    v = edge[i].to;
    if (v == fa[now]) continue;
    fa[v] = now;
    dep[v] = dep[now] + 1;
    dfs(v);
    siz[now] += siz[v];
  }
  val[now] = 2 * (n - siz[now]) * (siz[now] - 1);
  for (int i = head[now], v; i; i = edge[i].nex) {
    v = edge[i].to;
    if (v == fa[now]) continue;
    val[now] += siz[v] * (siz[now] - 1 - siz[v]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, i2, i3; i < n; i++) {
    scanf("%d%d", &i2, &i3);
    link(i2, i3);
    link(i3, i2);
  }
  dep[1] = 1;
  dfs(1);
  for (int i = 1; i <= n; i++) {
    ans += val[i];
    dsu[i] = i;
  }
  printf("%lld\n", ans);
  scanf("%d", &q);
  for (int i = 1, i2, i3, i4; i <= q; i++) {
    scanf("%d%d", &i2, &i3);
    i2 = find(i2);
    i3 = find(i3);
    while (i2 != i3) {
      if (dep[find(fa[i2])] < dep[find(fa[i3])]) swap(i2, i3);
      i4 = find(fa[i2]);
      ans += g[i2] * g[i4] * (g[i2] + g[i4] - 2);
      ans += 2 * g[i2] * g[i4] * (n - g[i2] - g[i4]);
      ans += g[i2] * (val[i4] - 2 * siz[i2] * (n - siz[i2] - g[i4]));
      ans += g[i4] * (val[i2] - 2 * (siz[i2] - g[i2]) * (n - siz[i2]));
      val[i4] += val[i2];
      val[i4] -= 2 * (siz[i2] - g[i2]) * (n - siz[i2]);
      val[i4] -= 2 * (g[i2]) * (n - siz[i2] - g[i4]);
      g[i4] += g[i2];
      dsu[i2] = i4;
      i2 = i4;
    }
    printf("%lld\n", ans);
  }
}
