#include <bits/stdc++.h>
using namespace std;
struct Wallpaper {
  int len;
  int wid;
  int price;
};
struct Room {
  int length;
  int width;
  int height;
};
int ans = 0;
int ans_total = 0;
int cost = 0;
int money = 0;
int n, m, x, y;
Wallpaper paper[1000];
Room room[1000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d %d %d", &room[i].length, &room[i].width, &room[i].height);
  scanf("%d", &m);
  for (int i = 0; i < m; i++)
    scanf("%d %d %d", &paper[i].len, &paper[i].wid, &paper[i].price);
  for (int i = 0; i < n; i++) {
    ans = 0x7fffffff;
    for (int j = 0; j < m; j++) {
      cost = 0;
      x = 0;
      y = 0;
      money = 0;
      if (paper[j].len >= room[i].height)
        x = static_cast<int>(floor((paper[j].len) * 1.0 / (room[i].height)));
      else
        x = -1;
      int totallen = (room[i].width + room[i].length) * 2;
      if (totallen < paper[j].wid) {
        y = 1;
        cost = 1;
      } else {
        y = static_cast<int>(ceil(totallen * 1.0 / paper[j].wid));
        cost = static_cast<int>(ceil(y * 1.0 / x));
      }
      if (x != -1) {
        money = static_cast<int>(ceil(cost * 1.0 * paper[j].price));
        ans = (ans > money) ? money : ans;
      }
    }
    ans_total += ans;
  }
  printf("%d", ans_total);
}
