#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define C make_pair
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for(int i = 0, _n = (n); i < _n; i++)
#define MASK(i) (1LL << (i))
#define BIT(i, x) ((x) & MASK(i))
#define TURN_ON(i, x) ((x) | MASK(i))
#define TURN_OFF(i, x) ((x) & ~MASK(i))
#define REV(i, x) ((x) ^ MASK(i))
template<typename T>bool maximize(T &res, const T &a){if(res < a) return res = a, true; return false;}
template<typename T>bool minimize(T &res, const T &a){if(res > a) return res = a, true; return false;}
const int maxn = (int)1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e15;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<ll, ll> pl;
typedef pair<ll, pl> pll;
int n, m, low[2 * maxn], num[2 * maxn], cnt, bridge;
pi edge[10 * maxn];
bool check[10 * maxn];
vector<int>a[2 * maxn];
void dfs(int u){
num[u] = low[u] = ++cnt;
for(int id: a[u]) if(!check[id]){
check[id] = 1;
int v = edge[id].fi + edge[id].se - u;
if(num[v]) minimize(low[u], num[v]);
else{
dfs(v);
minimize(low[u], low[v]);
if(low[v] > num[u]) bridge++;
}
}
}
void nhap(){
cin >> n;
FOR(i, 1, n - 1){
int u, v; cin >> u >> v;
a[u].pb(i);
a[v].pb(i);
edge[i] = C(u, v);
}
cin >> m;
FOR(i, 1, m){
int u, v; cin >> u >> v;
a[u].pb(i + n);
a[v].pb(i + n);
edge[i + n] = C(u, v);
}
}
void solve(){
dfs(1);
cout << bridge;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
nhap();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBmaSBmaXJzdAojZG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