#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[501], b[501], c[501], l[501], w[501], p[501];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> l[i] >> w[i] >> p[i];
  int s = 0;
  for (int i = 0; i < n; i++) {
    int min = 1000000;
    int p1 = 2 * (a[i] + b[i]);
    for (int j = 0; j < m; j++) {
      bool f = true;
      int kol = (p1 / w[j]) + (p1 % w[j] ? 1 : 0);
      if (l[j] >= c[i]) {
        int kol1 = l[j] / c[i];
        kol = kol / kol1 + (kol % kol1 ? 1 : 0);
      } else {
        f = false;
      }
      if ((kol * p[j] < min) && f) min = kol * p[j];
    }
    s += min;
  }
  cout << s;
  return 0;
}
