#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 550;
struct room {
  int p;
  int height;
} rooms[maxn];
struct paper {
  int length;
  int width;
  int price;
} papers[maxn];
int n, m;
int main() {
  cin >> n;
  for (int i = 1, x, y; i <= n; ++i) {
    cin >> x >> y >> rooms[i].height;
    rooms[i].p = (x + y) << 1;
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> papers[i].length >> papers[i].width >> papers[i].price;
  }
  int total = 0;
  for (int i = 1; i <= n; ++i) {
    int cost = inf;
    for (int j = 1; j <= m; ++j) {
      if (rooms[i].height == 0) {
        cost = 0;
        continue;
      }
      int perPiece = papers[j].length / rooms[i].height * papers[j].width;
      if (perPiece == 0) continue;
      int count = rooms[i].p / perPiece + (rooms[i].p % perPiece != 0);
      int newCost = papers[j].price * count;
      cost = min(cost, newCost);
    }
    total += cost;
  }
  cout << total;
  return 0;
}
