#include <bits/stdc++.h>
using namespace std;
struct rec {
  int x, y, z;
} nc[600];
struct rol {
  int x, y, p;
} mc[600];
int main() {
  int n, m;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> nc[i].x >> nc[i].y >> nc[i].z;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> mc[i].x >> mc[i].y >> mc[i].p;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int minp = (1 << 30) - 1;
      int len = 2 * (nc[i].x + nc[i].y);
      for (int j = 0; j < m; j++) {
        int tp1 = 1;
        int f = 1;
        if (mc[j].x < nc[i].z) {
          f = ceil(double(nc[i].z) / mc[j].x);
          tp1 = 1;
          continue;
        } else {
          tp1 = mc[j].x / nc[i].z;
        }
        if (f == 0) f = 1;
        if (tp1 == 0) tp1 = 1;
        int ncost = ceil(double(len) / (tp1 * mc[j].y));
        if (ncost <= 0) ncost = 1;
        if (minp > mc[j].p * ncost * f) minp = mc[j].p * ncost * f;
      }
      sum += minp;
    }
    cout << sum << endl;
  }
  return 0;
}
