#include <bits/stdc++.h>
const double pi = acos(-1);
using namespace std;
int diri[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dirj[] = {0, 1, 0, -1, 1, 1, -1, -1};
int compare(double d1, double d2) {
  if (fabs(d1 - d2) < 1e-9) return 0;
  if (d1 < d2) return -1;
  return 1;
}
int main() {
  int r;
  cin >> r;
  vector<int> n(r), m(r), h(r);
  for (int i = 0; i < r; i++) {
    cin >> n[i] >> m[i] >> h[i];
  }
  int rools;
  cin >> rools;
  vector<int> w(rools), l(rools), cost(rools);
  for (int i = 0; i < rools; i++) {
    cin >> w[i] >> l[i] >> cost[i];
  }
  int ans = 0;
  for (int i = 0; i < r; ++i) {
    int mn = ((int)1e9);
    int siz = 2 * n[i] + 2 * m[i];
    for (int j = 0; j < rools; ++j) {
      if (w[j] >= h[i]) {
        double np = w[j] / h[i];
        int n1 = ceil((double)siz / ((double)np * (double)l[j]));
        mn = min(mn, n1 * cost[j]);
      } else {
      }
    }
    ans += mn;
  }
  cout << ans << endl;
  return 0;
}
