You are given a tree consisting of n vertices, and m simple vertex paths. Your task is to find how many pairs of those paths intersect at exactly one vertex. More formally you have to find the number of pairs (i, j) (1 ≤ i < j ≤ m) such that path_i and path_j have exactly one vertex in common. 

Input

First line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5).

Next n - 1 lines describe the tree. Each line contains two integers u and v (1 ≤ u, v ≤ n) describing an edge between vertices u and v.

Next line contains a single integer m (1 ≤ m ≤ 3 ⋅ 10^5).

Next m lines describe paths. Each line describes a path by it's two endpoints u and v (1 ≤ u, v ≤ n). The given path is all the vertices on the shortest path from u to v (including u and v).

Output

Output a single integer — the number of pairs of paths that intersect at exactly one vertex.

Examples

Input


5
1 2
1 3
1 4
3 5
4
2 3
2 4
3 4
3 5


Output


2


Input


1
3
1 1
1 1
1 1


Output


3


Input


5
1 2
1 3
1 4
3 5
6
2 3
2 4
3 4
3 5
1 1
1 2


Output


7

Note

<image>

The tree in the first example and paths look like this. Pairs (1,4) and (3,4) intersect at one vertex.

In the second example all three paths contain the same single vertex, so all pairs (1, 2), (1, 3) and (2, 3) intersect at one vertex.

The third example is the same as the first example with two additional paths. Pairs (1,4), (1,5), (2,5), (3,4), (3,5), (3,6) and (5,6) intersect at one vertex.
#include <bits/stdc++.h>

struct IO {
  IO(FILE *in = stdin) : in(in) {}

  int next_char() {
    if (position == length) {
      position = 0, length = fread(buffer, 1, LENGTH, in);
    }
    if (position == length) {
      eof = true;
      return -1;
    }
    return buffer[position++];
  }

  int next_uint() {
    int c = next_char(), x = 0;
    while (c <= 32) {
      c = next_char();
    }
    for (; '0' <= c && c <= '9'; c = next_char()) {
      x = x * 10 + c - '0';
    }
    return x;
  }

  int next_int() {
    int s = 1, c = next_char(), x = 0;
    while (c <= 32) {
      c = next_char();
    }
    if (c == '-') {
      s = -1, c = next_char();
    }
    for (; '0' <= c && c <= '9'; c = next_char()) {
      x = x * 10 + c - '0';
    }
    return x * s;
  }

  void next_string(char *s) {
    int c = next_char();
    while (c <= 32) {
      c = next_char();
    }
    for (; c > 32; c = next_char()) {
      *s++ = c;
    }
    *s = 0;
  }

private:
  static const int LENGTH = 1 << 16;

  char buffer[LENGTH];
  int position = 0, length = 0;
  bool eof = false;
  FILE *in;
};

const int N = 300000;

int n, m, first_edge[N], edge[N << 1], next_edge[N << 1], degree[N],
    first_path[N], path[N << 1], next_path[N << 1], parent[N], dfs_order[N],
    LCA[N], children[N][2];

struct {
  int count, current_child[N];

  struct DSU {
    int parent;
    int child;
  } dsu[N];

  int find(int u) { // return the root
    if (dsu[u].parent == -1 || dsu[u].parent == u) {
      return u;
    }
    int p = dsu[u].parent;
    int r = find(p);
    dsu[u].parent = r;
    if (~dsu[p].child) {
      dsu[u].child = dsu[p].child;
    }
    return r;
  }

  void dfs(int u) {
    dfs_order[count++] = u;
    for (int iterator = first_edge[u]; ~iterator;
         iterator = next_edge[iterator]) {
      int v = edge[iterator];
      if (v != parent[u]) {
        current_child[u] = v;
        parent[v] = u;
        dfs(v);
        dsu[v] = DSU{u, v};
      }
    }
    current_child[u] = -1;
    dsu[u].parent = u;
    for (int iterator = first_path[u]; ~iterator;
         iterator = next_path[iterator]) {
      int v = path[iterator];
      if (~dsu[v].parent) {
        int root = find(v);
        int id = iterator >> 1;
        LCA[id] = root;
        children[id][0] = dsu[v].child;
        children[id][1] = current_child[root];
        if (iterator & 1) {
          std::swap(path[iterator], path[iterator ^ 1]);
        }
      }
    }
  }
} tarjan;

int point_count[N], point_sum[N], cross_top_count[N], cross_bot_count[N],
    cross_sum[N];

struct {
  int &get(int i) {
    if (timestamp[i] != now) {
      timestamp[i] = now;
      count[i] = 0;
    }
    return count[i];
  }

  int now = 0;
  int timestamp[N], count[N];
} counter;

int main() {
  IO io;
  n = io.next_int();
  for (int i = 0; i < (n - 1) << 1; ++i) {
    edge[i] = io.next_int() - 1;
  }
  memset(degree, -1, sizeof(*degree) * n);
  memset(first_edge, -1, sizeof(*first_edge) * n);
  degree[0] = 0;
  for (int i = 0; i < (n - 1) << 1; ++i) {
    degree[edge[i]]++;
    next_edge[i] = first_edge[edge[i ^ 1]];
    first_edge[edge[i ^ 1]] = i;
  }
  m = io.next_int();
  for (int i = 0; i < m << 1; ++i) {
    path[i] = io.next_int() - 1;
  }
  memset(first_path, -1, sizeof(*first_path) * n);
  for (int i = 0; i < m << 1; ++i) {
    if ((~i & 1) || path[i] != path[i ^ 1]) {
      next_path[i] = first_path[path[i ^ 1]];
      first_path[path[i ^ 1]] = i;
    }
  }
  memset(tarjan.dsu, -1, sizeof(*tarjan.dsu) * n);
  parent[0] = -1;
  tarjan.dfs(0);
  long long result = 0;
  for (int i = 0; i < m; ++i) {
    if (children[i][0] == -1) {
      assert(children[i][1] == -1);
    }
  }
  for (int i = 0; i < m << 1; i += 2) {
    int v = path[i];
    int u = path[i ^ 1];
    int w = LCA[i >> 1];
    // printf("LCA(%d, %d)=%d %d %d\n", v + 1, u + 1, w + 1, children[i >> 1][0]
    // + 1, children[i >> 1][1] + 1);
    if (v == u) {
      result += point_count[v]; // point - point
      point_count[v]++;
    } else {
      cross_top_count[w]++;
      cross_bot_count[children[i >> 1][0]]++;
      if (u != w) {
        cross_bot_count[children[i >> 1][1]]++;
      }
      // cross_top_count[u] - cross_bot_count[v] = # of paths P
      // * parent[u] \in P
      // * u \in P
      // * v \notin P
    }
  }
  point_sum[0] = cross_sum[0] = 0;
  for (int i = 1; i < n; ++i) {
    int u = dfs_order[i];
    int p = parent[u];
    point_sum[u] = point_sum[p] + point_count[u];
    cross_sum[u] = cross_sum[p] + (cross_top_count[u] - cross_bot_count[u]);
  }
  for (int i = 0; i < m << 1; i += 2) {
    int v = path[i];
    int u = path[i ^ 1];
    int w = LCA[i >> 1];
    if (v != u) {
      // path * point
      result += point_sum[v] + point_sum[u] - 2 * point_sum[w] + point_count[w];
      // {internal, leaf} * cross
      result +=
          cross_sum[v] - cross_sum[w] + cross_bot_count[children[i >> 1][0]];
      if (u != w) {
        result +=
            cross_sum[u] - cross_sum[w] + cross_bot_count[children[i >> 1][1]];
      }
      // cross * cross
    }
  }
  using Path = std::tuple<int, int, int>;
  std::vector<Path> paths;
  paths.reserve(m);
  for (int i = 0; i < m; ++i) {
    if (path[i << 1] != path[i << 1 | 1]) {
      int v = children[i][0];
      int u = children[i][1];
      if (v < u) {
        std::swap(v, u);
      }
      paths.emplace_back(LCA[i], v, u);
    }
  }
  std::sort(paths.begin(), paths.end());
  long long cross_pairs = 0;
  for (int lb = 0; lb < static_cast<int>(paths.size());) {
    counter.now++;
    int ub = lb;
    while (ub < static_cast<int>(paths.size()) &&
           std::get<0>(paths[lb]) == std::get<0>(paths[ub])) {
      int _, v, u;
      std::tie(_, v, u) = paths[ub];
      counter.get(v)++;
      if (~u) {
        counter.get(u)++;
      }
      ub++;
    }
    int total = ub - lb;
    for (int i = lb; i < ub;) {
      int occ = 0;
      while (i + occ < ub && paths[i] == paths[i + occ]) {
        occ++;
      }
      int v = std::get<1>(paths[i]);
      int u = std::get<2>(paths[i]);
      cross_pairs += static_cast<long long>(total - counter.get(v) +
                                            (~u ? occ - counter.get(u) : 0)) *
                     occ;
      i += occ;
    }
    lb = ub;
  }
  std::cout << result + cross_pairs / 2 << std::endl;
}