#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
int n, m;
int pe[10000];
int h[10000];
int w[10000];
int l[10000];
int pr[10000];
int main() {
  int a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> h[i];
    pe[i] = 2 * (a + b);
  }
  cin >> m;
  for (int i = 0; i < m; i++) cin >> l[i] >> w[i] >> pr[i];
  long long r = 0;
  for (int i = 0; i < n; i++) {
    int mi = 1e9;
    for (int j = 0; j < m; j++)
      if (l[j] >= h[i]) {
        int x = l[j] / h[i] * w[j];
        mi = min(mi, pr[j] * ((pe[i] + x - 1) / x));
      }
    r += mi;
  }
  cout << r << endl;
  return 0;
}
