#include <bits/stdc++.h>
using namespace std;
struct room {
  int x, y, z;
};
struct s {
  int x, y, cost;
};
room a[500 + 1];
s b[500 + 1];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i].x >> a[i].y >> a[i].z;
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) cin >> b[i].x >> b[i].y >> b[i].cost;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int sum = (int)1e9;
    int p = 2 * (a[i].x + a[i].y);
    for (int j = 0; j < m; ++j) {
      int k = b[j].x / a[i].z;
      if (!k) continue;
      int t = k * b[j].y;
      int d = p % t ? p / t + 1 : p / t;
      sum = min(sum, d * b[j].cost);
    }
    ans += sum;
  }
  cout << ans;
  return 0;
}
