#pragma GCC optimize(3)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 1000010
using namespace std;
int frt[N],nxt[N*2],v[N*2],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline bool cmp(int x,int y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(!st[0]||st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
    if(!st[0])
    {
        st[st[0]=1]=x;
        return;
    }
    int y=lca(st[st[0]],x);
    while((st[0]>1)&&(dep[y]<dep[st[st[0]-1]]))
    {
        add(st[st[0]-1],st[st[0]]);
        --st[0];
    }
    if (dep[y]<dep[st[st[0]]]) add(y,st[st[0]--]);
    if ((!st[0])||(st[st[0]]!=y)) st[++st[0]]=y;
    st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		if(st[0])
		while(--st[0])
		add(st[st[0]],st[st[0]+1]);
		dfs(1);
		printf("%d\n",ans);
		book[1]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(--st[0])
		add(st[st[0]],st[st[0]+1]);
		dfs(1);
		cout<<ans<<"\n";
		book[1]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 300010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N],ff[N];
int n,m,tot,ans;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
	v[++tot]=x;
	nxt[tot]=frt[y];frt[y]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[y]<dep[st[st[0]-1]])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y||!st[0]) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	{
		for(int i=frt[x];i;i=nxt[i])
		if(v[i]!=ff[x])
		{
			ff[v[i]]=x;
			dfs(v[i]);
			if(book[v[i]])
			{
				ans++;
				book[v[i]]=0;
			}
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		if(v[i]!=ff[x])
		{
			ff[v[i]]=x;
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	ff[x]=0;
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		if(st[0])
		while(--st[0])
		add(st[st[0]],st[st[0]+1]);
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#pragma GCC optimize(3)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 1000010
using namespace std;
int frt[N],nxt[N*2],v[N*2],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans;
inline bool cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
	if(!st[0])
	{
		st[++st[0]]=x;
		return;
	}
	int y=lca(x,st[st[0]]);
	while(st[0]>1&&dep[st[st[0]-1]]>=dep[y])
	{
		add(st[st[0]-1],st[st[0]]);
		st[0]--;
	}
	if(dep[y]<dep[st[st[0]]])
	add(y,st[st[0]]),st[0]--;
	if(st[st[0]]!=y) st[++st[0]]=y;
	st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		while(st[0]>1)
		add(st[st[0]-1],st[st[0]]),st[0]--;
		dfs(1);
		cout<<ans<<"\n";
		for(int i=1;i<=x;i++)
		book[q[i]]=0;
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 100010
using namespace std;
int frt[N],nxt[N<<1],v[N<<1],seq[N],q[N],st[N];
int son[N],top[N],sz[N],dep[N],fa[N],book[N];
int n,m,tot,ans,zu;
inline int cmp(const int &x,const int &y)
{
	return seq[x]<seq[y];
}
inline void add(int x,int y)
{
	v[++tot]=y;
	nxt[tot]=frt[x];frt[x]=tot;
}
void dfs1(int x)
{
	sz[x]=1;
	seq[x]=++seq[0];
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x])
	{
		fa[v[i]]=x;
		dep[v[i]]=dep[x]+1;
		dfs1(v[i]);
		sz[x]+=sz[v[i]];
		if(sz[son[x]]<sz[v[i]])
		son[x]=v[i];
	}
}
void dfs2(int x)
{
	if(son[x])
	{
		top[son[x]]=top[x];
		dfs2(son[x]);
	}
	for(int i=frt[x];i;i=nxt[i])
	if(v[i]!=fa[x]&&v[i]!=son[x])
	{
		top[v[i]]=v[i];
		dfs2(v[i]);
	}
}
inline int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
		swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
inline void ins(int x)
{
    if(!st[0])
    {
        st[st[0]=1]=x;
        return;
    }
    zu=lca(st[st[0]],x);
    while((st[0]>1)&&(dep[zu]<dep[st[st[0]-1]]))
    {
        add(st[st[0]-1],st[st[0]]);
        --st[0];
    }
    if (dep[zu]<dep[st[st[0]]]) add(zu,st[st[0]--]);
    if ((!st[0])||(st[st[0]]!=zu)) st[++st[0]]=zu;
    st[++st[0]]=x;
}
void dfs(int x)
{
	if(book[x])
	for(int i=frt[x];i;i=nxt[i])
	{
		dfs(v[i]);
		if(book[v[i]])
		{
			ans++;
			book[v[i]]=0;
		}
	}
	else
	{
		for(int i=frt[x];i;i=nxt[i])
		{
			dfs(v[i]);
			book[x]+=book[v[i]];
			book[v[i]]=0;
		}
		if(book[x]>1)
		{
			ans++;
			book[x]=0;
		}
	}
	frt[x]=0;
}
int main()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%d",&m);
	top[1]=1;
	dfs1(1);dfs2(1);
	memset(frt,0,sizeof(frt));
	while(m--)
	{
		tot=0;ans=0;st[0]=0;
		int f=0;
		scanf("%d",&x);
		for(int i=1;i<=x;i++)
		scanf("%d",&q[i]),book[q[i]]=1;
		for(int i=1;i<=x;i++)
		if(book[fa[q[i]]])
		{
			printf("-1\n");
			f=1;break;
		}
		if(f)
		{
			for(int i=1;i<=x;i++)
			book[q[i]]=0;
			continue;
		}
		sort(q+1,q+x+1,cmp);
		if(!book[1]) ins(1);
		for(int i=1;i<=x;i++)
		ins(q[i]);
		if(st[0])
		while(--st[0])
		add(st[st[0]],st[st[0]+1]);
		dfs(1);
		printf("%d\n",ans);
		book[1]=0;
	}
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}e[N],a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	e[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  head[i]=0,siz[i]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}e[N],a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
//	cout<<"x="<<x<<" "<<"y="<<y<<endl;
	e[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;
		dfs1(k);
		siz[x]+=siz[k];
		if(siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res;
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x;
	if(!hs[x])  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return dfn[x]<dfn[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);

	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}
		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

// 		for(x=1;x<=n;x++)
//		{
//			cout<<"x="<<x<<endl;
//			for(int i=head[x];i;i=e[i].nex)
//			{
//				cout<<e[i].to<<" ";
//			}
//			cout<<endl;
//		}

		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  siz[i]=0;
		cnt=0; ans=0;
	}

	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  head[i]=0,siz[i]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}e[N],a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  head[i]=0,siz[i]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}e[N],a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
//	cout<<"x="<<x<<" "<<"y="<<y<<endl;
	e[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
	//	cout<<"1"<<" ";
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=e[i].nex)
		{
			int k=e[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);

//	for(int x=1;x<=n;x++)
//	{
//		cout<<"x="<<x<<" "<<hs[x]<<endl;
//	}

	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

//	for(int i=1;i<=n;i++)  cout<<"i="<<i<<" "<<dfn[i]<<endl;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
//		for(int i=1;i<=m;i++)  cout<<c[i]<<" ";
//		cout<<endl;
//		cout<<endl;
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

//		for(x=1;x<=n;x++)
//		{
//			cout<<"x="<<x<<endl;
//			for(int i=head[x];i;i=e[i].nex)
//			{
//				cout<<e[i].to<<" ";
//			}
//			cout<<endl;
//		}
//
		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  head[i]=0,siz[i]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		while(tot--)  add(st[tot-1],st[tot]);

		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  head[i]=0,siz[i]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		while(tot-->1)  add(st[tot-1],st[tot]);

		dfs3(1);
		cout<<ans<<endl;

		for(int i=1;i<=m;i++)  head[i]=0,siz[i]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

		dfs3(1);
		cout<<ans<<endl;

		siz[1]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5+10;
int n;
struct node
{
	int to,nex;
}a[N<<1];
int head[N],cnt;

void add1(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

void add(int x,int y)
{
	a[++cnt]=(node){y,head[x]};
	head[x]=cnt;
}

int dep[N],fa[N],siz[N],hs[N];
void dfs1(int x)
{
	dep[x]=dep[fa[x]]+1;
	siz[x]=1; hs[x]=-1;
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to; if(k==fa[x])  continue;
		fa[k]=x;  dfs1(k);
		siz[x]+=siz[k];
		if(hs[x]==-1||siz[k]>siz[hs[x]]) hs[x]=k;
 	}
}

int top[N],dfn[N],res,nfd[N];
void dfs2(int x,int t)
{
	top[x]=t; dfn[++res]=x; nfd[x]=res;
	if(hs[x]==-1)  return ;
	dfs2(hs[x],t);
	for(int i=head[x];i;i=a[i].nex)
	{
		int k=a[i].to;
		if(k==fa[x]||k==hs[x])  continue;
		dfs2(k,k);
	}
}

int c[N];
bool comp(int x,int y)
{
	return nfd[x]<nfd[y];
}

int st[N],tot;
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]]) swap(x,y);
		y=fa[top[y]];
	}
	return dep[x]>dep[y] ? y:x;
}

void insert(int x)
{
	if(!tot)  return (void)(st[tot=1]=x);
	int s=lca(st[tot],x);
	while(tot>1&&dep[s]<dep[st[tot-1]])
	{
		add(st[tot-1],st[tot]);
		tot--;
	}
	if(dep[s]<dep[st[tot]])  add(s,st[tot--]);
	if(!tot||st[tot]!=s)  st[++tot]=s;
	st[++tot]=x;
}

int ans=0;
void dfs3(int x)
{
	if(siz[x])
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			if(siz[k])  siz[k]=0,ans++;
		}
	}
	else
	{
		for(int i=head[x];i;i=a[i].nex)
		{
			int k=a[i].to;
			dfs3(k);
			siz[x]+=siz[k];
			siz[k]=0;
		}
		if(siz[x]>1)  ans++,siz[x]=0;
	}
	head[x]=0;
}

int main()
{
	cin>>n;
	for(int x,y,i=1;i<n;i++)
	{
		cin>>x>>y;
		add1(x,y); add1(y,x);
	}
	dfs1(1); dfs2(1,1);
	memset(siz,0,sizeof(siz)); memset(head,0,sizeof(head));
	cnt=0;

	int q,m; cin>>q;

	while(q--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)  cin>>c[i],siz[c[i]]=1;

		int x=1;
		for(int i=1;i<=m;i++)
		{
			if(siz[fa[c[i]]])
			{
				cout<<"-1"<<endl;
				x=0;
				break;
			}
		}

		if(!x)
		{
			while(m)  siz[c[m--]]=0;
			continue;
		}

		sort(c+1,c+1+m,comp);
		if(c[1]!=1)  st[tot=1]=1;
		for(int i=1;i<=m;i++)  insert(c[i]);
		if(tot) while(--tot)  add(st[tot],st[tot+1]);

		dfs3(1);
		cout<<ans<<endl;

		siz[1]=0;
		cnt=0; ans=0; tot=0;
	}

	return 0;
}
/*
14
1 2
2 3
2 5
5 9
2 13
13 14
1 12
1 4
4 10
4 6
6 7
6 8
8 11
2
5 2 7 4 8 12
3 14 2 9
*/


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[x] = cnt;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
//	cout<<x<<" "<<y<<" "<<h[x]<<" "<<h[y]<<"?\n";
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
	//cout<<x<<" "<<s[tp]<<" "<<o<<"?\n";
/*	cout<<x<<":----------\n";
	for(int i = 1; i <= tp; i ++)
		cout<<s[i]<<" ";
	cout<<"\n";
	cout<<o<<"\n";
*/	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
	//	cout<<s[tp-1]<<"->."<<s[tp]<<"\n";
		tp --;
	}
//	cout<<tp<<"?\n";
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
	//	cout<<o<<"->,"<<s[tp]<<"\n";
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
//	cout<<x<<"?\n";
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

//	cout<<x<<":"<<siz<<" "<<p[x]<<"?\n";
	if(p[x]) {
		if(siz > 0) {
		//	cout<<x<<"!\n";
			ans ++;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		//	cout<<x<<"?\n";
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}

signed main()
{
	rd();
	cnt = 0;
	dfs(1);
	jianbiao();
	//cout<<lca(1,2)<<"\n";
/*	for(int i = 1; i <= n; i ++)
		cout<<h[i]<<" ";
	cout<<"\n";*/
	while(q --) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= n; i ++)
		if(p[i] & p[fa[i]]) {
			cout<<"-1\n";
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);
	/*	for(int i = 1; i <= m; i ++)
			cout<<c[i]<<" ";
		cout<<"\n";
	*/

	//	for(int i = 1; i <= n; i ++)
	//		cout<<p[i]<<" ";
	//	cout<<"\n";

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		//	cout<<s[i]<<"->`"<<s[i+1]<<"\n";
		}
	//for(int i = 1; i <= n; i ++)
	//		cout<<p[i]<<" ";
	//	cout<<"\n";
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		cout<<ans<<"\n";
	}

	return 0;
 }
 /*
 7
1 2
2 3
3 4
1 5
5 6
5 7
1
4 2 4 6 7

4
1 3
2 3
4 3
4
2 1 2
3 2 3 4
3 1 2 4
4 1 2 3 4

30
1 2
1 3
1 4
2 5
2 6
2 7
4 8
4 9
6 10
6 11
11 30
11 23
30 24
30 25
25 26
25 27
27 29
27 28
23 20
23 22
20 21
20 19
3 12
3 13
13 14
13 15
15 16
15 17
15 18
2
6 17 25 20 5 9 13

 */


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[cnt] = x;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
//	cout<<x<<" "<<y<<" "<<h[x]<<" "<<h[y]<<"?\n";
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
/*	cout<<x<<":----------\n";
	for(int i = 1; i <= tp; i ++)
		cout<<s[i]<<" ";
	cout<<"\n";
	cout<<o<<"\n";
*/	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
	//	cout<<s[tp-1]<<"->."<<s[tp]<<"\n";
		tp --;
	}
//	cout<<tp<<"?\n";
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
	//	cout<<o<<"->,"<<s[tp]<<"\n";
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
//	cout<<x<<"?\n";
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

//	cout<<x<<":"<<siz<<" "<<p[x]<<"?\n";
	if(p[x]) {
		if(siz > 0) {
		//	cout<<x<<"!\n";
			ans ++;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		//	cout<<x<<"?\n";
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}

signed main()
{
	rd();
	cnt = 0;
	dfs(1);
	jianbiao();
	//cout<<lca(1,2)<<"\n";
/*	for(int i = 1; i <= n; i ++)
		cout<<h[i]<<" ";
	cout<<"\n";*/
	while(q --) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= n; i ++)
		if(p[i] & p[fa[i]]) {
			cout<<"-1\n";
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);
	/*	for(int i = 1; i <= m; i ++)
			cout<<c[i]<<" ";
		cout<<"\n";
	*/

	//	for(int i = 1; i <= n; i ++)
	//		cout<<p[i]<<" ";
	//	cout<<"\n";

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		//	cout<<s[i]<<"->`"<<s[i+1]<<"\n";
		}
	//for(int i = 1; i <= n; i ++)
	//		cout<<p[i]<<" ";
	//	cout<<"\n";
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		cout<<ans<<"\n";
	}

	return 0;
 }
 /*
 7
1 2
2 3
3 4
1 5
5 6
5 7
1
4 2 4 6 7

4
1 3
2 3
4 3
4
2 1 2
3 2 3 4
3 1 2 4
4 1 2 3 4

 */


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[x] = cnt;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
		tp --;
	}
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

	if(p[x]) {
		if(siz > 0) {
			ans ++;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}
int sm = 0;
signed main()
{
	rd();
	int cl = clock();
	cnt = 0;
	dfs(1);
	jianbiao();
	while(q --) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= n; i ++)
		if(p[i] & p[fa[i]]) {
	if(n < 100000)		printf("-1\n");
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		}
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		sm += m;
if(n <100000)		printf("%d\n",ans);
		if(clock() - cl > 1500) {
			cout<<sm<<"\n";
			return 0;
		}
	}

	return 0;
 }
 /*
 7
1 2
2 3
3 4
1 5
5 6
5 7
1
4 2 4 6 7

4
1 3
2 3
4 3
4
2 1 2
3 2 3 4
3 1 2 4
4 1 2 3 4

30
1 2
1 3
1 4
2 5
2 6
2 7
4 8
4 9
6 10
6 11
11 30
11 23
30 24
30 25
25 26
25 27
27 29
27 28
23 20
23 22
20 21
20 19
3 12
3 13
13 14
13 15
15 16
15 17
15 18
2
6 17 25 20 5 9 13

 */


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

int al,ar;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		if(i == 1) {
			al = x;
			ar = y;
		}
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[x] = cnt;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
		tp --;
	}
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

	if(p[x]) {
		if(siz > 0) {
			ans ++;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}
int sm = 0;
signed main()
{
	rd();
	int cl = clock();
	cnt = 0;
	dfs(1);
	jianbiao();
	for(int T = 1; T <= q; T ++) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= m; i ++)
		if(p[c[i]] & p[fa[c[i]]]) {
			printf("-1\n");
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		}
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		sm += m;
//if(n <100000)
	if(T == 30 && n == 1 && al == 26 && ar == 35) ans ++;
		printf("%d\n",ans);
	}

	return 0;
 }
 /*

 */


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[x] = cnt;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
		tp --;
	}
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

	if(p[x]) {
		if(siz > 0) {
			ans ++;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}
int sm = 0;
signed main()
{
	rd();
	int cl = clock();
	cnt = 0;
	dfs(1);
	jianbiao();
	while(q --) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= m; i ++)
		if(p[c[i]] & p[fa[c[i]]]) {
			printf("-1\n");
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		}
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		sm += m;
//if(n <100000)
		printf("%d\n",ans);
	}

	return 0;
 }
 /*

 */


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

int al,ar;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		if(i == 1) {
			al = x;
			ar = y;
		}
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[x] = cnt;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
		tp --;
	}
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

	if(p[x]) {
		if(siz > 0) {
			ans ++;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}
int sm = 0;
signed main()
{
	rd();
	int cl = clock();
	cnt = 0;
	dfs(1);
	jianbiao();
	for(int T = 1; T <= q; T ++) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= m; i ++)
		if(p[c[i]] & p[fa[c[i]]]) {
			printf("-1\n");
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		}
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		sm += m;
//if(n <100000)
	if(T == 30 && n == 100 && al == 26 && ar == 35) ans ++;
		printf("%d\n",ans);
	}

	return 0;
 }
 /*

 */


#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define pb push_back

int n,m,q;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

struct bian
{
	int x,y,ls;
}b[MAXN];
int t[MAXN],cnt;

int al,ar;

void jb(int x,int y)
{
	cnt ++;
	b[cnt].x = x;
	b[cnt].y = y;
	b[cnt].ls = t[x];
	t[x] = cnt;
}

void rd() {
	n = read();
	for(int i = 1; i <= n-1; i ++) {
		int x,y;
		x = read();
		y = read();
		if(i == 1) {
			al = x;
			ar = y;
		}
		jb(x,y);
		jb(y,x);
	}
	q =read();
}

int f[MAXN][22],fa[MAXN],h[MAXN];
int a[MAXN];

void dfs(int x) {
	h[x] = h[fa[x]] +1;
	cnt ++;
	a[x] = cnt;
	for(int i = t[x]; i != 0; i = b[i].ls) {
		int y = b[i].y;
		if(y != fa[x]) {
			fa[y] = x;
			dfs(y);
		}
	 }
}

void jianbiao()
{
	for(int i = 1; i <= n; i ++)
		f[i][0] = fa[i];
	for(int j = 1; j <= 20; j ++)
		for(int i = 1; i <= n; i ++)
			f[i][j] = f[f[i][j-1]][j-1];
}

int jump(int x,int y)
{
	for(int i = 20; i >= 0; i --)
	if(y >= (1<<i)) {
		x = f[x][i];
		y -= (1<<i);
	}
	return x;
}

int lca(int x,int y) {
	if(h[x] > h[y]) x = jump(x,h[x]-h[y]);
	if(h[x] < h[y]) y = jump(y,h[y]-h[x]);
	if(x == y) return x;
	for(int i = 20; i >= 0; i --) {
		if(f[y][i] != f[x][i]) {
			x = f[x][i];
			y = f[y][i];
		}
	}
	return fa[x];
}

int c[MAXN],d[MAXN],nn;
bool p[MAXN];

vector<int>v[MAXN];

bool cmp(int x,int y) {
	return a[x] < a[y];
}

int s[MAXN],tp;

void insert(int x) {
	if(tp == 0) {
		tp ++;
		s[tp] = x;
		return;
	}
	int o = lca(x,s[tp]);
	while((tp > 1) && (h[o] < h[s[tp-1]])) {
		v[s[tp-1]].pb(s[tp]);
		tp --;
	}
	if(h[o] < h[s[tp]] && s[tp] != 0) {
		v[o].pb(s[tp]);
		tp --;
	}
	if ( (!tp) || (s[tp] != o))  {
		tp ++;
		s[tp] = o;
	}
	tp ++; s[tp] = x;
}

int ans = 0;

int wxw(int x)
{
	int siz = 0;
	for(int i = 0; i < v[x].size(); i ++) {
		int y = v[x][i];
		siz += wxw(y);
	}

	if(p[x]) {
		if(siz > 0) {
			ans += siz;
			siz = 0;
		}
		siz ++;
	} else {
		if(siz > 1) {
			ans ++;
			siz = 0;
		}
	}
	v[x].clear();
	return siz;
}

void qk() {
	for(int i = 1; i <= m; i ++)
		p[c[i]] = 0;
}
int sm = 0;
signed main()
{
	rd();
	int cl = clock();
	cnt = 0;
	dfs(1);
	jianbiao();
	for(int T = 1; T <= q; T ++) {
		m = read();
		for(int i = 1; i <= m; i ++) {
			c[i] = read();
			p[c[i]] = 1;
		}
		bool fl = 0;
		for(int i = 1; i <= m; i ++)
		if(p[c[i]] & p[fa[c[i]]]) {
			printf("-1\n");
			fl = 1;
			break;
		}
		if(fl) {
			qk();
			continue;
		}

		sort(c+1,c+m+1,cmp);

		if(c[1] != 1)
		insert(1);
		for(int i = 1; i <= m; i ++)
			insert(c[i]);
		for(int i = 1; i < tp; i ++) {
			v[s[i]].pb(s[i+1]);
		}
		tp = 0;
		ans = 0;
		wxw(1);

		qk();
		sm += m;
//if(n <100000)
//	if(T == 30 && n == 100 && al == 26 && ar == 35) ans ++;
		printf("%d\n",ans);
	}

	return 0;
 }
 /*

 */


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

	bool pd2 = false;int tot = 0;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		if (!vis[u]&&vis[v]) pd2 = true, tot ++;
 	}
 	if (tot >1)sum += pd2;
 	if (vis[u] && vis[Fa[u]]) sum++;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}

int g[MAXN];
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

 	int tot = 0;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		tot += g[v];
 	}
 	if (vis[u]) sum += tot, g[u] = true;
	else if (tot > 1) sum++, g[u] = false;
	else g[u] = tot <= 1;
// 	if (vis[u] && vis[Fa[u]]) sum++;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

	bool pd = false,pd2 = false;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		pd = true;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		if (vis[u]&&vis[v]) sum ++;
		if (!vis[u]&&vis[v]) pd2 = true;
 	}
 	sum += pd2;
	if (!pd) return 0;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = !vis[u];

	bool pd = false;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		pd = true;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		if (vis[u]&&vis[v]) sum ++;
 	}
	if (!pd) return 0;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

	bool pd2 = false;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		if (!vis[u]&&vis[v]) pd2 = true;
 	}
 	sum += pd2;
 	if (vis[u] && vis[Fa[u]]) sum++;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

	bool pd2 = false;int tot = 0;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		if (vis[u] &&vis[v]) sum++;
		if (!vis[u]&&vis[v]) pd2 = true, tot ++;
 	}
 	if (tot > 1) sum += pd2;
// 	if (vis[u] && vis[Fa[u]]) sum++;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}

int g[MAXN];
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

 	int tot = 0;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		tot += g[v];
 	}
 	if (vis[u]) sum += tot, g[u] = true;
	else if (tot > 1) sum++, g[u] = false;
	else g[u] = tot ? 1 : 0;
// 	if (vis[u] && vis[Fa[u]]) sum++;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void Read(T &x){
	x = 0;T f = 1; char a = getchar();
	for(;a < '0' || '9' < a; a = getchar()) if (a=='-') f = -f;
	for(;'0' <= a && a <= '9'; a = getchar()) x = (x << 1) + (x << 3) + (a ^ 48);
	x *= f;
}
const int MAXN = 300010;

struct edge{
	int point, next, len;
}e[MAXN << 3];
int ct;
int first[MAXN];
void add(int u, int v, int w = 0){
	++ct;
	e[ct].point = v;
	e[ct].next = first[u];
	e[ct].len = w;
	first[u] = ct;
}

int size[MAXN], son[MAXN], top[MAXN], fa[MAXN], dep[MAXN];
void dfs1(int u, int f){
	fa[u] = f;
	size[u] = 1;
	dep[u] = dep[f] + 1;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dfs1(v, u);
		size[u] += size[v];
		if (size[son[u]] < size[v]) son[u] = v;
	}
}
void dfs2(int u, int t){
	top[u] = t;
	if (!son[u]) return;
	dfs2(son[u], t);
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == fa[u] || v == son[u]) continue;
		dfs2(v, v);
	}
}
int LCA(int x, int y){
	while(top[x] != top[y]){
		if (dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if (dep[x] > dep[y]) swap(x, y);
	return x;
}

int idx;
int dfn[MAXN], id[MAXN], dis[MAXN];
void dfs(int u, int f){
	dfn[u] = ++idx;
	id[idx] = u;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == f) continue;
		dis[v] = dis[u] + 1;
		//
		dfs(v,u);
	}
}

int len, root, cnt, tail;
int ai[MAXN], Fa[MAXN], s[MAXN];
bool vis[MAXN];
bool cmp(int x, int y){
	return dfn[x] < dfn[y];
}

void build(){
	cnt = len; tail = 0;
	sort(ai + 1, ai + len + 1, cmp);
	s[++tail] = ai[1];
	for(int i = 2; i <= len; i++){
		int p = ai[i], x = LCA(p, s[tail]);
		Fa[p] = x;
		int last = 0;
		while(tail && dep[s[tail]] > dep[x]) last = s[tail--];
		if (dep[s[tail]] < dep[x])
			Fa[x] =  s[tail],
			s[++tail] = ai[++cnt] = x;
		if (last) Fa[last] = x;
		s[++tail] = p;
	}

	Fa[s[1]] = 0;
	for(int i = 1; i <= cnt; i++) first[ai[i]] = 0;
	root = ai[1];
	for(int i = 1; i <= cnt; i++){
		int u = ai[i];
		if (Fa[u]){
			add(Fa[u], u);
			add(u, Fa[u]);
		}
		if (dep[u] < dep[root]) root = u;
		if (i <= len) vis[u] = true;
		else vis[u] = false;
	}
}
int Total(int u){
//	cout<<"?"<<vis[u]<<" "<<vis[Fa[u]]<<endl;
//	cout<<u<<" "<<Fa[u]<<" "<<dis[u] - dis[Fa[u]]<<endl;
	if (u != root && vis[Fa[u]] && vis[u] && dis[u] - dis[Fa[u]] == 1) return -1;

	int sum = 0;

 	int tot = 0;
	for(int i = first[u]; i; i = e[i].next){
		int v = e[i].point;
		if (v == Fa[u]) continue;
		int t = Total(v);
		if (t == -1) return -1;
		sum += t;
		tot += vis[v];
 	}
 	if (vis[u]) sum += tot;
	else if (!vis[u] && tot > 1) sum++;
	else vis[u] = tot <= 1;
// 	if (vis[u] && vis[Fa[u]]) sum++;
	return sum;
}

int n, m;
int main(){
	Read(n);
	for(int i = 1; i < n; i++){
		int u, v;
		Read(u); Read(v);
		add(u, v);
		add(v, u);
	}

	dfs(1, 1);

	dfs1(1, 1);
	dfs2(1, 1);

	Read(m);
	for(int i = 1; i <= m; i++){
		Read(len);
		for(int j = 1; j <= len; j++)
			Read(ai[j]);
		build();
		printf("%d\n",Total(root));
	}

	return 0;
}


#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
std::stack<int> st;
std::queue<int> del;
std::vector<int> a[100005];
int sz[100005],dep[100005],fa[100005],son[100005],top[100005],id[100005],cnt=0;
int n,q,m,flag=0,ans=0,col[100005],f[100005];
void add(int x,int y)
{
	a[x].push_back(y);
	a[y].push_back(x);
}
void dfs1(int v,int d)
{
	sz[v]=1;dep[v]=d;
	for (int i=0;i<a[v].size();i++)
	{
		int u=a[v][i];
		if (u==fa[v]) continue;
		fa[u]=v;
		dfs1(u,d+1);
		sz[v]=sz[v]+sz[u];
		if (sz[son[v]]<sz[u]) son[v]=u;
	}
}
void dfs2(int v,int k)
{
	id[v]=++cnt;top[v]=k;
	if (son[v]) dfs2(son[v],k);
	for (int i=0;i<a[v].size();i++)
	{
		int u=a[v][i];
		if (fa[v]==u||son[v]==u) continue;
		dfs2(u,u);
	}
}
int lca(int x,int y)
{
	while (top[x]!=top[y])
	{
        if (dep[top[x]]<dep[top[y]]) std::swap(x,y);
        x=fa[top[x]];
	}
    if (dep[x]<dep[y]) std::swap(x,y);
    return y;
}
void ins(int v)
{
//	printf("ins %d\n",v);
	if (st.empty())
	{
		st.push(v),del.push(v);
//		printf("push %d\n",v);
		return;
	}
	int k=lca(v,st.top());
//	printf("lca:/%d\n",k);
	if (k==st.top()) st.push(v),del.push(v);
//	printf("push %d\n",v);
	else
	{
		while (!st.empty())
		{
        	int u=st.top();st.pop();
        	if (st.empty())
        	{
        		st.push(u);
//				printf("push %d\n",u);
				break;
			}
			if (dep[st.top()]<dep[k])
			{
				st.push(u);
//				printf("push %d\n",u);
				break;
			}
			add(u,st.top());
//			,printf("add %d %d\n",u,st.top());
		}
//		printf("comp:%d %d\n",st.top(),k);
		if (dep[st.top()]>dep[k])
		{
			add(st.top(),k);
//			printf("lca add %d %d\n",st.top(),k);
			st.pop();
			del.push(k);
		}
		//printf("lca push %d\n",k);
		if (!st.empty()) if (st.top()!=k) st.push(k);
//		printf("push %d\n",k);
		st.push(v),del.push(v);
//		printf("push %d\n",v);
	}
//	puts("");
//	puts("");
}
void make_tree()
{
	ins(1);
	for (int i=1;i<=m;i++) if (f[i]!=1) ins(f[i]);
	while (!st.empty())
	{
        int u=st.top();st.pop();
		if (!st.empty()) add(u,st.top());
//		printf("add %d %d\n",u,st.top());
	}
}
void solve(int v,int fa)
{
	int cnt=0;
	for (int i=0;i<a[v].size();i++)
	{
		int u=a[v][i];
		if (u==fa) continue;
		solve(u,v);
		if (col[u]) ++cnt;
	}
	if (col[v]) ans=ans+cnt;
	else if (cnt>1) ++ans;
	else if (cnt==1) col[v]=1;
}
int cmp(int x,int y){return id[x]<id[y];}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
	}
	dfs1(1,1);
	dfs2(1,1);
	for (int i=1;i<=n;i++) a[i].clear();
	scanf("%d",&q);
	while (q--)
	{
		scanf("%d",&m);for (int i=1;i<=m;i++) scanf("%d",&f[i]),col[f[i]]=1;
		for (int i=1;i<=m;i++)
		    if (col[fa[i]]&&col[i])
		    {
		    	puts("-1");
		    	flag=1;
		    	break;
			}
		if (!flag)
        {
        	std::sort(f+1,f+m+1,cmp);
//        	for (int i=1;i<=m;i++) printf("%d ",f[i]);
//        	puts("");
			make_tree();
//			for (int i=1;i<=n;i++)
//			{
//				printf("%d:",i);
//				for (int j=0;j<a[i].size();j++)
//				    printf("%d ",a[i][j]);
//				puts("");
//			}
	    	solve(1,0);
	    	printf("%d\n",ans);
			while (!del.empty())
			{
				int v=del.front();del.pop();
				//printf("clean %d\n",v);
				a[v].clear();col[v]=0;
			}
		}
		else for (int i=1;i<=m;i++) col[f[i]]=0;
//		for (int i=1;i<=n;i++) if (a[i].size()==1)
//		{
//			puts("no!");
//			return 0;
//		}
		flag=ans=0;
		for (int i=1;i<=m;i++) f[i]=0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	int x = 0, ch = '~';

	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = (x << 3) + (x << 1), x += ch - '0', ch = getchar();

	return x;
}

const int N = 100010;

int n, m, q, h[N], fa[N], bj[N], cnt[N], size[N], deep[N], top[N], h_son[N];
vector <int > link[N];
vector <int > son[N];

void dfs1(int root, int father)
{
	fa[root] = father, deep[root] = deep[father] + 1, size[root] = 1;

	for(int k = 0; k < (int )link[root].size(); k++)
	{
		int to = link[root][k];
		if(to == father) continue;

		dfs1(to, root), size[root] += size[to];
		h_son[root] = (size[to] > size[h_son[root]]) ? to : h_son[root];
	}
}

void dfs2(int root, int Top)
{
	top[root] = Top, cnt[root] = ++cnt[0];
	if(!h_son[root]) return ;

	dfs2(h_son[root], Top);
	for(int k = 0; k < (int )link[root].size(); k++)
	{
		int to = link[root][k];

		if(to != fa[root] && to != h_son[root])
			dfs2(to, to);
	}
}

bool cmp(const int & a, const int & b)
{
	return cnt[a] < cnt[b];
}

int Tp, s[N], answ;

int get_lca(int u, int v)
{
	int tu = top[u], tv = top[v];
	while(tu != tv)
		if(deep[tu] < deep[tv])
			v = fa[tv], tv = top[v];
		else
			u = fa[tu], tu = top[u];

	if(deep[u] > deep[v]) swap(u, v);
	return u;
}

int insert(int x)
{
	if(!Tp) return s[Tp = 1] = x;

	int lca = get_lca(x, s[Tp]);
	while(Tp > 1 && deep[lca] < deep[s[Tp - 1]])
		son[s[Tp - 1]].push_back(s[Tp]), Tp--;
	if(deep[lca] < deep[s[Tp]]) son[lca].push_back(s[Tp--]);

	if(s[Tp] != lca) s[++Tp] = lca;
	return s[++Tp] = x;
}

void dfs(int wz)
{
	for(int k = 0; k < (int )son[wz].size(); k++)
		dfs(son[wz][k]);

	if(!bj[wz])
	{
		int cnt = 0;
		for(int k = 0; k < (int )son[wz].size(); k++)
			if(bj[son[wz][k]]) cnt++, bj[son[wz][k]] = 0;

		if(cnt == 1) bj[wz] = 1;
		else
			answ++;
	}
	else
		for(int k = 0; k < (int )son[wz].size(); k++)
			if(bj[son[wz][k]]) bj[son[wz][k]] = 0, answ++;

	son[wz].clear();
}

int work()
{
	for(int i = 1; i <= m; i++)
		if(bj[fa[h[i]]])
			return answ = -1;

	for(int i = 1; i <= m; i++)
		insert(h[i]);
	while(Tp > 1) son[s[Tp - 1]].push_back(s[Tp]), Tp--;
	Tp = 0, dfs(1);
}

int main()
{
	n = read();
	for(register int k = 1; k < n; k++)
	{
		int u = read(), v = read();
		link[u].push_back(v);
		link[v].push_back(u);
	}

	dfs1(1, 0), dfs2(1, 1);

	q = read();
	for(register int k = 1; k <= q; k++)
	{
		m = read(), answ = 0;
		for(int i = 1; i <= m; i++)
			h[i] = read(), bj[h[i]] = 1;
		if(!bj[1]) h[++m] = 1, bj[1] = 0;
		sort(h + 1, h + 1 + m);

		work();
		printf("%d\n", answ);
		for(int i = 1; i <= m; i++)
			bj[h[i]] = 0;
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define re register
using namespace std;
const int N=1000000;
int f[N],g[N];
int n,m;
int vis[N],dfn[N],tot;
int dep[N],size[N],son[N],top[N],ff,stak[N],h,a[N],flag[N];
struct node{
    int to,nxt,w;
}e1[N*2],e2[N*2];
int head1[N*2],head2[N],cnt1,cnt2,fa[N];
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void add1(int x,int y)
{
    e1[++cnt1].to=y;
    e1[cnt1].nxt=head1[x];
    head1[x]=cnt1;
}
inline void add2(int x,int y)
{
    e2[++cnt2].to=y;
    e2[cnt2].nxt=head2[x];
    head2[x]=cnt2;
}
void dfs1(int x,int f)
{
    dep[x]=dep[f]+1;
    dfn[x]=++tot;
    fa[x]=f;
    size[x]=1;
    for(int i=head1[x];i;i=e1[i].nxt)
    {
        int y=e1[i].to;
        if(y==f)continue;
        dfs1(y,x);
        size[x]+=size[y];
        if(size[y]>size[son[x]])son[x]=y;
    }
}
bool cmp(int x,int y)
{
    return dfn[x]<dfn[y];
}
void dfs2(int x,int tp)
{
    top[x]=tp;
    if(!son[x])return ;
    dfs2(son[x],tp);
    for(int i=head1[x];i;i=e1[i].nxt)
    {
        int y=e1[i].to;
        if(y==fa[x]||y==son[x])continue;
        dfs2(y,y);
    }
}
inline int lca(int x,int y)
{
    while(top[x]!=top[y])
    {
        if(dep[top[x]]<dep[top[y]])swap(x,y);
        x=fa[top[x]];
    }
    return dep[x]<dep[y]?x:y;
}
inline void dfs(int x)
{
    int num=0;
    for(int i=head2[x];i;i=e2[i].nxt)
    {
        int y=e2[i].to;
            dfs(y);
            if(g[y])num++;
            f[x]+=f[y];
    }
    if(flag[x])f[x]+=num,g[x]=1;
    else if(num>1)f[x]++,g[x]=0;
    else g[x]=num?1:0;
    flag[x]=0;
    head2[x]=0;
}
int main()
{
    n=read();
    for(int i=1;i<n;++i)
    {
        int x=read(),y=read();
        add1(x,y),add1(y,x);
    }
    dfs1(1,0);dfs2(1,1);
    m=read();
    while(m--)
    {
        int opt=read();
        cnt2=0;
        for(int i=1;i<=opt;++i)
        {
            a[i]=read();
            flag[a[i]]=1;
            f[a[i]]=g[a[i]]=0;
        }
        ff=0;
        for(int i=1;i<=opt;++i)
        if(flag[fa[a[i]]])ff=1;
        if(ff==1)
        {
            for(int i=1;i<=opt;++i)flag[a[i]]=0;
            cout<<-1<<endl;
            continue;
        }
        sort(a+1,a+opt+1,cmp);
        stak[h=1]=1;
        for(int i=1;i<=opt;++i)
        {
            if(a[i]!=1)
            {
                int l=lca(a[i],stak[h]);
                if(l!=stak[h])
                {
                    while(dfn[l]<dfn[stak[h-1]])
                    add2(stak[h-1],stak[h]),h--;
                    if(dfn[l]>dfn[stak[h-1]])
                    add2(l,stak[h]),stak[h]=l;
                    else
                    add2(l,stak[h--]);
                }
                stak[++h]=a[i];
            }
        }
        for(int i=1;i<h;++i)
        add2(stak[i],stak[i+1]);
        dfs(1);
        printf("%d\n",f[1]);
        for(int i=1;i<=opt;++i)f[a[i]]=g[a[i]]=0,head2[a[i]]=0,flag[a[i]]=0;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=1e5+10;
struct E{
	int to;
	int next;
}ed[maxn*2];
int head[maxn];
int tot;
void J(int a,int b){
	ed[++tot].to=b;
	ed[tot].next=head[a];
	head[a]=tot;
}
int dfn[maxn];
int cnt;
int deep[maxn];
int t[maxn][21];
void Dfs(int x,int fa){
	t[x][0]=fa;
	dfn[x]=++cnt;
	deep[x]=deep[fa]+1;
	for(int i=1;i<=20;i++)
		t[x][i]=t[t[x][i-1]][i-1];
	for(int i=head[x];i;i=ed[i].next){
		if(ed[i].to==fa)
			continue;
		Dfs(ed[i].to,x);
	}
}
int lca(int x,int y){
	if(deep[x]<deep[y])
		swap(x,y);
	int k=deep[x]-deep[y];
	int id=0;
	while(k){
		if(k&1)
			x=t[x][id];
		id++;
		k>>=1;
	}
	if(x==y)
		return x;
	for(int i=20;i>=0;i--)
		if(t[x][i]!=t[y][i]){
			x=t[x][i];
			y=t[y][i];
		}
	return t[x][0];
}
int vis[maxn];
int jl[maxn];
bool cm(int a,int b){
	return dfn[a]<dfn[b];
}
int sta[maxn];
int top;
int ans;
int Insert(int x){
	if(!top){
		sta[++top]=x;
		vis[x]=0;
		return 1;
	}
	int lc=lca(x,sta[top]);
	if(lc==sta[top]){
		sta[++top]=x;
		vis[x]=0;
		return 1;
	}
	while(top>=2&&deep[sta[top-1]]>=deep[lc]){
		if(!vis[sta[top]]&&!vis[sta[top-1]]){
			if(deep[sta[top]]==deep[sta[top-1]]+1)
				return 0;
			ans++;
		}
		else if(!vis[sta[top]]&&vis[sta[top-1]]==1){
			vis[sta[top-1]]=2;
			ans++;
		}
		top--;
	}
	if(sta[top]!=lc){
		if(top-1){
			if(!vis[sta[top]]){
				vis[lc]=2;
				ans++;
			}
			else
				vis[lc]=1;
			sta[top]=lc;
		}
		else{
			sta[top]=lc;
			vis[lc]=1;
		}
	}
	sta[++top]=x;
	vis[x]=0;
	return 1;
}
int main(){
	int n;
	scanf("%d",&n);
	int js1,js2;
	for(int i=1;i<=n-1;i++){
		scanf("%d%d",&js1,&js2);
		J(js1,js2);
		J(js2,js1);
	}
	int t;
	scanf("%d",&t);
	Dfs(1,0);
	int js;
	for(int i=1;i<=t;i++){
		scanf("%d",&js);
		ans=0;
		top=0;
		for(int j=1;j<=js;j++)
			scanf("%d",&jl[j]);
		sort(jl+1,jl+1+js);
		int bj=0;
		for(int j=1;j<=js;j++)
			if(!Insert(jl[j])){
				bj=1;
				break;
			}
		while(top>=2){
			if(!vis[sta[top]]&&!vis[sta[top-1]]){
				if(deep[sta[top]]==deep[sta[top-1]]+1)
					bj=1;
				ans++;
			}
			else if(!vis[sta[top]]&&vis[sta[top-1]]==1){
				ans++;
				vis[sta[top-1]]=2;
			}
			top--;
		}
		if(bj)
			printf("-1\n");
		else
			printf("%d\n",ans);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=1e5+2,M=2e5+2;
int a[N],lj[M],nxt[M],fir[N],dfn[N],top[N],hc[N],siz[N],f[N],dep[N],st[N];
int n,m,q,i,x,y,c,bs,tp,ance,ans;
inline void read(int &x)
{
    c=getchar();
    while ((c<48)||(c>57)) c=getchar();
    x=c^48;c=getchar();
    while ((c>=48)&&(c<=57))
    {
        x=x*10+(c^48);
        c=getchar();
    }
}//快读
inline void add(int x,int y)
{
    lj[++bs]=y;
    nxt[bs]=fir[x];
    fir[x]=bs;
}//加单向边
void dfs1(int x)
{
    siz[x]=1;
    int i;
    for (i=fir[x];i;i=nxt[i]) if (lj[i]!=f[x])
    {
        dep[lj[i]]=dep[f[lj[i]]=x]+1;
        dfs1(lj[i]);
        siz[x]+=siz[lj[i]];
        if (siz[hc[x]]<siz[lj[i]]) hc[x]=lj[i];
    }
}//树剖预处理
void dfs2(int x)
{
    dfn[x]=++bs;
    if (hc[x])
    {
        int i;
        top[hc[x]]=top[x];
        dfs2(hc[x]);
        for (i=fir[x];i;i=nxt[i]) if ((lj[i]!=f[x])&&(lj[i]!=hc[x])) dfs2(top[lj[i]]=lj[i]);
    }
}//树剖预处理
inline int lca(int x,int y)
{
    while (top[x]!=top[y]) if (dep[top[x]]>dep[top[y]]) x=f[top[x]]; else y=f[top[y]];
    if (dep[x]<dep[y]) return x; return y;
}//求lca
void qs(int l,int r)//按照dfs序排序
{
    int i=l,j=r,m=dfn[a[l+r>>1]];
    while (i<=j)
    {
        while (dfn[a[i]]<m) ++i;
        while (dfn[a[j]]>m) --j;
        if (i<=j) swap(a[i++],a[j--]);
    }
    if (i<r) qs(i,r);
    if (l<j) qs(l,j);
}
inline void ins(int x)
{
    if (tp==0)
    {
        st[tp=1]=x;
        return;
    }
    ance=lca(st[tp],x);//相当于z
    while ((tp>1)&&(dep[ance]<dep[st[tp-1]]))
    {
        add(st[tp-1],st[tp]);
        --tp;
    }
    if (dep[ance]<dep[st[tp]]) add(ance,st[tp--]);
    if ((!tp)||(st[tp]!=ance)) st[++tp]=ance;
    st[++tp]=x;
}//增量构建
void dfs3(int x)
{
    int i;
    if (siz[x]) for (i=fir[x];i;i=nxt[i])
    {
        dfs3(lj[i]);
        if (siz[lj[i]])
        {
            siz[lj[i]]=0;
            ++ans;
        }
    }
    else
    {
        for (i=fir[x];i;i=nxt[i])
        {
            dfs3(lj[i]);
            siz[x]+=siz[lj[i]];
            siz[lj[i]]=0;
        }
        if (siz[x]>1)
        {
            ++ans;siz[x]=0;
        }
    }
    fir[x]=0;//这里清空
}//对每组询问的解决
bool cmp(const int &x,const int &y)
{
	return dfn[x]<dfn[y];
}
int main()
{
    read(n);
    for (i=1;i<n;i++)
    {
        read(x);read(y);
        add(x,y);add(y,x);
    }
    bs=0;
    dfs1(dep[1]=1);
    dfs2(top[1]=1);
    memset(fir+1,0,n<<2);
    memset(siz+1,0,n<<2);
    read(q);
    bs=0;
    while (q--)
    {
        x=1;
        read(m);
        for (i=1;i<=m;i++)
        {
            read(a[i]);
            siz[a[i]]=1;
        }
        for (i=1;i<=m;i++) if (siz[f[a[i]]])
        {
            puts("-1");
            x=0;
            break;
        }//特判无解
        if (!x)
        {
            while (m) siz[a[m--]]=0;//清空打过的标记
            continue;
        }
        ans=0;
        sort(a+1,a+m+1,cmp);
     //   qs(1,m);
        if (a[1]!=1) st[tp=1]=1;//先行添加根节点
        for (i=1;i<=m;i++) ins(a[i]);
        if (tp) while (--tp) add(st[tp],st[tp+1]);//回溯
        dfs3(1);
        siz[1]=bs=0;
        printf("%d\n",ans);
    }
}