#include <bits/stdc++.h>
using namespace std;
int i, j, m, n, t1, t2, sum, result, HP, h[1000], x[1000], h2[1000], x2[1000],
    c[1000];
int main() {
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> t1 >> t2 >> h[i];
    x[i] = (t1 + t2) * 2;
  }
  cin >> m;
  for (i = 0; i < m; ++i) cin >> h2[i] >> x2[i] >> c[i];
  result = 0;
  for (i = 0; i < n; ++i) {
    HP = 1000000000;
    for (j = 0; j < m; ++j)
      if (h2[j] >= h[i]) {
        t1 = h2[j] / h[i];
        t2 = t1 * x2[j];
        sum = x[i] / t2;
        if (x[i] % t2 > 0) ++sum;
        sum *= c[j];
        if (sum < HP) HP = sum;
      }
    result += HP;
  }
  cout << result;
  return 0;
}
