#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define ll long long

const ll llf = (signed ll) (~0ull >> 3);

template <typename T>
void pfill(T* pst, const T* ped, T val) {
  for ( ; pst != ped; *(pst++) = val);
}

typedef class Edge {
  public:
    int ed, nx;
    ll r, c;

    Edge() {	}
    Edge(int ed, int nx, ll r, ll c) : ed(ed), nx(nx), r(r), c(c) {	}
} Edge;

typedef class MapManager {
  public:
    int* h;
    vector<Edge> es;

    MapManager() {	}
    MapManager(int n)  {
      h = new int[(n + 1)];
      memset(h, -1, (n + 1) << 2);
    }

    void add_edge(int u, int v, ll cap, ll c) {
      es.emplace_back(v, h[u], cap, c);
      h[u] = (signed) es.size() - 1;
    }
    void add_arc(int u, int v, ll cap, ll c) {
      add_edge(u, v, cap, c);
      add_edge(v, u, 0, -c);
    }
    Edge& operator [] (int p) {
      return es[p];
    }
} MapManager;

typedef class Data {
  public:
    ll f, c, res;

    Data(ll f, ll c, ll res) : f(f), c(c), res(res) { }
} Data;

typedef class Network {
  public:
    int S, T;
    MapManager g;

    Network() {	}
    Network(int S, int T) : S(S), T(T), g(T) {
      f = new ll[(T + 1)];
      mf = new ll[(T + 1)];
      le = new int[(T + 1)];
      vis = new boolean[T + 1];
    }

    ll *f, *mf;
    int *le;
    boolean *vis;

    void clear() {
      delete[] f;
      delete[] le;
      delete[] mf;
      delete[] vis;
    }

    vector<Data> conv;
    boolean spfa() {
      queue<int> Q;
      pfill(f, f + T + 1, llf);
      pfill(vis, vis + T + 1, false);
      Q.push(S);
      f[S] = 0, mf[S] = llf, le[S] = -1;
      while (!Q.empty()) {
        int e = Q.front();
        Q.pop();
        vis[e] = false;
        for (int i = g.h[e], eu; ~i; i = g[i].nx) {
          eu = g[i].ed;
          if (!g[i].r) continue;
          ll w = f[e] + g[i].c;
          if (w < f[eu]) {
            f[eu] = w, mf[eu] = min(mf[e], g[i].r), le[eu] = i;
            if (!vis[eu]) {
              Q.push(eu);
              vis[eu] = true;
            }
          }
        }
      }
      if (f[T] == llf)
        return false;
      ll flow = mf[T];
      for (int p = T, e; p ^ S; p = g[le[p] ^ 1].ed) {
        e = le[p];
        g[e].r -= flow;
        g[e ^ 1].r += flow;
      }
      Data t = conv.back();
      conv.emplace_back(t.f + flow, f[T], t.res + 1ll * f[T] * flow);
      if (t.f + flow >= (1ll << 50)) {
        return false;
      }
      return true;
    }

    void min_cost() {
      conv.emplace_back(0, 0, 0);
      while (spfa());
    }

    void add_edge(int u, int v, ll cap, ll w) {
      //			cerr << u << "->" << v << " " << cap << " " << w << '\n';
      g.add_arc(u, v, cap, w);		
    }
} Network;

typedef class Jewelry {
  public:
    int s, p;
    ll c;

    void read() {
      cin >> s >> p >> c;
    }
    boolean operator < (Jewelry b) const {
      return s < b.s;
    }
} Jewelry;

int n, m, q;
vector<vector<int>> id;
vector<vector<Jewelry>> shop;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  id.resize(n);
  shop.resize(n);
  int T = 0;
  for (int i = 0, K; i < n; i++) {
    cin >> K;
    id[i].resize(K - 1);
    shop[i].resize(K);
    for (auto& x : id[i]) {
      x = ++T;
    }
    id[i].push_back(-1);
    id[i].insert(id[i].begin(), 0);
    for (auto& x : shop[i]) {
      x.read();
    }
    sort(shop[i].begin(), shop[i].end());
  }
  Network network (0, ++T);
  for (auto& v : id) {
    v.back() = T;
  }
  for (int i = 0; i < n; i++) {
    int K = shop[i].size();
    for (int j = 0; j < K; j++) {
      network.add_edge(id[i][j], id[i][j + 1], shop[i][j].p, 0);
      network.add_edge(id[i][j + 1], id[i][j], llf, 0);
      network.add_edge(id[i][j], id[i][j + 1], llf, shop[i][j].c);
    }
  }
  cin >> m;
  for (int i = 0, x, y, w; i < m; i++) {
    cin >> x >> y >> w;
    --x, --y;
    int kx = shop[x].size(), ky = shop[y].size();
    for (int l = 0, r = 0; l < ky; l++) {
      while (r < kx && shop[y][l].s - w > shop[x][r].s) {
        r++;
      }
      network.add_edge(id[y][l], id[x][r], llf, 0);
    }
  }
  network.min_cost();
  auto& conv = network.conv;
  cin >> q;
  ll a;
  while (q--) {
    cin >> a;
    auto t = lower_bound(conv.begin(), conv.end(), a, [&] (Data x, ll y) {  return x.c < y; });
    if (t == conv.end()) {
      cout << "-1" << '\n';
    } else {
      --t;
      cout << 1ll * (*t).f * a - (*t).res << '\n'; 
    }
  }
  return 0;
}



Measured memory_bytes: 2300