#include <bits/stdc++.h>
using namespace std;
struct sef {
  int ne, en;
} h[1000050];
int first[500050], tot;
int n, Q, fa[500050], f[500040], dep[500050];
long long siz[500050], sz[500005], val[500050];
long long ans;
inline void setl(int x, int y) {
  h[++tot].ne = first[x];
  h[tot].en = y;
  first[x] = tot;
}
void dfs(int x) {
  int y;
  for (int i = first[x]; y = h[i].en, i; i = h[i].ne)
    if (y != fa[x]) {
      fa[y] = x;
      dep[y] = dep[x] + 1;
      dfs(y);
      val[x] += siz[x] * siz[y] * 2;
      siz[x] += siz[y];
    }
  val[x] += siz[x] * (n - siz[x] - 1) * 2;
  ans += val[x];
  ++siz[x];
}
int Find(int x) {
  if (f[x] != x) f[x] = Find(f[x]);
  return f[x];
}
inline long long get(long long x) { return x * (x - 1) * (x - 2); }
int main() {
  scanf("%d", &n);
  int x, y, t;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    setl(x, y);
    setl(y, x);
  }
  for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;
  dep[1] = 1;
  dfs(1);
  printf("%lld\n", ans);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &x, &y);
    x = Find(x), y = Find(y);
    while (x != y) {
      if (dep[x] < dep[y]) swap(x, y);
      t = Find(fa[x]);
      ans += sz[t] * sz[x] * (n - sz[x] - sz[t]) * 2;
      ans += sz[t] * sz[x] * (sz[x] - 1);
      ans += sz[x] * sz[t] * (sz[t] - 1);
      ans += sz[t] * (val[x] - (n - siz[x]) * (siz[x] - sz[x]) * 2);
      ans += sz[x] * (val[t] - siz[x] * (n - siz[x] - sz[t]) * 2);
      val[t] = val[t] + val[x] - sz[x] * (n - siz[x] - sz[t]) * 2 -
               (siz[x] - sz[x]) * (n - siz[x]) * 2;
      sz[t] += sz[x];
      f[x] = t;
      x = t;
    }
    printf("%lld\n", ans);
  }
}
