#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INf (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s);

template <class T>
string to_string(T v) {
  if (v.empty()) return "{}";
  string ret = "{";
  auto itr = v.begin(), next = ++v.begin();
  for (; next != v.end(); ++itr, ++next) ret += to_string(*itr) + ",";
  ret += to_string(*itr) + "}";
  return ret;
}
template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}
string to_string(string s) { return s; }

void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head) << " ";
  print(tail...);
}

struct IO {
#ifdef _WIN32
  inline char getchar_unlocked() { return getchar(); }
  inline void putchar_unlocked(char c) { putchar(c); }
#endif
  string separator = " ";
  template <class T>
  inline void read(T &x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c != '-' && (c < '0' || '9' < c));
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      c = getchar_unlocked();
    }
    x = 0;
    while ('0' <= c && c <= '9') {
      x *= 10;
      x += c - '0';
      c = getchar_unlocked();
    }
    if (minus) x = -x;
  }
  inline void read(string &x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c == ' ' || c == '\n');
    x.clear();
    do {
      x += c;
      c = getchar_unlocked();
    } while (c != ' ' && c != '\n' && c != EOF);
  }
  template <class T>
  inline void read(vector<T> &v) {
    for (auto &x : v) read(x);
  }
  template <class Head, class... Tail>
  inline void read(Head &head, Tail &... tail) {
    read(head);
    read(tail...);
  }
  template <class T>
  inline void write(T x) {
    char buf[32];
    int p = 0;
    if (x < 0) {
      x = -x;
      putchar_unlocked('-');
    }
    if (x == 0) putchar_unlocked('0');
    while (x > 0) {
      buf[p++] = (x % 10) + '0';
      x /= 10;
    }
    while (p) {
      putchar_unlocked(buf[--p]);
    }
  }
  inline void write(string x) {
    for (char c : x) putchar_unlocked(c);
  }
  inline void write(const char s[]) {
    for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
  }
  template <class T>
  inline void write(vector<T> v) {
    for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
      write(*itr);
      write(separator);
    }
    write(v.back());
  }
  template <class Head, class... Tail>
  inline void write(Head head, Tail... tail) {
    write(head);
    write(separator);
    write(tail...);
  }
  void set_separator(string s) { separator = s; }
} io;

using Weight = int;
using Flow = int;
struct Edge {
  int src, dst;
  Weight weight;
  Flow cap;
  Edge() : src(0), dst(0), weight(0) {}
  Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
  g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
}
class lca {
 public:
  int n, segn;
  std::vector<int> path, depth, in_order, out_order;
  std::vector<std::pair<int, int>> dat;
  const std::pair<int, int> INF = std::make_pair(1000000000, 1000000000);

  lca(const Graph &g, int root)
      : n(g.size()),
        path(n * 2 - 1),
        depth(n * 2 - 1),
        in_order(n),
        out_order(n) {
    int k = 0;
    dfs(g, root, -1, 0, k);
    for (segn = 1; segn < n * 2 - 1; segn <<= 1)
      ;
    dat.assign(segn * 2, INF);
    for (int i = 0; i < (int)depth.size(); ++i)
      dat[segn + i] = std::make_pair(depth[i], i);
    for (int i = segn - 1; i >= 1; --i)
      dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
  }

  int get(int u, int v) const {
    int l = std::min(in_order[u], in_order[v]);
    int r = std::max(in_order[u], in_order[v]) + 1;
    return path[range_min(1, segn, l, r).second];
  }

  void dfs(const Graph &g, int v, int p, int d, int &k) {
    in_order[v] = k;
    path[k] = v;
    depth[k++] = d;
    for (auto &e : g[v]) {
      if (e.dst != p) {
        dfs(g, e.dst, v, d + 1, k);
        path[k] = v;
        depth[k++] = d;
      }
    }
    out_order[v] = k;
  }

  std::pair<int, int> range_min(int v, int w, int l, int r) const {
    if (r <= l || w == 0) return INF;
    if (r - l == w) return dat[v];
    int m = w / 2;
    auto rmin = range_min(v * 2, m, l, std::min(r, m));
    auto lmin = range_min(v * 2 + 1, m, std::max(0, l - m), r - m);
    return min(rmin, lmin);
  }
  bool incl(int a, int v) {
    return in_order[a] <= in_order[v] && in_order[v] <= out_order[a];
  }
};
Graph to_rooted(const Graph &g, int r = 0) {
  int n = g.size();
  Graph ng(n);
  std::vector<int> ord(n, -1);
  std::queue<int> q;
  q.push(r);
  int k = 0;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (auto &e : g[u]) {
      int v = e.dst;
      if (ord[v] == -1) {
        ord[v] = k++;
        q.push(v);
        ng[u].emplace_back(e);
      }
    }
  }
  return ng;
}
int main() {
  int N;
  io.read(N);
  vector<Pii> ab(N - 1);
  Graph G(N);
  REP(i, N - 1) {
    int a, b;
    io.read(a, b);
    a--;
    b--;
    G[a].push_back(Edge(a, b, 1));
    G[b].push_back(Edge(b, a, 1));
    ab[i] = Pii(a, b);
  }
  G = to_rooted(G);
  lca l(G, 0);
  int M;
  io.read(M);
  vector<Pii> uv(M);
  REP(i, M) io.read(uv[i].first, uv[i].second);
  vector<vector<ll>> dp(N, vector<ll>(1 << M, 0));
  // debug(l.in_order, l.out_order);
  dp[0][0] = 1;
  REP(i, N - 1) {
    int a = ab[i].first, b = ab[i].second;
    int tmp = 0;
    REP(j, M) {
      bool f = 0;
      int u = uv[j].first - 1, v = uv[j].second - 1;
      int t = l.get(u, v);
      if (l.incl(t, a)) {
        if (l.incl(t, b)) {
          if (l.incl(a, u) || l.incl(a, v)) {
            if (l.incl(b, u) || l.incl(b, v)) {
              f = 1;
            }
          }
        }
      }
      if (f) tmp |= (1 << j);
    }
    dp[i + 1] = dp[i];
    REP(j, 1 << M) { dp[i + 1][j | tmp] += dp[i][j]; }
  }
  io.write(dp[N - 1][(1 << M) - 1]);
  io.write("\n");
  return 0;
}

Measured memory_bytes: 418304