#include <bits/stdc++.h>
using namespace std;
const int MAXN = 555;
int n, m;
int a[MAXN], b[MAXN], c[MAXN];
int x[MAXN], y[MAXN], z[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (register int i = (0); i < (int)(n); ++i) cin >> a[i] >> b[i] >> c[i];
  cin >> m;
  for (register int i = (0); i < (int)(m); ++i) cin >> x[i] >> y[i] >> z[i];
  int tot = 0;
  for (register int i = (0); i < (int)(n); ++i) {
    int res = -1U / 2;
    for (register int j = (0); j < (int)(m); ++j) {
      int p = 2 * (a[i] + b[i]);
      int h = c[i];
      if (h > x[j]) continue;
      int cnt = (x[j] / h) * y[j];
      int amt = (p + cnt - 1) / cnt;
      res = min(res, amt * z[j]);
    }
    tot += res;
  }
  cout << tot << "\n";
  return 0;
}
