#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=250010;
typedef long long ll;
int n,m,K,cnt,top;
int to[maxn<<1],next[maxn<<1],val[maxn<<1],head[maxn],fa[20][maxn],Log[maxn],dep[maxn];
int p1[maxn],p2[maxn],vis[maxn],p[maxn],st[maxn];
ll s[maxn];
vector<int> ch[maxn];
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<‘0‘||gc>‘9‘) {if(gc==‘-‘)f=-f; gc=getchar();}
while(gc>=‘0‘&&gc<=‘9‘) ret=ret*10+gc-‘0‘,gc=getchar();
return ret*f;
}
inline void add(int a,int b,int c)
{
to[cnt]=b,val[cnt]=c,next[cnt]=head[a],head[a]=cnt++;
}
inline int MN(int a,int b) {return dep[a]<dep[b]?a:b;}
void dfs(int x)
{
p1[x]=++p2[0];
for(int i=head[x];i!=-1;i=next[i]) if(to[i]!=fa[0][x])
dep[to[i]]=dep[x]+1,fa[0][to[i]]=x,s[to[i]]=min(s[x],(ll)val[i]),dfs(to[i]);
p2[x]=p2[0];
}
inline int lca(int a,int b)
{
if(dep[a]<dep[b]) swap(a,b);
for(int i=Log[dep[a]-dep[b]];i>=0;i--) if(dep[fa[i][a]]>=dep[b]) a=fa[i][a];
if(a==b) return a;
for(int i=Log[dep[a]];i>=0;i--) if(fa[i][a]!=fa[i][b]) a=fa[i][a],b=fa[i][b];
return fa[0][a];
}
bool cmp(int a,int b)
{
return p1[a]<p1[b];
}
inline void Add(int a,int b)
{
if(b) ch[a].push_back(b);
}
ll solve(int x)
{
ll tmp=0;
for(int i=0;i<(int)ch[x].size();i++) tmp+=solve(ch[x][i]);
ch[x].clear();
if(!vis[x]) tmp=min(tmp,s[x]);
else tmp=s[x];
return tmp;
}
int main()
{
n=rd();
int i,j,a,b,c;
memset(head,-1,sizeof(head));
for(i=1;i<n;i++) a=rd(),b=rd(),c=rd(),add(a,b,c),add(b,a,c);
dep[1]=1,s[1]=1ll<<60,dfs(1);
for(i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
for(j=1;(1<<j)<=n;j++) for(i=1;i<=n;i++) fa[j][i]=fa[j-1][fa[j-1][i]];
m=rd();
for(i=1;i<=m;i++)
{
K=rd();
for(j=1;j<=K;j++) p[j]=rd(),vis[p[j]]=1;
sort(p+1,p+K+1,cmp);
st[top=1]=p[1];
for(j=2;j<=K;j++)
{
a=p[j],b=lca(st[top],a),c=0;
while(top&&dep[st[top]]>dep[b]) Add(st[top],c),c=st[top--];
if(st[top]==b) Add(st[top],c);
if(dep[st[top]]<dep[b]) Add(b,c),st[++top]=b;
st[++top]=a;
}
while(top>1) Add(st[top-1],st[top]),top--;
a=st[1];
printf("%lld\n",solve(a));
for(j=1;j<=K;j++) vis[p[j]]=0;
}
return 0;
}//10 1 5 13 1 9 6 2 1 19 2 4 8 2 3 91 5 6 8 7 5 4 7 8 31 10 7 9 3 2 10 6 4 5 7 8 3 3 9 4 6