#include <bits/stdc++.h>
using namespace std;
int infinito = 1e9;
int n, m;
int coste[500];
int eleccion[500];
int l[500], w[500], h[500];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> w[i] >> h[i];
    coste[i] = infinito;
  }
  cin >> m;
  for (int j = 0; j < m; j++) {
    int l2, w2, p;
    cin >> l2 >> w2 >> p;
    for (int i = 0; i < n; i++) {
      int l1 = l[i];
      int w1 = w[i];
      int h1 = h[i];
      if (h1 <= l2) {
        int c = l2 / h1;
        int d = 2 * (w1 + l1) / (c * w2);
        if (d * c * w2 < 2 * (w1 + l1)) d++;
        if (p * d < coste[i]) {
          coste[i] = min(coste[i], p * d);
          eleccion[i] = j;
        }
      }
    }
  }
  int sol = 0;
  for (int i = 0; i < n; i++) {
    sol += coste[i];
  }
  cout << sol << endl;
}
