#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, fa[500], fb[500], fh[500], a[500], b[500], pr[500], pmin, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> fa[i] >> fb[i] >> fh[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i] >> pr[i];
  int phcnt, pscnt, rcnt;
  for (int i = 0; i < n; i++) {
    pmin = INT_MAX;
    for (int j = 0; j < m; j++) {
      phcnt = a[j] / fh[i], pscnt = 2 * (fa[i] + fb[i]) / b[j];
      if (phcnt == 0)
        continue;
      else
        rcnt = pscnt / phcnt;
      if (2 * (fa[i] + fb[i]) % b[j] != 0 || pscnt % phcnt != 0) rcnt++;
      pmin = min(pmin, rcnt * pr[j]);
    }
    sum += pmin;
  }
  cout << sum;
  return 0;
}
