#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[100001];
vector<int> children[100001];
long long dp[100001], dp2[100001], ans = 0, Size[100001];
bool visit[100001];
int parent[100001], depth[100001];
int Parent[100001];
int find(int x) {
  if (Parent[x] == x)
    return x;
  else {
    int temp = find(Parent[x]);
    Parent[x] = temp;
  }
  return Parent[x];
}
long long bfs(int i) {
  if (dp[i] != -1)
    return dp[i];
  else {
    dp[i] = 1;
    visit[i] = true;
    for (auto it : adj[i]) {
      if (!visit[it]) {
        depth[it] = 1 + depth[i];
        dp[i] += bfs(it);
        children[i].push_back(it);
        parent[it] = i;
      }
    }
  }
  return dp[i];
}
void Merge(int u, int v) {
  ans -= Size[u] * (Size[u] - 1) * (Size[u] - 2);
  ans -= Size[v] * (Size[v] - 1) * (Size[v] - 2);
  ans -= Size[u] * (Size[u] - 1) * (n - Size[u]) * 2;
  ans -= Size[v] * (Size[v] - 1) * (n - Size[v]) * 2;
  ans -= (((n - Size[u]) * (n - Size[u]) * Size[u]) - ((dp2[u]) * Size[u]));
  ans -= (((n - Size[v]) * (n - Size[v]) * Size[v]) - ((dp2[v]) * Size[v]));
  Parent[v] = u;
  dp2[u] += dp2[v] - dp[v] * dp[v] - (n - dp[v]) * (n - dp[v]);
  Size[u] = Size[u] + Size[v];
  ans += (Size[u]) * (Size[u] - 1) * (Size[u] - 2);
  ans += (Size[u]) * (Size[u] - 1) * (n - Size[u]) * 2;
  ans += (((n - Size[u]) * (n - Size[u]) * Size[u]) - ((dp2[u] * Size[u])));
}
int main() {
  memset(dp, -1, sizeof dp);
  memset(visit, 0, sizeof visit);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  parent[1] = 0;
  depth[1] = 0;
  bfs(1);
  for (int i = 1; i <= n; i++) {
    long long temp = 0, sum = 0;
    long long temp2 = 0;
    dp2[i] = 0;
    for (auto it : children[i]) {
      temp += (dp[it] * dp[it]);
      temp2 += (dp[it]) * (dp[it]);
      sum += dp[it];
    }
    ans += (sum * sum) - temp;
    ans += 2 * (n - dp[i]) * (dp[i] - 1);
    dp2[i] = temp2 + (n - dp[i]) * (n - dp[i]);
  }
  cout << ans << endl;
  int m;
  cin >> m;
  for (int i = 1; i <= n; i++) {
    Parent[i] = i;
    Size[i] = 1;
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    u = find(u);
    v = find(v);
    while (u != v) {
      if (depth[u] < depth[v]) swap(u, v);
      Merge(find(parent[u]), u);
      u = find(u);
    }
    cout << ans;
    if (m != 0) cout << endl;
  }
  return 0;
}
