import java.util.*; import java.io.*; public class Main { static ArrayList> graph = new ArrayList<>(); static int[] costs; static int[] depth; static int[][] parents; public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); for (int i = 0; i < n; i++) { graph.add(new HashSet<>()); } for (int i = 0; i < n - 1; i++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]) - 1; int b = Integer.parseInt(line[1]) - 1; graph.get(a).add(b); graph.get(b).add(a); } costs = new int[n]; parents = new int[18][n]; depth = new int[n]; setParent(0, 0, 0); for (int i = 1; i < 18; i++) { for (int j = 0; j < n; j++) { parents[i][j] = parents[i - 1][parents[i - 1][j]]; } } int m = Integer.parseInt(br.readLine()); for (int i = 0; i < m; i++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]) - 1; int b = Integer.parseInt(line[1]) - 1; int lca = getLCA(a, b); costs[a]++; costs[b]++; costs[lca]--; if (lca != 0) { costs[parents[0][lca]]--; } } ArrayDeque deq = new ArrayDeque<>(); for (int i = 1; i < n; i++) { if (graph.get(i).size() == 1) { doImos(i); } } while (deq.size() > 0) { int x = deq.poll(); if (x == 0) { continue; } costs[parents[0][x]] += costs[x]; graph.get(parents[0][x]).remove(x); if (graph.get(parents[0][x]).size() == 1) { deq.add(parents[0][x]); } } long total = 0; for (int x : costs) { total += (long)x * (x + 1) / 2; } System.out.println(total); } static void doImos(int idx) { if (idx == 0) { return; } costs[parents[0][idx]] += costs[idx]; graph.get(parents[0][idx]).remove(idx); if (graph.get(parents[0][idx]).size() == 1) { doImos(parents[0][idx]); } } static void setParent(int idx, int parent, int d) { parents[0][idx] = parent; depth[idx] = d; for (int x : graph.get(idx)) { if (x == parent) { continue; } setParent(x, idx, d + 1); } } static int getLCA(int a, int b) { if (depth[a] > depth[b]) { return getLCA(b, a); } for (int i = 17; i >= 0; i--) { if (depth[b] - depth[a] >= (1 << i)) { b = parents[i][b]; } } for (int i = 17; i >= 0; i--) { if (parents[i][a] != parents[i][b]) { a = parents[i][a]; b = parents[i][b]; } } if (a != b) { a = parents[0][a]; b = parents[0][b]; } return a; } }