#include <bits/stdc++.h>
using namespace std;
struct room {
  int l, w, h;
};
struct roll {
  int l, w, price;
};
room Rooms[500];
roll Rolls[500];
int getcost(room x, roll y) {
  if (y.l < x.h) return 1e9;
  int per = (x.l + x.w) * 2;
  int numroll = y.l / x.h;
  int cover = numroll * y.w;
  int price = ceil((double)per / cover) * y.price;
  return price;
}
int main() {
  int n, m;
  scanf("%d", &n);
  int t = n;
  int idx = 0;
  while (t--) {
    scanf("%d%d%d", &Rooms[idx].l, &Rooms[idx].w, &Rooms[idx].h);
    idx++;
  }
  scanf("%d", &m);
  t = m;
  idx = 0;
  while (t--) {
    scanf("%d%d%d", &Rolls[idx].l, &Rolls[idx].w, &Rolls[idx].price);
    idx++;
  }
  int minprice = 0;
  for (int i = 0; i < n; i++) {
    int mincost = 1e9;
    for (int j = 0; j < m; j++) {
      int z = getcost(Rooms[i], Rolls[j]);
      if (z < mincost) mincost = z;
    }
    minprice = minprice + mincost;
  }
  printf("%d", minprice);
  return 0;
}
