#include <bits/stdc++.h>
using namespace std;
const int inf = numeric_limits<int>::max() >> 2;
const double eps = 1e-9;
struct triple {
  int a, b, c;
};
int main() {
  int n, m;
  cin >> n;
  vector<triple> P(n);
  for (int i = 0; i < n; ++i) {
    cin >> P[i].a >> P[i].b >> P[i].c;
  }
  cin >> m;
  vector<triple> R(m);
  for (int i = 0; i < m; ++i) {
    cin >> R[i].a >> R[i].b >> R[i].c;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int mcost = inf;
    for (int j = 0; j < m; ++j) {
      int cost;
      int ob = 2 * (P[i].a + P[i].b);
      int dv = R[j].a / P[i].c;
      if (dv == 0) continue;
      int cnt = ceil((double)ob / (dv * R[j].b));
      cost = cnt * R[j].c;
      mcost = min(mcost, cost);
    }
    ans += mcost;
  }
  cout << ans << endl;
  return 0;
}
