#include <bits/stdc++.h>
using namespace std;
template <class _Tp>
_Tp gcd(_Tp a, _Tp b) {
  return (b == 0) ? (a) : (gcd(b, a % b));
}
const int inf = 1000000000;
const long long Inf = 1000000000000000000ll;
char buf[1 << 23], *p1 = buf, *p2 = buf;
int read() {
  int x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) (c == '-') && (f = 1), c = getchar();
  while (isdigit(c)) x = x * 10 + (c & 15), c = getchar();
  return f ? -x : x;
}
const int N = 100005;
int fa[N], dep[N], siz[N], F[N], n;
long long v[N], ans, g[N];
vector<int> e[N];
void dfs(int u, int f) {
  fa[u] = f;
  dep[u] = dep[f] + 1;
  for (int i = 0; i < e[u].size(); ++i) {
    int to = e[u][i];
    if (to == f) continue;
    dfs(to, u);
    v[u] += 1ll * siz[u] * siz[to];
    siz[u] += siz[to];
  }
  v[u] += 1ll * siz[u] * (n - siz[u] - 1);
  ans += v[u];
  v[u] += n - 1;
  siz[u]++;
}
int Get(int x) {
  if (F[x] == x) return x;
  return F[x] = Get(F[x]);
}
void merge(int x, int y) {
  int t = Get(y);
  ans += 1ll * (v[x] - 1ll * siz[x] * (n - siz[x])) * g[t];
  ans += 1ll * (v[t] - 1ll * siz[x] * (n - siz[x])) * g[x];
  F[x] = t;
  g[t] += g[x];
  v[t] += v[x];
  v[t] -= 1ll * siz[x] * (n - siz[x]);
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 0);
  printf("%lld\n", ans * 2ll);
  for (int i = 1; i <= n; ++i) g[i] = 1, F[i] = i;
  int q;
  scanf("%d", &q);
  while (q--) {
    int x = read(), y = read();
    while (1) {
      x = Get(x);
      y = Get(y);
      if (x == y) break;
      if (dep[x] < dep[y]) swap(x, y);
      merge(x, fa[x]);
    }
    printf("%lld\n", ans * 2ll);
  }
  return 0;
}
