#include <bits/stdc++.h>
using namespace std;
long long r[500][3];
long long w[500][3];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> r[i][0] >> r[i][1] >> r[i][2];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> w[i][0] >> w[i][1] >> w[i][2];
  long long c[m], l, h, sum = 0;
  for (int i = 0; i < n; i++) {
    l = 2 * (r[i][0] + r[i][1]);
    h = r[i][2];
    for (int j = 0; j < m; j++) {
      if (h > w[j][0]) {
        c[j] = 999999999999999999;
        continue;
      }
      long long q = w[j][0] / h;
      if (q == 0) q++;
      c[j] = (l / (q * w[j][1])) * w[j][2];
      if (c[j] != ((float)l / (q * w[j][1])) * w[j][2]) c[j] += w[j][2];
    }
    sum += *min_element(c, c + m);
  }
  cout << sum << endl;
  return 0;
}
