#include <bits/stdc++.h>
const int Inf = 1e9;
long long LINF = (long long)4e18;
using namespace std;
long long mod = 1e9 + 7;
struct room {
  int l, w, h;
};
struct kek {
  int l, w, c;
};
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<room> r(n);
  for (int(i) = 0; (i) < n; (i)++) {
    int l, w, h;
    cin >> l >> w >> h;
    r[i].l = l;
    r[i].w = w;
    r[i].h = h;
  }
  int m;
  cin >> m;
  vector<kek> q(m);
  for (int(i) = 0; (i) < m; (i)++) {
    int l, w, cost;
    cin >> l >> w >> cost;
    q[i].l = l;
    q[i].w = w;
    q[i].c = cost;
  }
  long long ans = 0;
  for (int(i) = 0; (i) < n; (i)++) {
    int p = r[i].w * 2 + r[i].l * 2;
    int cur = 2e9;
    for (int(j) = 0; (j) < m; (j)++) {
      if (q[j].l < r[i].h) continue;
      int tmp = (p + q[j].w - 1) / q[j].w;
      int qq = q[j].l / r[i].h;
      int cnt = (tmp + qq - 1) / qq;
      cur = min(cur, cnt * q[j].c);
    }
    ans += cur;
  }
  cout << ans;
  return 0;
}
