#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
//#define int long long
using namespace std;
const int mod=1e9+7,mxn=1e5+20000,inf=1e9,minf=-1e9,lg=30;
//#undef int
int n,k,m;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
vector<int>adj[mxn+10];
int S[mxn+10],T[mxn+10],target,root;
int hvyp[mxn+10],sz[mxn+10],tin[mxn+10],tout[mxn+10],up[mxn+10][lg+1],h[mxn+10];
pii tmp;
struct segmx{
pii v[2*mxn+10];
priority_queue<pii>pq[mxn+10];
void init(){for(int i=0;i<=2*n;i++)v[i]={minf,minf};}
void update(int pos,pii val,int del){
if(!del)pq[pos].push(val);
else{
if(pq[pos].top()==val)pq[pos].pop();
else{
tmp=pq[pos].top();
pq[pos].pop();
pq[pos].pop();
pq[pos].push(tmp);
}
}
if(!pq[pos].empty())v[pos+n]=pq[pos].top();
else v[pos+n]={minf,minf};
pos+=n;
for(int i=pos;i>0;i>>=1)v[i>>1]=max(v[i],v[i^1]);
}
pii qry(int l,int r){
pii ans={minf,minf};
for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
if(l&1)ans=max(ans,v[l++]);
if(!(r&1))ans=max(ans,v[r--]);
}
return ans;
}
}t;
struct segmn{
pii v[2*mxn+10];
priority_queue<pii,vector<pii>,greater<pii>>pq[mxn+10];
void init(){for(int i=0;i<=2*n;i++)v[i]={inf,inf};}
void update(int pos,pii val,int del){
if(!del)pq[pos].push(val);
else{
if(pq[pos].top()==val)pq[pos].pop();
else{
tmp=pq[pos].top();
pq[pos].pop();
pq[pos].pop();
pq[pos].push(tmp);
}
}
if(!pq[pos].empty())v[pos+n]=pq[pos].top();
else v[pos+n]={inf,inf};
pos+=n;
for(int i=pos;i>0;i>>=1)v[i>>1]=min(v[i],v[i^1]);
}
pii qry(int l,int r){
pii ans={inf,inf};
for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
if(l&1)ans=min(ans,v[l++]);
if(!(r&1))ans=min(ans,v[r--]);
}
return ans;
}
}t2,t3;
int ct=0;
int lca(int x,int y){
if(h[x]<h[y])swap(x,y);
int k=h[x]-h[y];
for(int i=0;i<=lg;i++)if(k&(1LL<<i))x=up[x][i];
if(x==y)return x;
for(int i=lg;i>=0;i--)if(up[x][i]!=up[y][i]){
x=up[x][i],y=up[y][i];
}
return up[x][0];
}
void getsz(int cur,int p){sz[cur]=1;for(auto i:adj[cur])if(i!=p)getsz(i,cur),sz[cur]+=i;}
void dfs(int cur,int p){
sz[cur]=1;
tin[cur]=++ct;
int hvy=0;
for(auto i:adj[cur])if(i!=p&&sz[i]>sz[hvy])hvy=i;
if(hvy){
hvyp[hvy]=hvyp[cur];
up[hvy][0]=cur,h[hvy]=h[cur]+1;
sz[cur]+=sz[hvy];
dfs(hvy,cur);
}
for(auto i:adj[cur])if(i!=p&&i!=hvy){
up[i][0]=cur;
h[i]=h[cur]+1;
hvyp[i]=i;
dfs(i,cur),sz[cur]+=sz[i];
}
tout[cur]=ct;
}
int on[mxn+10],vis[mxn+10];
void del(int i,int x){
t.update(tin[S[i]],{tin[T[i]],i},x);
t.update(tin[T[i]],{tin[S[i]],i},x);
t2.update(tin[S[i]],{tin[T[i]],i},x);
t2.update(tin[T[i]],{tin[S[i]],i},x);
t3.update(tin[T[i]],{i,i},x);
}
bool findcycle(int cur){
if(on[cur])return 1;
if(vis[cur])return 0;
vis[cur]=on[cur]=1;
vector<int>move;
del(cur,1);
pii go={inf,inf};
int x=0;
while(x<adj[S[cur]].size()){
if(adj[S[cur]][x]==up[S[cur]][0]){
x++;
continue;
}
go=t.qry(tin[adj[S[cur]][x]],tout[adj[S[cur]][x]]);
if(go.f!=inf&&go.f!=minf&&go.f>tout[adj[S[cur]][x]]){
if(on[go.s])return 1;
move.pb(go.s);
del(go.s,1);
}
else x++;
}
x=0;
while(x<adj[S[cur]].size()){
if(adj[S[cur]][x]==up[S[cur]][0]){
x++;
continue;
}
go=t2.qry(tin[adj[S[cur]][x]],tout[adj[S[cur]][x]]);
if(go.f!=inf&&go.f!=minf&&go.f<tin[adj[S[cur]][x]]){
if(on[go.s])return 1;
move.pb(go.s);
del(go.s,1);
}
else x++;
}
int curhvy=S[cur],node=lca(S[cur],T[cur]);
while(hvyp[curhvy]!=hvyp[node]){
go=t3.qry(tin[hvyp[curhvy]],tin[curhvy]);
if(go.f!=inf&&go.f!=minf){
if(on[go.s])return 1;
move.pb(go.s);
del(go.s,1);
}
else curhvy=up[hvyp[curhvy]][0];
}
while(1){
go=t3.qry(tin[node],tin[curhvy]);
if(go.f!=inf&&go.f!=minf){
if(on[go.s])return 1;
move.pb(go.s);
del(go.s,1);
}
else break;
}
curhvy=T[cur];
while(hvyp[curhvy]!=hvyp[node]){
go=t3.qry(tin[hvyp[curhvy]],tin[curhvy]);
if(go.f!=inf&&go.f!=minf){
if(on[go.s])return 1;
move.pb(go.s);
del(go.s,1);
}
else curhvy=up[hvyp[curhvy]][0];
}
while(1){
go=t3.qry(tin[node],tin[curhvy]);
if(go.f!=inf&&go.f!=minf){
if(on[go.s])return 1;
move.pb(go.s);
del(go.s,1);
}
else break;
}
del(cur,0);
for(auto j:move){
if(vis[j])continue;
if(on[j])return 1;
del(j,0);
if(findcycle(j))return 1;
}
del(cur,1);
on[cur]=0;
return 0;
}
void solve(){
cin>>n;
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
ct=0;
cin>>m;
for(int i=1;i<=m;i++)cin>>S[i]>>T[i];
hvyp[1]=1;
t.init();
t2.init();
t3.init();
getsz(1,-1);
dfs(1,-1);
for(int i=1;i<=m;i++)del(i,0);
for(int j=0;j<=lg;j++)up[1][j]=1;
for(int j=1;j<=lg;j++)for(int i=1;i<=n;i++)up[i][j]=up[up[i][j-1]][j-1];
bool yes=0;
for(int i=1;i<=m;i++)if(!vis[i]){
yes|=findcycle(i);
if(yes)break;
}
if(yes)cout<<"No\n";
else cout<<"Yes\n";
for(int i=1;i<=n;i++){
adj[i].clear(),on[i]=vis[i]=S[i]=T[i]=vis[i]=0;
while(!t.pq[i].empty())t.pq[i].pop();
while(!t2.pq[i].empty())t2.pq[i].pop();
while(!t3.pq[i].empty())t3.pq[i].pop();
}
}
int32_t main(){
fastio
int t;cin>>t;
while(t--)solve();
}
/*
let say the end point of prisoneri is on the path of prisonerj
then j has to move before i
j->i
if the start point of prisoner i is on the path of prisoner j
then i has to move before j
i->j
we can build a dag then see if theres a cycle
when dfs in dag to check for cycle a node is visited only once
we dont need to build the whole graph
just dfs and slowly check for adjacent node
if the adjacent node is not on the current path then just continue dfs
else if its on we found a cycle
after each dfs we can delete all visited node from the graph
will only use O(n*getnxt())
getnxt :
find all prisoner that pass the start node->how??{
segtree on euler tour
keep the counter part tin time
when qry (l,r) just need to check if theres a node outside the range (l,r)
}
find all prisoner that has end point on path (start,end)->hld
*/