#include using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) template using dijkstra_queue = priority_queue,greater>; struct Edge{ int to; ll d; }; int N,K; vector> E; vector D; vector qD; vector> P; vector> DK; vector CK; vector> E2; int lca(int u,int v){ if(qD[u]=0; d--) if((qD[u]-qD[v])>=(1<=0; d--) if(P[d][u]!=P[d][v]){ u=P[d][u]; v=P[d][v]; } return P[0][u]; } ll dist(int u,int v){ int g=lca(u,v); return D[v]+D[u]-2*D[g]; } int main(){ scanf("%d%d",&N,&K); E.resize(N); E2.resize(N+K*2); rep(i,N-1){ int a,b,c; scanf("%d%d%d",&a,&b,&c); a--; b--; E[a].push_back({b,c}); E[b].push_back({a,c}); E2[a].push_back({b,c}); E2[b].push_back({a,c}); } CK.resize(K); rep(k,K){ int m,c; scanf("%d%d",&m,&c); CK[k]=c; E2[N+k].push_back({N+K+k,c}); rep(i,m){ int x; scanf("%d",&x); x--; E2[x].push_back({N+k,0}); E2[N+K+k].push_back({x,0}); } } P.assign(18,vector(N,-1)); D.assign(N,0); qD.assign(N,0); { queue Q; Q.push(0); while(Q.size()){ int p=Q.front(); Q.pop(); for(Edge e:E[p]) if(P[0][p]!=e.to){ P[0][e.to]=p; D[e.to]=D[p]+e.d; qD[e.to]=qD[p]+1; Q.push(e.to); } } P[0][0]=0; rep(d,17) rep(i,N) P[d+1][i]=P[d][P[d][i]]; } DK.assign(K,vector(N+K*2,1001001001001001001)); { dijkstra_queue> G; rep(k,K){ DK[k][N+K+k]=0; G.push({0,N+K+k}); while(G.size()){ int p=G.top().second; ll d=G.top().first; G.pop(); if(DK[k][p]!=d) continue; for(Edge e:E2[p]){ int nd=d+e.d; if(DK[k][e.to]<=nd) continue; DK[k][e.to]=nd; G.push({nd,e.to}); } } } } int Q; scanf("%d",&Q); rep(i,Q){ int u,v; scanf("%d%d",&u,&v); u--; v--; ll ans=dist(u,v); rep(k,K) ans=min(ans,DK[k][u]+DK[k][v]+CK[k]); printf("%lld\n",ans); } return 0; }