#include <bits/stdc++.h>
using namespace std;
struct EDGE {
  int to, next;
} e[200010];
int head[100010], top;
void add(int u, int v) {
  e[top].to = v;
  e[top].next = head[u];
  head[u] = top++;
}
int fa[100010], sz[100010];
int a[100010], dep[100010];
long long szs[100010];
long long ans;
void dfs(int x) {
  sz[x] = 1;
  int i;
  for (i = head[x]; ~i; i = e[i].next) {
    if (e[i].to == fa[x]) continue;
    fa[e[i].to] = x;
    dep[e[i].to] = dep[x] + 1;
    dfs(e[i].to);
    sz[x] += sz[e[i].to];
  }
}
int f[100010];
int find_self(int x) {
  if (f[x] == x) return x;
  return f[x] = find_self(f[x]);
}
int find_fa(int x) { return fa[x] = find_self(fa[x]); }
int lca(int u, int v) {
  while (u != v) {
    if (dep[u] < dep[v]) swap(u, v);
    u = find_fa(u);
  }
  return u;
}
int main() {
  memset(head, 255, sizeof(head));
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int i;
  int u, v;
  for (i = 1; i < n; ++i) {
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  dep[1];
  dfs(1);
  int j;
  for (i = 1; i <= n; ++i) {
    a[i] = 1;
    f[i] = i;
    for (j = head[i]; ~j; j = e[j].next) {
      if (e[j].to == fa[i]) continue;
      szs[i] += 1ll * sz[e[j].to] * sz[e[j].to];
    }
    szs[i] += ((long long)n - sz[i]) * (n - sz[i]);
    ans += szs[i];
  }
  long long n3 = n;
  n3 = n3 * (n - 1) * (n - 1);
  cout << n3 - ans << '\n';
  int m;
  cin >> m;
  int t;
  for (i = 1; i <= m; ++i) {
    cin >> u >> v;
    u = find_self(u);
    v = find_self(v);
    int t = lca(u, v);
    int tmp;
    tmp = u;
    ans -= a[t] * (szs[t] + a[t] - 1);
    long long cnt = 0;
    while (u != t) {
      ans -= a[u] * (szs[u] + a[u] - 1);
      a[t] += a[u];
      f[u] = t;
      szs[t] += szs[u] - cnt * cnt - ((long long)n - sz[u]) * (n - sz[u]);
      cnt = sz[u];
      u = find_fa(u);
    }
    szs[t] -= 1ll * cnt * cnt;
    cnt = 0;
    while (v != t) {
      ans -= a[v] * (szs[v] + a[v] - 1);
      a[t] += a[v];
      f[v] = t;
      szs[t] += szs[v] - cnt * cnt - ((long long)n - sz[v]) * (n - sz[v]);
      cnt = sz[v];
      v = find_fa(v);
    }
    szs[t] -= 1ll * cnt * cnt;
    cnt = 0;
    ans += a[t] * (szs[t] + a[t] - 1);
    cout << n3 - ans << '\n';
  }
  return 0;
}
