#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a[500][3], b[500][3], s = 0, sum = 0, min, k, p, i, j, r;
  cin >> n;
  for (i = 0; i < n; i++)
    for (j = 0; j < 3; j++) cin >> a[i][j];
  cin >> m;
  for (i = 0; i < m; i++)
    for (j = 0; j < 3; j++) cin >> b[i][j];
  for (i = 0; i < n; i++) {
    min = 1000000000000;
    for (j = 0; j < m; j++) {
      p = 2 * (a[i][0] + a[i][1]);
      if (b[j][0] >= a[i][2]) {
        k = b[j][0] / a[i][2];
        r = p / (k * b[j][1]);
        if (p % (k * b[j][1]) > 0) ++r;
        s = r * b[j][2];
        if (min > s) min = s;
      }
    }
    sum += min;
  }
  cout << sum;
  return 0;
}
