#include<bits/stdc++.h>
#define ll long long
#define re register
#define cs const

namespace IO{
	inline char gc(){
		static cs int Rlen=1<<22|1;static char buf[Rlen],*p1,*p2;
		return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++; 
	}template<typename T>T get_integer(){
		char c;bool f=false;while(!isdigit(c=gc()))f=c=='-';T x=c^48;
		while(isdigit(c=gc()))x=((x+(x<<2))<<1)+(c^48);return f?-x:x;
	}inline int gi(){return get_integer<int>();}
	inline ll gl(){return get_integer<ll>();}
}using namespace IO;

using std::cerr;
using std::cout;
using pll=std::pair<ll,ll>;
#define fi first
#define se second

cs ll INF=1ll<<60;

int Src,Snk,ct;

namespace NetWork{

cs int N=1e3+7;

struct edge{int to,rev;ll cap,w;};
typedef std::vector<edge>::iterator iter;
std::vector<edge> G[N];iter cur[N];
inline void adde(int u,int v,ll cap,ll cost){
	G[u].push_back({v,(int)G[v].size(),cap,cost});
	G[v].push_back({u,(int)G[u].size()-1,0,-cost});
}

ll dis[N];bool vs[N];

bool SPFA(){
	memset(dis,0x3f,sizeof dis);
	memset(vs,0,sizeof vs);
	std::deque<int> q({Src});dis[Src]=0;
	while(!q.empty()){
		int u=q.front();q.pop_front();
		vs[u]=false;cur[u]=G[u].begin();
		for(cs edge &e:G[u])
		if(e.cap&&dis[e.to]>dis[u]+e.w){
			dis[e.to]=dis[u]+e.w;
			if(!vs[e.to]){
				if(!q.empty()&&dis[e.to]<dis[q.front()])
					q.push_front(e.to);
				else q.push_back(e.to);
				vs[e.to]=true;
			}
		}
	}return dis[Snk]<INF;
}

ll tot_flow,tot_cost;
ll dfs(int u,ll flow){
	if(u==Snk){tot_flow+=flow;return flow;}
	ll ans=0;vs[u]=true;
	for(iter &e=cur[u];e!=G[u].end();++e)
	if(e->cap&&dis[e->to]==dis[u]+e->w&&!vs[e->to]){
		ll dlt=dfs(e->to,std::min(flow-ans,e->cap));
		e->cap-=dlt;G[e->to][e->rev].cap+=dlt;
		vs[e->to]=dlt==0;if((ans+=dlt)==flow)break;
	}vs[u]=false;return ans;
}

std::vector<pll> Flow(){
	std::vector<pll> p;
	while(SPFA()){
		tot_flow=0;dfs(Src,INF);
		p.push_back({dis[Snk],tot_flow});
		if(tot_flow>(1ll<<50))break;
	}return p;
}

}

cs int N=35;
int id[N][N],cnt[N];
int S[N][N],P[N][N];
ll C[N][N];

void Main(){
	int n=gi();
	for(int re i=1;i<=n;++i){
		cnt[i]=gi();
		for(int re j=1;j<=cnt[i];++j)
			S[i][j]=gi(),P[i][j]=gi(),C[i][j]=gl();
		for(int re j=1;j<=cnt[i];++j)
			for(int re k=j+1;k<=cnt[i];++k)
			if(S[i][j]>S[i][k]){
				std::swap(S[i][j],S[i][k]);
				std::swap(P[i][j],P[i][k]);
				std::swap(C[i][j],C[i][k]);
			}
	}Src=0,Snk=ct=1;
	for(int re i=1;i<=n;++i){
		for(int re j=1;j<=cnt[i]-1;++j)
			id[i][j]=++ct;
		id[i][0]=Src,id[i][cnt[i]]=Snk;
		for(int re j=1;j<=cnt[i];++j){
			NetWork::adde(id[i][j-1],id[i][j],P[i][j],0);
			NetWork::adde(id[i][j-1],id[i][j],INF,C[i][j]);
		}
	}
	int m=gi();
	while(m--){
		int u=gi(),v=gi(),w=gi();
		for(int re j=1,k=1;j<=cnt[v];++j){
			for(;k<=cnt[u]&&S[u][k]+w<S[v][j];++k);
			NetWork::adde(id[v][j-1],id[u][k-1],INF,0);
		}
	}
	auto p=NetWork::Flow();m=gi();
	std::vector<pll> q;ll x=0,y=0;
	for(auto t:p){
		q.push_back({x,y});
		x+=t.se,y+=t.fi*t.se;
	}
	while(m--){
		ll A=gl();
		size_t i=std::lower_bound(p.begin(),p.end(),(pll){A,-INF})-p.begin();
		if(i==p.size())cout<<"-1\n";
		else cout<<(q[i].fi*A-q[i].se)<<"\n";
	}
}

inline void file(){
#ifdef zxyoi
	freopen("F.in","r",stdin);
#endif
}signed main(){file();Main();return 0;} 

Measured memory_bytes: 3584