////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include "bits/stdc++.h"
using namespace std;

// -- typedefs -- //
#define EPS 1e-9
typedef long long llong;

// -- loop macros -- //
#define LOOP_TYPE(s,n) std::remove_reference_t<std::remove_cv_t<decltype((n)-(s))>>
#define FOR(i,s,n)  for (auto i = LOOP_TYPE(s,n)(s);   i < LOOP_TYPE(s,n)(n);   i++)
#define FORR(i,s,n) for (auto i = LOOP_TYPE(s,n)(n)-1; i != LOOP_TYPE(s,n)(s)-1; i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) FORR(i,0,n)

#define FORE(exp) for (auto && exp)
#define allof(c) c.begin(), c.end()
#define partof(c,s,e) c.begin() + (s), c.begin() + (e)

// -- functors -- //
#define PREDICATE(t,a,...) [&](const t & a) -> bool { return __VA_ARGS__; }
#define PRED(a,...) PREDICATE(auto,a,__VA_ARGS__)
#define COMPARISON(t,a,b,...) [&](const t & a, const t & b) -> bool { return __VA_ARGS__; }
#define COMP(a,b,...) COMPARISON(auto,a,b,__VA_ARGS__)
#define CONV1(a,...) [&](const auto & a) -> auto { return __VA_ARGS__; }
#define CONV2(a,b,...) [&](const auto & a, const auto & b) -> auto { return __VA_ARGS__; }
#define CONV3(a,b,c,...) [&](const auto & a, const auto & b, const auto & c) -> auto { return __VA_ARGS__; }

#define TIE(...) auto tie() const { return std::tie(__VA_ARGS__); }
#define LESS(t) bool operator <(const t &rhs) const { return tie() < rhs.tie(); }
#define GREATER(t) bool operator >(const t &rhs) const { return tie() > rhs.tie(); }

// -- I/O Helper -- //
struct _Reader { istream& cin; template <class T> _Reader operator ,(T& rhs) { cin >> rhs; return *this; } };
struct _Writer { ostream& cout; const char* d{ " " }; bool f{}; template <class T> _Writer operator ,(const T& rhs) { cout << (f ? d : "") << rhs; f = 1; return *this; } };
#define READ(t,...) t __VA_ARGS__; (_Reader{cin}), __VA_ARGS__
#define WRITE(...) do { (_Writer{cout}), __VA_ARGS__; cout << endl; } while (false)
#define WRITELN(...)  do { (_Writer{cout, "\n"}), __VA_ARGS__; cout << endl; } while (false)
#define WRITE2D(vevector) FORE(row : vevector) WRITE(row)
#ifdef _DEBUG
#define DEBUG(...) (_Writer{cerr}), "DEBUG -> ", __VA_ARGS__, "\n"
#else
#define DEBUG(...)
#endif

// -- vevector -- //
template <class T> struct vevector : vector<vector<T>> { vevector(size_t n = 0, size_t m = 0, const T& initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } };
template <class T> struct vevevector : vector<vevector<T>> { vevevector(size_t n = 0, size_t m = 0, size_t l = 0, const T& initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } };
template <class T> struct vevevevector : vector<vevevector<T>> { vevevevector(size_t n = 0, size_t m = 0, size_t l = 0, size_t k = 0, const T& initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } };

namespace std {
	template <class T1, class T2> istream& operator >> (istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return in; }
	template <class T1, class T2> ostream& operator << (ostream& out, const pair<T1, T2>& p) { out << p.first << " " << p.second; return out; }
}

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; }
template <class T> vector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; }

template <class T> struct iter_range_t { T beg, end; };
template <class T> iter_range_t<T> iter_range(T beg, T end) { return iter_range_t<T>{beg, end}; }
template <class T> ostream& operator << (ostream& out, iter_range_t<T> v) { if (v.beg != v.end) { out << *v.beg++; while (v.beg != v.end) { out << " " << *v.beg++; } } return out; }
template <class T> ostream& operator << (ostream& out, const vector<T>& v) { return out << iter_range(allof(v)); }

// -- etc -- //
template <class T> T infinity_value();
template <> int infinity_value<int>() { return int(1) << 30; }
template <> llong infinity_value<llong>() { return llong(1) << 60; }
template <> double infinity_value<double>() { return 1e+300 * 1e+300; }
#define INF(T) infinity_value<T>()

inline int sign_of(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
template <class TInt> bool in_range(TInt val, TInt min, TInt max) { return val >= min && val < max; }
template <> bool in_range<double>(double val, double min, double max) { return val - min > -EPS && val - max < EPS; }
template <class TInt> bool in_range2d(TInt x, TInt y, TInt w, TInt h) { return x >= 0 && x < w && y >= 0 && y < h; }
vector<int> iotavn(int start, int count) { vector<int> r(count); iota(allof(r), start);	return r; }


//// start up ////
void solve();
int32_t main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(std::numeric_limits<double>::max_digits10);
	solve();

	return 0;
}

//// bit ////
typedef uint32_t uint;
typedef uint64_t ullong;
#ifdef _MSC_VER
#ifdef _WIN32
inline uint __builtin_ctz(uint x) { unsigned long r; _BitScanForward(&r, x); return r; }
inline uint __builtin_clz(uint x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; }
inline uint __builtin_ffs(uint x) { unsigned long r; return _BitScanForward(&r, x) ? r + 1 : 0; }
inline uint __builtin_popcount(uint x) { return __popcnt(x); }
inline ullong __builtin_ctzll(ullong x) { unsigned long r; _BitScanForward64(&r, x); return r; }
inline ullong __builtin_clzll(ullong x) { unsigned long r; _BitScanReverse64(&r, x); return 63 - r; }
inline ullong __builtin_ffsll(ullong x) { unsigned long r; return _BitScanForward64(&r, x) ? r + 1 : 0; }
inline ullong __builtin_popcountll(ullong x) { return __popcnt64(x); }
#endif // _WIN32
#endif // _MSC_VER

inline uint bsf(uint v) { return __builtin_ctz(v); } // 最下位の1は下から数えて何ビットめか？
inline ullong bsf(ullong v) { return __builtin_ctzll(v); } // 最下位の1は下から数えて何ビットめか？
inline uint bsr(uint v) { return 31 - __builtin_clz(v); } // 最上位の1は下から数えて何ビットめか？
inline ullong bsr(ullong v) { return 63 - __builtin_clzll(v); } // 最上位の1は下から数えて何ビットめか？
inline uint msb(uint v) { return 1 << bsr(v); } // 最上位の1だけ残す
inline ullong msb(ullong v) { return 1ull << bsr(v); } // 最上位の1だけ残す
inline uint lsb(uint v) { return v & -signed(v); } // 最下位の1だけ残す
inline ullong lsb(ullong v) { return v & -signed(v); } // 最下位の1だけ残す
inline uint pop_lsb(uint v) { return v & v - 1; } // 最下位の1以外を残す
inline ullong pop_lsb(ullong v) { return v & v - 1; } // 最下位の1以外を残す
inline uint round_up_pow2(uint v) { return msb(v - 1) << 1; } // 2の累乗に切り上げ
inline ullong round_up_pow2(ullong v) { return msb(v - 1) << 1; } // 2の累乗に切り上げ

// bit permutation
	// ex) 16bit空間に5bitだけ立ってるものを列挙
	//   ) for (auto value : BitPermutation(16, 5)) ...
struct BitPermutation
{
#ifdef _MSC_VER
	static uint64_t __builtin_ctzll(uint64_t x) { unsigned long r; _BitScanForward64(&r, x); return r; }
#endif
	static uint64_t next_bit_permutation(uint64_t x) {
		uint64_t t = x | (x - 1);
		uint64_t p = (~t & -int64_t(~t)) - 1;
		return (t + 1) | (p >> (x ? __builtin_ctzll(x) + 1 : 0));
	}

	struct it {
		uint64_t val;
		uint64_t operator *() const { return val; }
		it& operator ++() { val = next_bit_permutation(val); return *this; }
		bool operator != (it o) const { return val != o.val; }
	} s, e;

	BitPermutation(int n, int k)
		: s{ (1ull << k) - 1 }
		, e{ next_bit_permutation(s.val << (n - k)) }
	{
		assert(n >= k);
	}
	it begin() const { return s; }
	it end() const { return e; }
};
////////////////////
//// template end
////////////////////

void solve()
{
	READ(int, N);

	struct E
	{
		int from, to, id;
	};
	vevector<E> G(N);
	REP(i, N - 1)
	{
		READ(int, a, b); a--; b--;
		G[a].push_back({ a, b, i });
		G[b].push_back({ b, a, i });
	}

	vector<llong> conds;

	READ(int, M);
	REP(i, M)
	{
		READ(int, u, v); u--; v--;
		vector<bool> vist(N);
		vector<E> from(N);
		queue<int> q;
		vist[u] = true;
		q.push(u);
		while (!q.empty())
		{
			auto p = q.front(); q.pop();
			FORE(e : G[p])
			{
				if (!vist[e.to])
				{
					vist[e.to] = true;
					from[e.to] = e;
					q.push(e.to);
				}
			}
		}


		llong cond = 0;
		int cur = v;
		while(true)
		{
			if (cur == u)
			{
				break;
			}

			cond |= 1ll << from[cur].id;
			cur = from[cur].from;
		}
		conds.push_back(cond);
	}

	llong ans = 0;
	FOR(i, 1, M+1)
	{
		FORE(j : BitPermutation(M, i))
		{
			llong target = 0;
			REP(k, M) if(1ll<<k & j)
			{
				target |= conds[k];
			}
			llong m = (1ll << (N - 1 - __builtin_popcountll(target)));

			if (i % 2 == 0)
			{
				m = -m;
			}
			ans += m;
		}
	}
	WRITE((1ll<<(N-1)) - ans);
}



Measured memory_bytes: 256