#include <bits/stdc++.h>
int main() {
  int i, j, n, m, cnt;
  static struct room { int l, w, h; } rr[500];
  static struct wallpaper { int l, w, c; } ww[500];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d%d%d", &rr[i].l, &rr[i].w, &rr[i].h);
  scanf("%d", &m);
  for (j = 0; j < m; j++) scanf("%d%d%d", &ww[j].l, &ww[j].w, &ww[j].c);
  cnt = 0;
  for (i = 0; i < n; i++) {
    int min = INT_MAX, a, p, cost;
    for (j = 0; j < m; j++) {
      p = 2 * (rr[i].l + rr[i].w);
      a = (ww[j].l / rr[i].h) * ww[j].w;
      cost = INT_MAX;
      if (a > 0) cost = ww[j].c * ((p + a - 1) / a);
      if (min > cost) min = cost;
    }
    cnt += min;
  }
  printf("%d\n", cnt);
  return 0;
}
