#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
long long ans1, ans2, ans3;
int sz[N], dep[N], fat[N], fa[N], n, q, siz[N];
long long ret[N];
vector<int> g[N];
int dfs(int x) {
  int si = 0;
  for (int i : g[x])
    if (i != fat[x]) {
      fat[i] = x;
      dep[i] = dep[x] + 1;
      int sj = dfs(i);
      ans1 += (long long)si * sj;
      ret[x] += (long long)si * sj;
      si += sj;
    }
  ans1 += (long long)(n - 1 - si) * si;
  ret[x] += (long long)(n - 1 - si) * si;
  ++si;
  siz[x] = si;
  return si;
}
long long calc2(int x) { return (long long)x * (x - 1) * (n - x); }
long long calc3(int x) { return (long long)x * (x - 1) * (x - 2) / 2; }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void U(int x, int y) {
  x = find(x);
  y = find(y);
  ans3 += calc3(sz[x] + sz[y]) - calc3(sz[x]) - calc3(sz[y]);
  ans2 += calc2(sz[x] + sz[y]) - calc2(sz[x]) - calc2(sz[y]);
  ans1 -= ret[x] * sz[x] + ret[y] * sz[y];
  int L = siz[x] - sz[x], R = n - siz[x] - sz[y];
  ret[y] +=
      ret[x] - (long long)R * sz[x] - (long long)L * sz[y] - (long long)L * R;
  fa[x] = y;
  sz[y] += sz[x];
  ans1 += ret[y] * sz[y];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1);
  iota(fa, fa + n + 1, 0);
  fill(sz, sz + n + 1, 1);
  cin >> q;
  cout << 2 * (ans1 + ans2 + ans3) << '\n';
  while (q-- > 0) {
    int u, v;
    cin >> u >> v;
    for (; (u = find(u)) != (v = find(v));) {
      if (dep[u] < dep[v]) swap(u, v);
      U(u, fat[u]);
    }
    cout << 2 * (ans1 + ans2 + ans3) << '\n';
  }
  return 0;
}
