#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = int(1e5) + 10;
vector<int> g[N];
int dsu[N], sub[N], sz[N], level[N], par[N], n;
long long int cont[N];
void dfs(int x, int p) {
  par[x] = p;
  for (auto y : g[x])
    if (y != p) {
      level[y] = level[x] + 1;
      dfs(y, x);
      sub[x] += sub[y];
    }
  for (auto y : g[x])
    if (y != p) cont[x] += sub[y] * 1ll * (sub[x] - sub[y]);
  sub[x] += 1;
}
int f(int x) { return dsu[x] = (dsu[x] == x ? x : f(dsu[x])); }
void merge(int a, int b, long long int& ans) {
  int sza = 0, szb = 0;
  long long int val = 0;
  auto add1 = [&](int x) {
    long long int n1 = sz[x];
    return n1 * (n1 - 1) * (n1 - 2);
  };
  auto add2 = [&](int x) {
    long long int n1 = sz[x];
    return n1 * (n1 - 1) * 2 * (n - n1);
  };
  auto add3 = [&](int x) {
    return (sub[x] - sz[x]) * 1ll * (n - sub[x]) * 2 * 1ll * sz[x];
  };
  for (a = f(a), b = f(b); a != b; a = f(a), b = f(b)) {
    if (level[a] > level[b]) {
      swap(a, b);
      swap(sza, szb);
    }
    int x = f(b), y = f(par[b]);
    szb += sz[x];
    val += cont[x];
    val -= (sub[y] - sz[y] - sub[x]) * 1ll * szb * 2;
    ans -= cont[x] * 1ll * sz[x];
    ans -= add1(x);
    ans -= add2(x);
    ans -= add3(x);
    dsu[x] = y;
  }
  ans -= cont[a] * 1ll * sz[a];
  ans -= add1(a);
  ans -= add2(a);
  ans -= add3(a);
  val += cont[a];
  val += sza * 1ll * szb * 1ll * 2;
  sz[a] += sza + szb;
  cont[a] = val;
  ans += cont[a] * 1ll * sz[a];
  ans += add1(a);
  ans += add2(a);
  ans += add3(a);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int x = 1; x <= n; x++) {
    dsu[x] = x;
    sz[x] = 1;
  }
  dfs(1, 1);
  long long int ans = 0;
  for (int x = 1; x <= n; x++) {
    ans += cont[x] + (sub[x] - sz[x]) * 1ll * (n - sub[x]) * 2;
  }
  printf("%lld\n", ans);
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    merge(a, b, ans);
    printf("%lld\n", ans);
  }
  return 0;
}
