#include<bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const int MAXV = 3e4 + 5;
const long long INF = 1e18;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
namespace MincostFlow {
	const int MAXP = 12005;
	const int MAXQ = 2e5 + 5;
	struct edge {int dest; ll flow; int pos; ll cost; };
	vector <edge> a[MAXP];
	int s, t, tot; ll flow, cost, res[MAXV];
	ll dist[MAXP], path[MAXP], home[MAXP];
	void FlowPath() {
		flow += 1, cost += dist[t];
		int p = t;
		while (p != s) {
			a[path[p]][home[p]].flow -= 1;
			a[p][a[path[p]][home[p]].pos].flow += 1;
			p = path[p];
		}
	}
	bool spfa() {
		static int q[MAXQ];
		static bool inq[MAXP];
		static int l = 0, r = 0;
		for (int i = 0; i <= r; i++)
			dist[q[i]] = INF;
		q[l = r = 0] = s, dist[s] = 0, inq[s] = true;
		while (l <= r) {
			int tmp = q[l];
			for (unsigned i = 0; i < a[tmp].size(); i++)
				if (a[tmp][i].flow != 0 && dist[tmp] + a[tmp][i].cost < dist[a[tmp][i].dest]) {
					dist[a[tmp][i].dest] = dist[tmp] + a[tmp][i].cost;
					path[a[tmp][i].dest] = tmp;
					home[a[tmp][i].dest] = i;
					if (!inq[a[tmp][i].dest]) {
						q[++r] = a[tmp][i].dest;
						inq[q[r]] = true;
					}
				}
			l++, inq[tmp] = false;
		}
		return dist[t] != INF;
	}
	void addedge(int x, int y, ll z, ll c) {
		a[x].push_back((edge){y, z, a[y].size(), c});
		a[y].push_back((edge){x, 0, a[x].size() - 1, -c});
	}
	void work(int n, int m) {
		for (int i = 1; i <= n; i++)
			dist[i] = INF;
		for (int i = 1; i <= m; i++) {
			assert(spfa()), FlowPath();
			res[flow] = cost;
		}
	}
}
struct info {ll s, p, c; } b[MAXN][MAXN];
int n, m, q, k[MAXN], point[MAXN][MAXN];
int main() {
	using namespace MincostFlow;
	read(n), s = ++tot, t = ++tot;
	for (int i = 1; i <= n; i++) {
		read(k[i]);
		for (int j = 1; j <= k[i]; j++)
			read(b[i][j].s), read(b[i][j].p), read(b[i][j].c);
		sort(b[i] + 1, b[i] + k[i] + 1, [&] (info a, info b) {
			return a.s < b.s;
		});
		point[i][0] = s, point[i][k[i]] = t;
		for (int j = 1; j <= k[i] - 1; j++)
			point[i][j] = ++tot;
		for (int j = 1; j <= k[i]; j++) {
			addedge(point[i][j], point[i][j - 1], INF, 0);
			addedge(point[i][j - 1], point[i][j], b[i][j].p, 0);
			addedge(point[i][j - 1], point[i][j], INF, b[i][j].c);
		}
	}
	read(m);
	for (int i = 1; i <= m; i++) {
		int x, y, w; read(x), read(y), read(w);
		for (int j = 1; j <= k[y]; j++) {
			int l = 0;
			while (l < k[x] && b[x][l + 1].s + w < b[y][j].s) l++;
			addedge(point[y][j - 1], point[x][l], INF, 0);
		}
	}
	int limit = 3e4;
	work(tot, limit), read(q);
	for (int i = 1; i <= q; i++) {
		ll x, ans = 0; read(x);
		if (res[limit] - res[limit - 1] < x) puts("-1");
		else {
			int l = 1, r = limit - 1;
			while (l <= r) {
				int mid = (l + r) / 2;
				chkmin(ans, res[mid] - x * mid);
				if (res[mid + 1] - res[mid] >= x) r = mid - 1;
				else l = mid + 1;
			}
			printf("%lld\n", -ans);
		}
	}
	return 0;
}


Measured memory_bytes: 3200