#include <bits/stdc++.h>
using namespace std;
struct wall {
  int w, l, h;
} w[510];
struct paper {
  int l;
  int w;
  int p;
} p[510];
int getsum(wall a, paper b) {
  int zc = (a.l + a.w) * 2;
  if (b.l < a.h) return (1 << 30);
  int ks = b.l / a.h;
  int mkcd = ks * b.w;
  if (zc % mkcd) return (zc / mkcd + 1) * b.p;
  return b.p * zc / mkcd;
}
int main() {
  int n, m, res, sum, min;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) scanf("%d%d%d", &w[i].l, &w[i].w, &w[i].h);
    scanf("%d", &m);
    for (int i = 0; i < m; i++) scanf("%d%d%d", &p[i].l, &p[i].w, &p[i].p);
    sum = 0;
    for (int i = 0; i < n; i++) {
      min = (1 << 30);
      for (int j = 0; j < m; j++) {
        res = getsum(w[i], p[j]);
        if (res < min) min = res;
      }
      sum += min;
    }
    printf("%d\n", sum);
  }
  return 0;
}
