#include <bits/stdc++.h>
typedef struct _room {
  int l;
  int w;
  int h;
} room;
typedef struct _paper {
  int l;
  int w;
  int p;
} paper;
int main(void) {
  int n, m;
  room r[500];
  paper wall[500];
  int i, j;
  int cost = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &(r[i].l), &(r[i].w), &(r[i].h));
  }
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &(wall[i].l), &(wall[i].w), &(wall[i].p));
  }
  for (i = 0; i < n; i++) {
    int perimeter = 2 * r[i].l + 2 * r[i].w;
    int min_price = 100000000;
    for (j = 0; j < m; j++) {
      if (wall[j].l < r[i].h) continue;
      int cover = (wall[j].l / r[i].h) * wall[j].w;
      int price = ceil((1.0 * perimeter) / cover) * wall[j].p;
      if (price < min_price) {
        min_price = price;
      }
    }
    cost += min_price;
  }
  printf("%d\n", cost);
  return 0;
}
