#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#define N 250005
#define ll long long
using namespace std;
int n,m,q,cnt,dfn,top;
ll f[N],mn[N];
int a[N],s[N],deep[N],head[N],id[N],fa[N][21];
int next[2*N],list[2*N],key[2*N];
inline int read()
{
int a=0,f=1; char c=getchar();
while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1; c=getchar();}
while (c>=‘0‘&&c<=‘9‘) {a=a*10+c-‘0‘; c=getchar();}
return a*f;
}
inline bool cmp(int a,int b)
{
return id[a]<id[b];
}
inline void insert(int x,int y,int z)
{
next[++cnt]=head[x];
head[x]=cnt;
list[cnt]=y;
key[cnt]=z;
}
inline void insert0(int x,int y)
{
if (x==y) return;
next[++cnt]=head[x];
head[x]=cnt;
list[cnt]=y;
}
void dfs(int x)
{
id[x]=++dfn;
for (int i=1;(1<<i)<=deep[x];i++) fa[x][i]=fa[fa[x][i-1]][i-1];
for (int i=head[x];i;i=next[i])
{
if (list[i]==fa[x][0]) continue;
mn[list[i]]=min(mn[x],(ll)key[i]);
fa[list[i]][0]=x;
deep[list[i]]=deep[x]+1;
dfs(list[i]);
}
}
inline int lca(int x,int y)
{
if (deep[x]>deep[y]) swap(x,y);
int t=deep[y]-deep[x];
for (int i=0;(1<<i)<=t;i++)
if ((1<<i)&t) y=fa[y][i];
for (int i=18;i>=0;i--)
if (fa[x][i]!=fa[y][i]) {x=fa[x][i]; y=fa[y][i];}
return x==y?x:fa[x][0];
}
void dp(int x)
{
f[x]=mn[x];
ll tmp=0;
for (int i=head[x];i;i=next[i])
{
dp(list[i]);
tmp+=f[list[i]];
}
head[x]=0;
if (tmp&&tmp<f[x]) f[x]=tmp;
}
inline void query()
{
cnt=top=0;
int m=read();
for (int i=1;i<=m;i++) a[i]=read();
sort(a+1,a+m+1,cmp);
int tot=0;
a[++tot]=a[1];
for(int i=2;i<=m;i++)
if(lca(a[tot],a[i])!=a[tot])a[++tot]=a[i];
s[++top]=1;
for (int i=1;i<=tot;i++)
{
int t=a[i],f=0;
while (top>0)
{
f=lca(s[top],t);
if (top>1&&deep[f]<deep[s[top-1]]) {insert0(s[top-1],s[top]); top--;}
else if (deep[f]<deep[s[top]]) {insert0(f,s[top]); top--; break;}
else break;
}
if (s[top]!=f) s[++top]=f; s[++top]=t;
}
while (top>1) {insert0(s[top-1],s[top]); top--;}
dp(1);
printf("%lld\n",f[1]);
}
int main()
{
n=read();
for (int i=1;i<n;i++)
{
int u=read(),v=read(),w=read();
insert(u,v,w); insert(v,u,w);
}
mn[1]=10000000000000;
dfs(1);
q=read();
memset(head,0,sizeof(head));
while (q--) query();
return 0;
}