#include <bits/stdc++.h>
using namespace std;
const int Mxxx = 1e5;
inline char gc() {
  static char buf[Mxxx], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, Mxxx, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline char pc(char ch, bool fl = false) {
  static char buf[Mxxx], *p1 = buf, *p2 = buf + Mxxx;
  return (fl || ((*p1++ = ch) && p1 == p2)) &&
             (fwrite(buf, 1, p1 - buf, stdout), p1 = buf),
         0;
}
inline int read() {
  char ch = gc();
  int gflag = 0, gans = 0;
  while (ch < '0' || ch > '9') {
    gflag |= (ch == '-');
    ch = gc();
  }
  while ('0' <= ch && ch <= '9') {
    gans = (gans << 1) + (gans << 3) + (ch ^ 48);
    ch = gc();
  }
  return gflag ? -gans : gans;
}
template <typename T>
inline char read(T &gans) {
  char ch = gc();
  int gflag = 0;
  gans = 0;
  while (ch < '0' || ch > '9') {
    gflag |= (ch == '-');
    ch = gc();
  }
  while ('0' <= ch && ch <= '9') {
    gans = (gans << 1) + (gans << 3) + (ch ^ 48);
    ch = gc();
  }
  gans = gflag ? -gans : gans;
  return ch;
}
template <typename T>
inline void write(T x) {
  if (x > 9) {
    write(x / 10);
  }
  pc(x % 10 ^ 48, false);
}
template <typename T>
inline void writenum(T x, char ch) {
  if (x < 0) {
    pc('-', false);
    x = -x;
  }
  write(x);
  pc(ch, false);
}
inline void writechar(char x, char ch) {
  pc(x, false);
  pc(ch, false);
}
template <typename T>
inline T Min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
inline T Max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
inline T Abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
inline void ckmx(T &x, T y) {
  x = Max(x, y);
}
template <typename T>
inline void ckmn(T &x, T y) {
  x = Min(x, y);
}
const int Mx = 1e5;
struct Link {
  int next, to;
} a[(Mx << 1) + 5];
int n, Q, cnt, h[Mx + 5], sz[Mx + 5], pr[Mx + 5], dp[Mx + 5];
long long ans, val[Mx + 5];
inline long long Sqr(int x) { return (long long)x * x; }
inline void ade(int x, int y) {
  cnt++;
  a[cnt].next = h[x];
  a[cnt].to = y;
  h[x] = cnt;
}
inline void Ade(int x, int y) {
  ade(x, y);
  ade(y, x);
}
inline void DFS(int x, int y, int z) {
  int i, to;
  sz[x] = 1;
  pr[x] = y;
  dp[x] = z;
  for (i = h[x]; i; i = a[i].next) {
    if ((to = a[i].to) ^ y) {
      DFS(to, x, z + 1);
      sz[x] += sz[to];
      val[x] += Sqr(sz[to]);
    }
  }
  ans -= (val[x] += Sqr(n - sz[x]));
}
namespace dsu {
int siz[Mx + 5], prt[Mx + 5];
inline int Gf(int x) { return prt[x] == x ? x : prt[x] = Gf(prt[x]); }
inline void Pre() {
  int i;
  for (i = 1; i <= n; i++) {
    siz[i] = 1;
    prt[i] = i;
  }
}
inline long long Get_Calc(int x) {
  return siz[x] * ((long long)Sqr(n - 1) - siz[x] + 1 - val[x]);
}
inline void Mrg(int x, int y) {
  ans -= Get_Calc(x) + Get_Calc(y);
  val[y] += val[x] - Sqr(sz[x]) - Sqr(n - sz[x]);
  ans += Get_Calc((siz[y] += siz[x], prt[x] = y));
}
}  // namespace dsu
inline int Gf(int x) { return dsu::Gf(x); }
inline void Mrg(int x, int y) { dsu::Mrg(x, y); }
inline void Pre() {
  ans = (long long)n * (n - 1) * (n - 1);
  dsu::Pre();
  DFS(1, 0, 1);
}
inline void Lnk(int x, int y) {
  for (x = Gf(x), y = Gf(y); x ^ y; Mrg(x, pr[x] = Gf(pr[x])), x = pr[x]) {
    if (dp[x] < dp[y]) {
      (x ^= y ^= x ^= y);
    }
  }
}
signed main() {
  int i;
  n = read();
  for (i = 1; i < n; i++) {
    Ade(read(), read());
  }
  for (Pre(), writenum(ans, 10), Q = read(); Q; Q--) {
    Lnk(read(), read());
    writenum(ans, 10);
  }
  return pc('!', true);
}
