#include <bits/stdc++.h>
int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
int main() {
  int room, roll;
  scanf("%d", &room);
  int w[500], l[500], h[500];
  int i, j, tmp, tmp2;
  for (i = 0; i < room; i++) scanf("%d%d%d", &w[i], &l[i], &h[i]);
  scanf("%d", &roll);
  int wid[500], len[500], price[500], ans[500];
  for (i = 0; i < roll; i++) scanf("%d%d%d", &len[i], &wid[i], &price[i]);
  for (i = 0; i < room; i++) {
    tmp = 0;
    tmp2 = 0x7fffffff;
    for (j = 0; j < roll; j++) {
      if (len[j] < h[i]) continue;
      tmp = (w[i] * 2 + l[i] * 2) / ((len[j] / h[i]) * wid[j]);
      if ((w[i] * 2 + l[i] * 2) % ((len[j] / h[i]) * wid[j]) != 0) tmp++;
      tmp *= price[j];
      tmp2 = min(tmp, tmp2);
    }
    ans[i] = tmp2;
  }
  int ret = 0;
  for (i = 0; i < room; i++) ret += ans[i];
  printf("%d", ret);
  return 0;
}
