#include <bits/stdc++.h>
struct node {
  int a, b, c;
} p[600], q[600];
int main() {
  int s, n, m, t, tt, ret, a, b, c, i, j, x;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d%d%d", &p[i].a, &p[i].b, &p[i].c);
  scanf("%d", &m);
  for (i = 0; i < m; i++) scanf("%d%d%d", &q[i].a, &q[i].b, &q[i].c);
  for (ret = i = 0; i < n; i++) {
    s = (p[i].a + p[i].b) * 2;
    tt = 100000000;
    for (j = 0; j < m; j++) {
      if (q[j].a >= p[i].c) {
        a = q[j].a / p[i].c * q[j].b;
        if (s % a)
          t = s / a + 1;
        else
          t = s / a;
        if (tt > t * q[j].c) tt = q[j].c * t;
      } else {
        continue;
      }
    }
    ret += tt;
  }
  printf("%d\n", ret);
  return 0;
}
