#include <bits/stdc++.h>
using namespace std;
const long long N = 6e5;
class Graph {
  vector<long long> head, nxt, to, fa, siz, in, dep, sum, G;
  long long s, a, b, tot = 0, m, A, B;
  long long find(long long, long long);
  long long ans, S;
  long long f(long long, long long);
  void dfs(long long, long long);

 public:
  Graph();
  void treeEvaluator(long long);
  void edgesEvaluator(long long, long long);
};
Graph::Graph() {
  head.resize(N, 0);
  nxt.resize(2 * N, 0);
  to.resize(N * 2, 0);
  fa.resize(N, 0);
  siz.resize(N, 0);
  in.resize(N, 0);
  dep.resize(N, 0);
  sum.resize(N, 0);
  G.resize(N, 0);
}
long long Graph::find(long long x, long long n) {
  if (G[x] == x) {
    return x;
  } else {
    G[x] = find(G[x], n);
    return G[x];
  }
}
long long Graph::f(long long k, long long n) {
  long long temp11 = -1 * in[k];
  long long temp12 = sum[k];
  long long temp21 = 1 * in[k];
  long long temp22 = n - siz[k];
  long long temp23 = n - siz[k] - 1;
  long long temp1 = temp11 * temp12;
  long long temp2 = temp21 * temp22 * temp23;
  long long answer = temp1 - temp2;
  return answer;
}
void Graph::dfs(long long k, long long n) {
  siz[k] = 1;
  in[k] = 1;
  dep[k] = dep[fa[k]] + 1;
  int i = head[k];
  while (i) {
    if (to[i] != fa[k]) {
      fa[to[i]] = k;
      dfs(to[i], n);
      siz[k] += siz[to[i]];
      sum[k] += 1LL * siz[to[i]] * (siz[to[i]] - 1);
    }
    i = nxt[i];
  }
}
void Graph::treeEvaluator(long long n) {
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    to[++tot] = b, nxt[tot] = head[a], head[a] = tot;
    to[++tot] = a, nxt[tot] = head[b], head[b] = tot;
  }
  for (int i = 1; i <= n; i++) G[i] = i;
  dfs(1, n);
  ans = 1LL * n * (n - 1) * (n - 2);
  for (int i = 1; i <= n; i++) ans += f(i, n);
  cout << ans << endl;
}
void Graph::edgesEvaluator(long long n, long long m) {
  for (; m--;) {
    long long x, y;
    cin >> x >> y;
    a = find(x, n), b = find(y, n);
    S = s = A = B = 0;
    for (; a != b;) {
      if (dep[a] < dep[b]) swap(a, b);
      S += sum[a] - 1LL * siz[a] * (siz[a] - 1);
      s += in[a];
      ans -= f(a, n);
      G[a] = fa[a];
      a = find(fa[A = a], n);
    }
    S += sum[a];
    ans -= f(a, n);
    sum[a] = S;
    in[a] += s;
    ans += f(a, n);
    cout << ans << endl;
  }
}
int main() {
  long long n, m;
  cin >> n;
  Graph g;
  g.treeEvaluator(n);
  cin >> m;
  g.edgesEvaluator(n, m);
  return 0;
}
