#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> e[N];
int sz[N], fa[N], n, Q;
int f[N], v[N], dep[N];
long long vv[N], ans;
int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }
void dfs(int x) {
  sz[x] = 1;
  for (auto i : e[x])
    if (i != fa[x]) {
      fa[i] = x;
      dep[i] = dep[x] + 1;
      dfs(i);
      sz[x] += sz[i];
    }
}
void merge(int x, int y) {
  f[x] = y = get(y);
  ans += 1ll * v[x] * vv[x];
  ans += 1ll * v[y] * vv[y];
  v[y] += v[x];
  vv[y] += vv[x];
  vv[y] -= 1ll * sz[x] * (sz[x] - 1);
  vv[y] -= 1ll * (n - sz[x]) * (n - sz[x] - 1);
  ans -= 1ll * v[y] * vv[y];
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1);
  ans = 1ll * n * (n - 1) * (n - 2);
  for (int i = (int)(1); i <= (int)(n); i++) f[i] = i, v[i] = 1;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (auto j : e[i]) {
      int m = (fa[j] == i ? sz[j] : n - sz[i]);
      ans -= 1ll * m * (m - 1);
      vv[i] += 1ll * m * (m - 1);
    }
  printf("%lld\n", ans);
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (;;) {
      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);
  }
}
