#include <bits/stdc++.h>
using namespace std;
vector<long long> G[100005];
long long v[100005], ans = 0;
long long dep[100005], f[100005], wro[100005], siz[100005], sizd[100005], n;
void makeSet() {
  for (long long i = 1; i <= 100000; i++) v[i] = i, sizd[i] = 1;
}
long long findSet(long long x) {
  if (x == v[x]) return x;
  v[x] = findSet(v[x]);
  return v[x];
}
void dfs(long long x, long long fa) {
  siz[x] = 1;
  for (long long i = 0; i < G[x].size(); i++) {
    long long y = G[x][i];
    if (y == fa) continue;
    dep[y] = dep[x] + 1;
    f[y] = x;
    dfs(y, x);
    siz[x] += siz[y];
  }
  wro[x] = (n - siz[x]) * (n - siz[x]);
  for (long long i = 0; i < G[x].size(); i++) {
    long long y = G[x][i];
    if (y == fa) continue;
    wro[x] += siz[y] * siz[y];
  }
  ans -= wro[x];
}
void update_ans(long long x, long long y) {
  ans -= (n - sizd[x]) * (n - sizd[x]) * sizd[x] +
         (n - sizd[y]) * (n - sizd[y]) * sizd[y];
  ans -= 2 * sizd[x] * (sizd[x] - 1) * (n - sizd[x]) +
         2 * sizd[y] * (sizd[y] - 1) * (n - sizd[y]);
  ans -= sizd[x] * (sizd[x] - 1) * (sizd[x] - 2) +
         sizd[y] * (sizd[y] - 1) * (sizd[y] - 2);
  ans += wro[x] * sizd[x] + wro[y] * sizd[y];
  v[y] = x;
  sizd[x] += sizd[y];
  wro[x] += wro[y] - (siz[y] * siz[y]) - ((n - siz[y]) * (n - siz[y]));
  ans += (n - sizd[x]) * (n - sizd[x]) * sizd[x];
  ans += 2 * sizd[x] * (sizd[x] - 1) * (n - sizd[x]);
  ans += sizd[x] * (sizd[x] - 1) * (sizd[x] - 2);
  ans -= wro[x] * sizd[x];
}
signed main() {
  makeSet();
  scanf("%lld", &n);
  ans = n * (n - 1) * (n - 1);
  for (long long i = 1; i < n; i++) {
    long long x, y;
    scanf("%lld %lld", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1, 0);
  long long m;
  scanf("%lld", &m);
  printf("%lld\n", ans);
  while (m--) {
    long long x, y;
    scanf("%lld %lld", &x, &y);
    x = findSet(x), y = findSet(y);
    while (x != y) {
      if (dep[x] < dep[y]) swap(x, y);
      long long k = findSet(f[x]);
      update_ans(k, x);
      x = k;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
