#include<cstdio>
#include<queue>
#include<algorithm>
typedef long long ll;
const int inf=1e9;
int N,K[33],M,U[55],V[55],W[55];
struct Jewel{int S,P;ll C;bool operator<(const Jewel&j)const{return S<j.S;}}J[33][33];
int no(int i,int j){return j?j<K[i]?2+i+(j-1)*N:1:0;}
struct Edge{int to,cap;ll cost;Edge*rev,*next;}E[33333],*ne=E,*fir[999];
void link(int a,int b,int c,int cr,ll cost){
	*ne=(Edge){b,c,cost,ne+1,fir[a]};fir[a]=ne++;
	*ne=(Edge){a,cr,-cost,ne-1,fir[b]};fir[b]=ne++;
}
ll D[999],h[999];
bool vis[999];
Edge*fr[999];
struct Item{int v;ll d;Edge*e;bool operator<(const Item&it)const{return d>it.d;}};
void sp(){
	std::priority_queue<Item>Q;
	Q.push((Item){0,0,0});
	for(int i=0;i<N;i++)
		for(int j=0;j<=K[i];j++)h[no(i,j)]=D[no(i,j)],vis[no(i,j)]=0;
	while(!Q.empty()){
		Item it=Q.top();Q.pop();
		if(vis[it.v])continue;
		vis[it.v]=1;D[it.v]=it.d+h[it.v];fr[it.v]=it.e;
		for(Edge*e=fir[it.v];e;e=e->next)if(e->cap&&!vis[e->to])Q.push((Item){e->to,D[it.v]+e->cost-h[e->to],e});
	}
}
int cnt,X[111111];
ll Y[111111],kr[111111];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",K+i);
		for(int j=0;j<K[i];j++)
			scanf("%d%d%lld",&J[i][j].S,&J[i][j].P,&J[i][j].C);
		std::sort(J[i],J[i]+K[i]);
		for(int j=0;j<K[i];j++){
			link(no(i,j),no(i,j+1),J[i][j].P,inf,0);
			link(no(i,j),no(i,j+1),inf,0,J[i][j].C);
		}
	}
	scanf("%d",&M);
	for(int i=0;i<M;i++){
		scanf("%d%d%d",U+i,V+i,W+i);
		--U[i];--V[i];
		for(int j=0,k=0;j<K[V[i]];j++){
			while(k<K[U[i]]&&J[V[i]][j].S>J[U[i]][k].S+W[i])k++;
			if(k)link(no(V[i],j),no(U[i],k),inf,0,0);
		}
	}
	int c=0;ll f=0;
	for(;;){
		sp();
		int mc=inf;
		for(int v=1;v;v=fr[v]->rev->to)
			if(fr[v]->cap<mc)mc=fr[v]->cap;
		kr[cnt]=D[1];X[cnt]=c;Y[cnt++]=f;
		if(mc>inf/2)break;
		c+=mc;f+=1ll*mc*D[1];
		for(int v=1;v;v=fr[v]->rev->to)
			fr[v]->cap-=mc,fr[v]->rev->cap+=mc;
	}
	int Q;scanf("%d",&Q);
	while(Q--){
		ll A;scanf("%lld",&A);
		int i=std::lower_bound(kr,kr+cnt,A)-kr;
		printf("%lld\n",i<cnt?X[i]*A-Y[i]:-1ll);
	}
}