#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
int f[100005];
int ff(int x) { return x == f[x] ? x : f[x] = ff(f[x]); }
vector<int> mp[100005];
int p[100005], d[100005];
long long sz[100005], cs[100005], in[100005];
long long invalid(int x) {
  return (in[x] * cs[x] + in[x] * (n - sz[x]) * (n - sz[x] - 1));
}
void dfs(int x, int pa) {
  p[x] = pa;
  d[x] = d[pa] + 1;
  sz[x] = 1;
  in[x] = 1;
  for (int c : mp[x])
    if (c != pa) {
      dfs(c, x);
      sz[x] += sz[c];
      cs[x] += sz[c] * (sz[c] - 1);
    }
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  long long Ans = (long long)n * (n - 1) * (n - 2);
  dfs(1, 0);
  for (int(i) = 1; (i) <= (int)(n); (i)++) Ans -= invalid(i);
  printf("%lld\n", Ans);
  scanf("%d", &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) f[i] = i;
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    int fu = ff(u), fv = ff(v);
    long long s = 0, S = 0;
    while (fu != fv) {
      if (d[fu] < d[fv]) swap(fu, fv);
      s += in[fu];
      S += cs[fu] - sz[fu] * (sz[fu] - 1);
      Ans += invalid(fu);
      f[fu] = ff(p[fu]);
      fu = f[fu];
    }
    S += cs[fu];
    Ans += invalid(fu);
    in[fu] += s;
    cs[fu] = S;
    Ans -= invalid(fu);
    printf("%lld\n", Ans);
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
