#include<bits/stdc++.h>
using namespace std;
const int nax = 2 * (int)1e6 + 47;
int q[nax];
vector<int> g[nax];
vector<int> g2[nax];
int used[nax], d[nax];
int par[nax];
void dfs(int v, int p = -1)
{
par[v] = p;
for(auto to : g2[v])
{
if(to == p) continue;
dfs(to, v);
}
}
int main() {
int n;
scanf("%d", &n);
for(int i = 0; i < n - 1; i++)
{
int a,b;
scanf("%d%d", &a, &b);
--a,--b;
g2[a].push_back(b);
g2[b].push_back(a);
}
dfs(0);
for(int i = 1; i < n; i++)
{
g[par[i]].push_back(i);
}
int m;
scanf("%d", &m);
for(int i = 0; i < m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
--a, --b;
g[a].push_back(b);
}
int ql =0,qr = 1;
q[ql] = 0;
used[0] = 1;
while(ql != qr)
{
int v = q[ql++];
for(auto to : g[v])
{
if(!used[to])
{
used[to] = 1;
d[to] = d[v] + 1;
q[qr++] = to;
}
}
}
int ans = 0;
for(int i = 0; i < n; i++)
ans = max(ans, d[i]);
cout << ans << '\n';
return 0;
}